contestId int64 0 1.01k | index stringclasses 57
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 11 | title stringclasses 522
values | time-limit stringclasses 8
values | memory-limit stringclasses 8
values | problem-description stringlengths 0 7.15k | input-specification stringlengths 0 2.05k | output-specification stringlengths 0 1.5k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 425k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 14
values | testset stringclasses 12
values | passedTestCount int64 0 1k | timeConsumedMillis int64 0 15k | memoryConsumedBytes int64 0 805M | code stringlengths 3 65.5k | prompt stringlengths 262 8.2k | response stringlengths 17 65.5k | score float64 -1 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
142 | C | Help Caretaker | PROGRAMMING | 2,300 | [
"brute force",
"dp"
] | null | null | Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse.
He's got problems wi... | The only line contains two space-separated integers *n* and *m* — the sizes of the warehouse (1<=≤<=*n*,<=*m*<=≤<=9). | In the first line print the maximum number of turboplows that can be positioned in the warehouse. In each of the next *n* lines print *m* characters. Use "." (dot) to mark empty space and use successive capital Latin letters ("A" for the first turboplow, "B" for the second one and so on until you reach the number of tu... | [
"3 3\n",
"5 6\n",
"2 2\n"
] | [
"1\nAAA\n.A.\n.A.\n",
"4\nA..C..\nAAAC..\nABCCCD\n.B.DDD\nBBB..D\n",
"0\n..\n..\n"
] | none | 1,500 | [
{
"input": "3 3",
"output": "1\nAAA\n.A.\n.A."
},
{
"input": "5 6",
"output": "4\nA..C..\nAAAC..\nABCCCD\n.B.DDD\nBBB..D"
},
{
"input": "2 2",
"output": "0\n..\n.."
},
{
"input": "4 2",
"output": "0\n..\n..\n..\n.."
},
{
"input": "3 4",
"output": "1\nA...\nAAA... | 1,535,320,564 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 248 | 102,400 | n, m = map(int, input().split())
swapped = False
if n < m:
n, m = m, n
swapped = True
ans = ''
if n == 1 and m == 1:
ans = '''0
.'''
if n == 2 and m == 1:
ans = '''0
.
.'''
if n == 2 and m == 2:
ans = '''0
..
..'''
if n == 3 and m == 1:
ans = '''0
.
.
.'''
if n == 3 and m == 2:
ans = '''0
..
..
..'''
if n... | Title: Help Caretaker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-triv... | ```python
n, m = map(int, input().split())
swapped = False
if n < m:
n, m = m, n
swapped = True
ans = ''
if n == 1 and m == 1:
ans = '''0
.'''
if n == 2 and m == 1:
ans = '''0
.
.'''
if n == 2 and m == 2:
ans = '''0
..
..'''
if n == 3 and m == 1:
ans = '''0
.
.
.'''
if n == 3 and m == 2:
ans = '''0
..
..
... | 3 | |
287 | A | IQ Test | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the... | Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black. | Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise. | [
"####\n.#..\n####\n....\n",
"####\n....\n####\n....\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | 500 | [
{
"input": "###.\n...#\n###.\n...#",
"output": "NO"
},
{
"input": ".##.\n#..#\n.##.\n#..#",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n.#.#\n#.#.",
"output": "NO"
},
{
"input": "##..\n..##\n##..\n..##",
"output": "NO"
},
{
"input": "#.#.\n#.#.\n.#.#\n.#.#",
"ou... | 1,590,779,836 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 140 | 0 | from sys import stdin
inp = lambda : stdin.readline().strip()
a = []
for i in range(4):
a.append(inp())
flag = False
for i in range(4):
for j in range(4):
white = 0
black = 0
for k in range(2):
for l in range(2):
if (i+k) < 4 and (j+l) < 4... | Title: IQ Test
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and o... | ```python
from sys import stdin
inp = lambda : stdin.readline().strip()
a = []
for i in range(4):
a.append(inp())
flag = False
for i in range(4):
for j in range(4):
white = 0
black = 0
for k in range(2):
for l in range(2):
if (i+k) < 4 and... | 3 | |
990 | D | Graph And Its Complement | PROGRAMMING | 1,700 | [
"constructive algorithms",
"graphs",
"implementation"
] | null | null | Given three numbers $n, a, b$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $a$, and the number of components in its complement is $b$. The matrix must be symmetric, and all digits on the main diagonal must be zeroes.
In an undirected graph loops (edg... | In a single line, three numbers are given $n, a, b \,(1 \le n \le 1000, 1 \le a, b \le n)$: is the number of vertexes of the graph, the required number of connectivity components in it, and the required amount of the connectivity component in it's complement. | If there is no graph that satisfies these constraints on a single line, print "NO" (without quotes).
Otherwise, on the first line, print "YES"(without quotes). In each of the next $n$ lines, output $n$ digits such that $j$-th digit of $i$-th line must be $1$ if and only if there is an edge between vertices $i$ and $j$... | [
"3 1 2\n",
"3 3 3\n"
] | [
"YES\n001\n001\n110\n",
"NO\n"
] | none | 0 | [
{
"input": "3 1 2",
"output": "YES\n001\n001\n110"
},
{
"input": "3 3 3",
"output": "NO"
},
{
"input": "5 1 1",
"output": "YES\n01000\n10100\n01010\n00101\n00010"
},
{
"input": "123 1 84",
"output": "YES\n0011111111111111111111111111111111111111111111111111111111111111111... | 1,528,628,891 | 3,791 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | def ii():
return int(input())
def mi():
return map(int, input().split())
def li():
return list(mi())
n, a, b = mi()
if a != 1 and b != 1:
print('NO')
else:
c = max(a, b)
if a == 1:
g = [[1] * n for i in range(n)]
for i in range(n):
g[i][i] = 0
... | Title: Graph And Its Complement
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given three numbers $n, a, b$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $a$, and the number of components in its complement is $b$. The ma... | ```python
def ii():
return int(input())
def mi():
return map(int, input().split())
def li():
return list(mi())
n, a, b = mi()
if a != 1 and b != 1:
print('NO')
else:
c = max(a, b)
if a == 1:
g = [[1] * n for i in range(n)]
for i in range(n):
g[i][i] = ... | 0 | |
342 | A | Xenia and Divisors | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divide... | The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3. | If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1. | [
"6\n1 1 1 2 2 2\n",
"6\n2 2 1 1 4 6\n"
] | [
"-1\n",
"1 2 4\n1 2 6\n"
] | none | 500 | [
{
"input": "6\n1 1 1 2 2 2",
"output": "-1"
},
{
"input": "6\n2 2 1 1 4 6",
"output": "1 2 4\n1 2 6"
},
{
"input": "3\n1 2 3",
"output": "-1"
},
{
"input": "3\n7 5 7",
"output": "-1"
},
{
"input": "3\n1 3 4",
"output": "-1"
},
{
"input": "3\n1 1 1",
... | 1,674,452,397 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 202 | 1,945,600 | n = int(input())
input_arr = input().split()
arr = []
sum = 0
for i in range(n):
# if int(input_arr[i]) == 5 or int(input_arr[i]) == 7:
# break
sum += int(input_arr[i])
arr.append(int(input_arr[i]))
arr.sort()
a_arr = []
b_arr = []
c_arr = []
for i in range(len(arr)//3):
a_arr.appe... | Title: Xenia and Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,... | ```python
n = int(input())
input_arr = input().split()
arr = []
sum = 0
for i in range(n):
# if int(input_arr[i]) == 5 or int(input_arr[i]) == 7:
# break
sum += int(input_arr[i])
arr.append(int(input_arr[i]))
arr.sort()
a_arr = []
b_arr = []
c_arr = []
for i in range(len(arr)//3):
... | 3 | |
730 | G | Car Repair Shop | PROGRAMMING | 1,600 | [
"implementation"
] | null | null | Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collected *n* requests from clients. The requests are numbered from 1 to *n* in o... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of requests from clients.
The following *n* lines contain requests, one request per line. The *i*-th request is given as the pair of integers *s**i*,<=*d**i* (1<=≤<=*s**i*<=≤<=109, 1<=≤<=*d**i*<=≤<=5·106), where *s**i* is the preferred time to start ... | Print *n* lines. The *i*-th line should contain two integers — the start day to repair the *i*-th car and the finish day to repair the *i*-th car. | [
"3\n9 2\n7 3\n2 4\n",
"4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000\n"
] | [
"9 10\n1 3\n4 7\n",
"1000000000 1000999999\n1 1000000\n100000000 100999999\n1000001 2000000\n"
] | none | 0 | [
{
"input": "3\n9 2\n7 3\n2 4",
"output": "9 10\n1 3\n4 7"
},
{
"input": "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000",
"output": "1000000000 1000999999\n1 1000000\n100000000 100999999\n1000001 2000000"
},
{
"input": "1\n1 1",
"output": "1 1"
},
... | 1,638,657,904 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define mp ma... | Title: Car Repair Shop
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing... | ```python
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#de... | -1 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,651,636,702 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | n,k=map(int,input().split())
lst=list(map(int,input().split()))
ctr=0
for num in lst:
if 5-num>=k: ctr+=1
print(ctr//3) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n,k=map(int,input().split())
lst=list(map(int,input().split()))
ctr=0
for num in lst:
if 5-num>=k: ctr+=1
print(ctr//3)
``` | 3 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,676,054,485 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | s=input()
t=[]
t.extend(s)
cnt=1
maxi=t[0]
flag=False
for i in range(1,len(t)):
if maxi==t[i] :
cnt+=1
maxi=t[i]
else :
cnt=1
maxi=t[i]
if cnt==7:
flag=True
break
if flag :
print('YES')
else :
print('NO') | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
s=input()
t=[]
t.extend(s)
cnt=1
maxi=t[0]
flag=False
for i in range(1,len(t)):
if maxi==t[i] :
cnt+=1
maxi=t[i]
else :
cnt=1
maxi=t[i]
if cnt==7:
flag=True
break
if flag :
print('YES')
else :
print('NO')
``` | 3.977 |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,697,638,701 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n = int(input())
m = sorted([int(i) for i in input().split()])
num, mid, coins = 1, sum(m)/2, m.pop(-1)
while coins <= mid:
if coins + m[-1] <= mid:
num += 1
coins += m.pop(-1)
else:
print(num + 1)
break
| Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
n = int(input())
m = sorted([int(i) for i in input().split()])
num, mid, coins = 1, sum(m)/2, m.pop(-1)
while coins <= mid:
if coins + m[-1] <= mid:
num += 1
coins += m.pop(-1)
else:
print(num + 1)
break
``` | 0 | |
807 | A | Is it rated? | PROGRAMMING | 900 | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order... | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som... | 500 | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
... | 1,651,659,759 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 150 | 93 | 2,355,200 | a, b = [], []
for i in range(int(input())):
x, y = map(int,input().split())
a.append(x)
b.append(y)
print('rated' if a != b else 'maybe' if sorted(a, reverse = True) == b else 'unrated') | Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number ... | ```python
a, b = [], []
for i in range(int(input())):
x, y = map(int,input().split())
a.append(x)
b.append(y)
print('rated' if a != b else 'maybe' if sorted(a, reverse = True) == b else 'unrated')
``` | 3 | |
330 | B | Road Construction | PROGRAMMING | 1,300 | [
"constructive algorithms",
"graphs"
] | null | null | A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two... | The first line consists of two integers *n* and *m* .
Then *m* lines follow, each consisting of two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*), which means that it is not possible to construct a road connecting cities *a**i* and *b**i*. Consider the cities are numbered from 1 to *n*.... | You should print an integer *s*: the minimum number of roads that should be constructed, in the first line. Then *s* lines should follow, each consisting of two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*), which means that a road should be constructed between cities *a**i* and *b**i*.... | [
"4 1\n1 3\n"
] | [
"3\n1 2\n4 2\n2 3\n"
] | This is one possible solution of the example:
These are examples of wrong solutions: | 1,000 | [
{
"input": "4 1\n1 3",
"output": "3\n1 2\n4 2\n2 3"
},
{
"input": "1000 0",
"output": "999\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 ... | 1,621,642,723 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n, m = map(int, input().split())
arr = [False]*(n+1)
for i in range(m):
a, b = map(int, input().split())
arr[a] = arr[b] = True
i = 1
while i < n + 1 and not arr[i]: i+=1
print(n-1)
for j in range(1, n+1):
if j != i:
print(i, j) | Title: Road Construction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constru... | ```python
n, m = map(int, input().split())
arr = [False]*(n+1)
for i in range(m):
a, b = map(int, input().split())
arr[a] = arr[b] = True
i = 1
while i < n + 1 and not arr[i]: i+=1
print(n-1)
for j in range(1, n+1):
if j != i:
print(i, j)
``` | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,675,812,618 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | s=input()
c=0
x=0
for i in s:
if i.lower():
c+=1
else:
x+=1
if c==x:
s=s.lower()
elif c>x:
s=s.lower()
elif x>c:
s=s.upper()
print(s) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=input()
c=0
x=0
for i in s:
if i.lower():
c+=1
else:
x+=1
if c==x:
s=s.lower()
elif c>x:
s=s.lower()
elif x>c:
s=s.upper()
print(s)
``` | 0 |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,698,095,232 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | t=int(input())
res=0
while t>0:
c=0
lis=map(int,input().split(" "))
for i in lis:
if i==1:
c+=1
if c>=2:
res+=1
t-=1
print(res) | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
t=int(input())
res=0
while t>0:
c=0
lis=map(int,input().split(" "))
for i in lis:
if i==1:
c+=1
if c>=2:
res+=1
t-=1
print(res)
``` | 3 | |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,695,379,937 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | def calculate_f(n):
result = 0
sign = -1
for i in range(1, n + 1):
result += sign * i
sign = -sign
return result
n = int(input("ادخل عددًا صحيحًا (n): "))
result = calculate_f(n)
print(f"f({n}) = {result}")
| Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
def calculate_f(n):
result = 0
sign = -1
for i in range(1, n + 1):
result += sign * i
sign = -sign
return result
n = int(input("ادخل عددًا صحيحًا (n): "))
result = calculate_f(n)
print(f"f({n}) = {result}")
``` | -1 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,586,783,568 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 108 | 0 | a = input()
h = a.find('h', 0)
e = a.find('e', 1)
l1 = a.find('l', 2)
l2 = a.find('l', 3)
o = a.find('o', 4)
if h and e and l1 and l2 and o >= 0:
print('YES')
else:
print('NO') | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
a = input()
h = a.find('h', 0)
e = a.find('e', 1)
l1 = a.find('l', 2)
l2 = a.find('l', 3)
o = a.find('o', 4)
if h and e and l1 and l2 and o >= 0:
print('YES')
else:
print('NO')
``` | 0 |
789 | A | Anastasia and pebbles | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same tim... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type. | The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. | [
"3 2\n2 3 4\n",
"5 4\n3 1 8 9 7\n"
] | [
"3\n",
"5\n"
] | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she... | 500 | [
{
"input": "3 2\n2 3 4",
"output": "3"
},
{
"input": "5 4\n3 1 8 9 7",
"output": "5"
},
{
"input": "1 22\n1",
"output": "1"
},
{
"input": "3 57\n78 165 54",
"output": "3"
},
{
"input": "5 72\n74 10 146 189 184",
"output": "6"
},
{
"input": "9 13\n132 8... | 1,648,897,357 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 140 | 9,523,200 | import math
n,k=map(int,input().split())
ar=list(map(int,input().split()))
s=0
for x in range(n):
s+=math.ceil(ar[x]/k)
print(math.ceil(s/2)) | Title: Anastasia and pebbles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could ... | ```python
import math
n,k=map(int,input().split())
ar=list(map(int,input().split()))
s=0
for x in range(n):
s+=math.ceil(ar[x]/k)
print(math.ceil(s/2))
``` | 3 | |
863 | A | Quasi-palindrome | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to str... | The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes. | Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes). | [
"131\n",
"320\n",
"2010200\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 0 | [
{
"input": "131",
"output": "YES"
},
{
"input": "320",
"output": "NO"
},
{
"input": "2010200",
"output": "YES"
},
{
"input": "1",
"output": "YES"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "999999999",
"output": "YES"
},
{
"i... | 1,585,553,722 | 2,147,483,647 | PyPy 3 | OK | TESTS | 44 | 140 | 0 | s = input()
s = s.strip('0')
l = len(s)
for i in range(0, l//2):
if s[i] != s[l - 1 - i]:
print("NO")
exit()
print("YES") | Title: Quasi-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from righ... | ```python
s = input()
s = s.strip('0')
l = len(s)
for i in range(0, l//2):
if s[i] != s[l - 1 - i]:
print("NO")
exit()
print("YES")
``` | 3 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,698,345,318 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | z=int(input())
m=list(map(int,input().split()))
m.sort()
for x in m:
print(x,end=' ') | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
z=int(input())
m=list(map(int,input().split()))
m.sort()
for x in m:
print(x,end=' ')
``` | 0 | |
817 | D | Imbalanced Array | PROGRAMMING | 1,900 | [
"data structures",
"divide and conquer",
"dsu",
"sortings"
] | null | null | You are given an array *a* consisting of *n* elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.
For example, the imbalance value of ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — size of the array *a*.
The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≤<=*a**i*<=≤<=106) — elements of the array. | Print one integer — the imbalance value of *a*. | [
"3\n1 4 1\n"
] | [
"9\n"
] | none | 0 | [
{
"input": "3\n1 4 1",
"output": "9"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "10\n1 4 4 3 5 2 4 2 4 5",
"output": "123"
},
{
"input": "10\n9 6 8 5 5 2 8 9 2 2",
"output": "245"
},
{
"input": "30\n4 5 2 2 5 2 3 4 3 3 2 1 3 4 4 5 3 3 1 5... | 1,622,787,046 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 1,216 | 114,585,600 | import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
stk = [(float('-inf'), int(-1))]
stk1 = [(float('inf'), int(-1))]
leftSmaller = []
leftGreater = []
for i, a in enumerate(A):
while stk[-1][0] > a:
stk.pop()
leftSmaller.append(stk[-1][1])
stk.append((a, i))... | Title: Imbalanced Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* consisting of *n* elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array ... | ```python
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
stk = [(float('-inf'), int(-1))]
stk1 = [(float('inf'), int(-1))]
leftSmaller = []
leftGreater = []
for i, a in enumerate(A):
while stk[-1][0] > a:
stk.pop()
leftSmaller.append(stk[-1][1])
stk.appe... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,643,983,379 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 |
n = int(input())
i = 0
j = 0
arra = []
res = []
sum1 = 0
while i < n:
inp = list(map(int, input().split()))
arra.append(inp)
i = i+1
for k in range(n):
sum = 0
for l in range(3):
sum += arra[k][l]
res.append(sum)
print(res)
for i in res:
sum1 += i
if sum1 == 0... | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
i = 0
j = 0
arra = []
res = []
sum1 = 0
while i < n:
inp = list(map(int, input().split()))
arra.append(inp)
i = i+1
for k in range(n):
sum = 0
for l in range(3):
sum += arra[k][l]
res.append(sum)
print(res)
for i in res:
sum1 += i
if... | 0 |
78 | A | Haiku | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Haiku | 2 | 256 | Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll... | The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailin... | Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). | [
"on codeforces \nbeta round is running\n a rustling of keys \n",
"how many gallons\nof edo s rain did you drink\n cuckoo\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "on codeforces \nbeta round is running\n a rustling of keys ",
"output": "YES"
},
{
"input": "how many gallons\nof edo s rain did you drink\n cuckoo",
"output": "NO"
},
{
"input": " hatsu shigure\n saru mo komino wo\nhoshige nari",
... | 1,590,998,415 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 248 | 0 | # haiku
s=str(input())
s1=str(input())
s2=str(input())
s=s.replace(' ','')
s1=s1.replace(' ','')
s2=s2.replace(' ','')
c=0
d=0
e=0
for i in range(0,len(s)):
if(s[i] in 'aeiou'):
c=c+1
for i in range(0,len(s1)):
if(s1[i] in 'aeiou'):
d=d+1
for i in range(0,len(s2)):
i... | Title: Haiku
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase... | ```python
# haiku
s=str(input())
s1=str(input())
s2=str(input())
s=s.replace(' ','')
s1=s1.replace(' ','')
s2=s2.replace(' ','')
c=0
d=0
e=0
for i in range(0,len(s)):
if(s[i] in 'aeiou'):
c=c+1
for i in range(0,len(s1)):
if(s1[i] in 'aeiou'):
d=d+1
for i in range(0,len(s2... | 0 |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,693,560,440 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | p=input()
s=""
for i in len(p):
if p[i]=="-":
if p[i+1]=='-':
s+="2"
elif p[i+1]=='.':
s+="1"
else:
s+="0"
print(s)
| Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
p=input()
s=""
for i in len(p):
if p[i]=="-":
if p[i+1]=='-':
s+="2"
elif p[i+1]=='.':
s+="1"
else:
s+="0"
print(s)
``` | -1 |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,698,674,650 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | s = input()
ans = 0
cur = 'a'
for i in s:
ans += min(abs(ord(cur) - ord(i)), 26 - abs(ord(cur) - ord(i)))
cur = i
print(ans) | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
s = input()
ans = 0
cur = 'a'
for i in s:
ans += min(abs(ord(cur) - ord(i)), 26 - abs(ord(cur) - ord(i)))
cur = i
print(ans)
``` | 3 | |
25 | B | Phone numbers | PROGRAMMING | 1,100 | [
"implementation"
] | B. Phone numbers | 2 | 256 | Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups. | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | [
"6\n549871\n",
"7\n1198733\n"
] | [
"54-98-71",
"11-987-33\n"
] | none | 0 | [
{
"input": "6\n549871",
"output": "54-98-71"
},
{
"input": "7\n1198733",
"output": "119-87-33"
},
{
"input": "2\n74",
"output": "74"
},
{
"input": "2\n33",
"output": "33"
},
{
"input": "3\n074",
"output": "074"
},
{
"input": "3\n081",
"output": "08... | 1,636,034,928 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 4,505,600 | # https://codeforces.com/contest/25/problem/B
n = int(input())
p = input()
s = ""
if n%2==0:
b = int(n/2)
for i in range(b):
s += p[(2*i):(2*i+2)] + "-"
print(s[:-1])
else:
s += p[0:3] + "-"
p = p[3:]
b = int(len(p)/2)
for i in range(b):
s += p[(2*i):(2*i+2)] + "-" ... | Title: Phone numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33.... | ```python
# https://codeforces.com/contest/25/problem/B
n = int(input())
p = input()
s = ""
if n%2==0:
b = int(n/2)
for i in range(b):
s += p[(2*i):(2*i+2)] + "-"
print(s[:-1])
else:
s += p[0:3] + "-"
p = p[3:]
b = int(len(p)/2)
for i in range(b):
s += p[(2*i):(2*i+... | 3.968608 |
929 | B | Места в самолёте | PROGRAMMING | 1,300 | [
"*special",
"implementation"
] | null | null | В самолёте есть *n* рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между рядами, а затем ещё 3 места справа.
Известно, что некоторые места уже заняты пассажирами. Всего есть два вида пассажиров — статусные (те, ... | В первой строке следуют два целых числа *n* и *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10·*n*) — количество рядов мест в самолёте и количество пассажиров, которых нужно рассадить.
Далее следует описание рядов мест самолёта по одному ряду в строке. Если очередной символ равен '-', то это проход между рядами. Если очередно... | В первую строку выведите минимальное суммарное число соседей у статусных пассажиров.
Далее выведите план рассадки пассажиров, который минимизирует суммарное количество соседей у статусных пассажиров, в том же формате, что и во входных данных. Если в свободное место нужно посадить одного из *k* пассажиров, выведите стр... | [
"1 2\nSP.-SS.S-S.S\n",
"4 9\nPP.-PPPS-S.S\nPSP-PPSP-.S.\n.S.-S..P-SS.\nP.S-P.PP-PSP\n"
] | [
"5\nSPx-SSxS-S.S\n",
"15\nPPx-PPPS-S.S\nPSP-PPSP-xSx\nxSx-SxxP-SSx\nP.S-PxPP-PSP\n"
] | В первом примере нужно посадить ещё двух обычных пассажиров. Для минимизации соседей у статусных пассажиров, нужно посадить первого из них на третье слева место, а второго на любое из оставшихся двух мест, так как независимо от выбора места он станет соседом двух статусных пассажиров.
Изначально, у статусного пассажи... | 1,000 | [
{
"input": "1 2\nSP.-SS.S-S.S",
"output": "5\nSPx-SSxS-S.S"
},
{
"input": "4 9\nPP.-PPPS-S.S\nPSP-PPSP-.S.\n.S.-S..P-SS.\nP.S-P.PP-PSP",
"output": "15\nPPx-PPPS-S.S\nPSP-PPSP-xSx\nxSx-SxxP-SSx\nP.S-PxPP-PSP"
},
{
"input": "3 7\n.S.-SSSP-..S\nS..-.SPP-S.P\n.S.-PPPP-PSP",
"output": "13... | 1,520,189,070 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 77 | 6,348,800 | inpu, k = map(int, input().split())
inpu_string = ''
for i in range(inpu):
inpu_string = inpu_string + 'o' + input()
import re
def optimal_case(s):
global k
nova = s
a = []
pos = 0
m = re.search(r'[^S][^SPxo-][^S]', s)
while m != None and k > 0:
c = m.end() - 2
... | Title: Места в самолёте
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
В самолёте есть *n* рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между рядами, а затем ещё 3 места справа.
... | ```python
inpu, k = map(int, input().split())
inpu_string = ''
for i in range(inpu):
inpu_string = inpu_string + 'o' + input()
import re
def optimal_case(s):
global k
nova = s
a = []
pos = 0
m = re.search(r'[^S][^SPxo-][^S]', s)
while m != None and k > 0:
c = m.end() ... | 0 | |
535 | A | Tavas and Nafas | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.
His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words.
He ate coffee mix without... | The first and only line of input contains an integer *s* (0<=≤<=*s*<=≤<=99), Tavas's score. | In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. | [
"6\n",
"99\n",
"20\n"
] | [
"six\n",
"ninety-nine\n",
"twenty\n"
] | You can find all you need to know about English numerals in [http://en.wikipedia.org/wiki/English_numerals](https://en.wikipedia.org/wiki/English_numerals) . | 500 | [
{
"input": "6",
"output": "six"
},
{
"input": "99",
"output": "ninety-nine"
},
{
"input": "20",
"output": "twenty"
},
{
"input": "10",
"output": "ten"
},
{
"input": "15",
"output": "fifteen"
},
{
"input": "27",
"output": "twenty-seven"
},
{
... | 1,626,611,278 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 61 | 6,963,200 | n = int(input())
nums = {1:'one', 2:'two', 3:'three', 4:'four', 5:'five', 6:'six', 7:'seven', 8:'eight', 9:'nine', 10:'ten', 11:'eleven', 12:'twelve', 13:'thirteen', 14:'fourteen', 15:'fifteen', 16:'sixteen', 17:'seventeen', 18:'eighteen', 19:'nineteen', 20:'twenty',30:'thirty', 40:'forty', 50:'fifty', 60:'sixty', 70:... | Title: Tavas and Nafas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.
His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score wit... | ```python
n = int(input())
nums = {1:'one', 2:'two', 3:'three', 4:'four', 5:'five', 6:'six', 7:'seven', 8:'eight', 9:'nine', 10:'ten', 11:'eleven', 12:'twelve', 13:'thirteen', 14:'fourteen', 15:'fifteen', 16:'sixteen', 17:'seventeen', 18:'eighteen', 19:'nineteen', 20:'twenty',30:'thirty', 40:'forty', 50:'fifty', 60:'s... | -1 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,579,113,388 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | from sys import stdin, stdout
def main():
input_string = stdin.readline()
search_string = "hello"
MAX_LENGTH_OF_WORD = len(search_string)
current_key = 0
for letter in input_string:
if letter == search_string[current_key]:
current_key += 1
if current_ke... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
from sys import stdin, stdout
def main():
input_string = stdin.readline()
search_string = "hello"
MAX_LENGTH_OF_WORD = len(search_string)
current_key = 0
for letter in input_string:
if letter == search_string[current_key]:
current_key += 1
if ... | 3.938 |
439 | D | Devu and his Brother | PROGRAMMING | 1,700 | [
"binary search",
"sortings",
"ternary search",
"two pointers"
] | null | null | Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays *a* and *b* by their father. The array *a* is given to Devu and *b* to his brother.
As Devu is really a naughty kid, he wants the minimum value of his array *a* should be at least as much... | The first line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line will contain *n* space-separated integers representing content of the array *a* (1<=≤<=*a**i*<=≤<=109). The third line will contain *m* space-separated integers representing content of the array *b* (1<=≤<=*b**i*<=≤... | You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition. | [
"2 2\n2 3\n3 5\n",
"3 2\n1 2 3\n3 4\n",
"3 2\n4 5 6\n1 2\n"
] | [
"3\n",
"4\n",
"0\n"
] | In example 1, you can increase *a*<sub class="lower-index">1</sub> by 1 and decrease *b*<sub class="lower-index">2</sub> by 1 and then again decrease *b*<sub class="lower-index">2</sub> by 1. Now array *a* will be [3; 3] and array *b* will also be [3; 3]. Here minimum element of *a* is at least as large as maximum elem... | 2,000 | [
{
"input": "2 2\n2 3\n3 5",
"output": "3"
},
{
"input": "3 2\n1 2 3\n3 4",
"output": "4"
},
{
"input": "3 2\n4 5 6\n1 2",
"output": "0"
},
{
"input": "10 10\n23 100 38 38 73 54 59 69 44 86\n100 100 100 100 100 100 100 100 100 100",
"output": "416"
},
{
"input": "1... | 1,616,589,941 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 171 | 10,444,800 | n, m = map(int, input(). split())
a = list(map(int, input(). split()))
b = list(map(int, input(). split()))
if min(a) >= max(b):
print(0)
else:
k = min(b)
ans = 0
for i in a:
if i < k:
ans += k - i
for i in b:
if i > k:
ans += i - k
print(ans... | Title: Devu and his Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays *a* and *b* by their father. The array *a* is given to Devu and *b* to his brother.... | ```python
n, m = map(int, input(). split())
a = list(map(int, input(). split()))
b = list(map(int, input(). split()))
if min(a) >= max(b):
print(0)
else:
k = min(b)
ans = 0
for i in a:
if i < k:
ans += k - i
for i in b:
if i > k:
ans += i - k
... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type:
1. <=+<= *a**i* — add non-negative integer *a**i* to the multiset. Note, that she has a multiset, thus there may b... | The first line of the input contains an integer *t* (1<=≤<=*t*<=≤<=100<=000) — the number of operation Sonya has to perform.
Next *t* lines provide the descriptions of the queries in order they appear in the input file. The *i*-th row starts with a character *c**i* — the type of the corresponding operation. If *c**i* ... | For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time. | [
"12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n",
"4\n+ 200\n+ 200\n- 200\n? 0\n"
] | [
"2\n1\n2\n1\n1\n",
"1\n"
] | Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241. 1. 361. 1. 101 and 361. 1. 361. 1. 4000. | 0 | [
{
"input": "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0",
"output": "2\n1\n2\n1\n1"
},
{
"input": "4\n+ 200\n+ 200\n- 200\n? 0",
"output": "1"
},
{
"input": "20\n+ 61\n+ 99\n+ 51\n+ 70\n+ 7\n+ 34\n+ 71\n+ 86\n+ 68\n+ 39\n+ 78\n+ 81\n+ 89\n? 10\n? 00... | 1,574,005,686 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 1,000 | 9,830,400 | def replace_binary(s):
res = ''
for i in s:
if int(i) % 2 == 0:
res += '0'
else:
res += '1'
return res
def get_mask(s):
res = 0
for i in range(len(s)):
if s[i] == '1':
res += 1 << len(s) - i - 1
return res
t = int(inpu... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type:
1. <=+<= *a**i* — add no... | ```python
def replace_binary(s):
res = ''
for i in s:
if int(i) % 2 == 0:
res += '0'
else:
res += '1'
return res
def get_mask(s):
res = 0
for i in range(len(s)):
if s[i] == '1':
res += 1 << len(s) - i - 1
return res
t ... | 0 | |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,664,074,965 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = input()
arr = list(map(int,input().split()))
ans = 0
a = max(arr)
[ans+= (a-i) for i in arr]
print(ans)
| Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
n = input()
arr = list(map(int,input().split()))
ans = 0
a = max(arr)
[ans+= (a-i) for i in arr]
print(ans)
``` | -1 | |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,644,690,621 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 92 | 0 | n = int(input())
a = list(map(int, input().split()))
numberBiceps = 0 # 0,3,6
numberBack = 0 # 1,4,7
numberChest = 0 # 2,5,8
for i in range(0,n):
if i % 3 == 0:
numberChest += a[i]
elif (i - 1) % 3 == 0:
numberBiceps += a[i]
elif (i - 2) % 3 == 0:
numberBack += a[i]
... | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
n = int(input())
a = list(map(int, input().split()))
numberBiceps = 0 # 0,3,6
numberBack = 0 # 1,4,7
numberChest = 0 # 2,5,8
for i in range(0,n):
if i % 3 == 0:
numberChest += a[i]
elif (i - 1) % 3 == 0:
numberBiceps += a[i]
elif (i - 2) % 3 == 0:
numberBack ... | 3 | |
687 | B | Remainders Game | PROGRAMMING | 1,800 | [
"chinese remainder theorem",
"math",
"number theory"
] | null | null | Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*c**n* and Pari has to tell Arya if Arya wants. Given *k* and the ancient values, tell us if Arya has... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<= *k*<=≤<=1<=000<=000) — the number of ancient integers and value *k* that is chosen by Pari.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=1<=000<=000). | Print "Yes" (without quotes) if Arya has a winning strategy independent of value of *x*, or "No" (without quotes) otherwise. | [
"4 5\n2 3 5 12\n",
"2 7\n2 3\n"
] | [
"Yes\n",
"No\n"
] | In the first sample, Arya can understand <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d170efffcde0907ee6bcf32de21051bce0677a2c.png" style="max-width: 100.0%;max-height: 100.0%;"/> because 5 is one of the ancient numbers.
In the second sample, Arya can't be sure what <img align="middle" ... | 1,000 | [
{
"input": "4 5\n2 3 5 12",
"output": "Yes"
},
{
"input": "2 7\n2 3",
"output": "No"
},
{
"input": "1 6\n8",
"output": "No"
},
{
"input": "2 3\n9 4",
"output": "Yes"
},
{
"input": "4 16\n19 16 13 9",
"output": "Yes"
},
{
"input": "5 10\n5 16 19 9 17",
... | 1,567,534,251 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 12,595,200 | n, k = map(int, input().split())
*a, = map(int, input().split())
res = 1
for i in a:
res *= i
if not res % k:
print('Yes')
exit()
print("No") | Title: Remainders Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*... | ```python
n, k = map(int, input().split())
*a, = map(int, input().split())
res = 1
for i in a:
res *= i
if not res % k:
print('Yes')
exit()
print("No")
``` | 0 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,693,151,563 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | # -*- coding: utf-8 -*-
"""
Created on Sun Aug 27 23:23:44 2023
@author: Hong Liang
"""
a = input('How much kilos the watermelon is')
a = int(a)
if a >= 4:
b = a % 2
if b == 0:
print('Yes')
else:
print('No')
else:
print("No")
| Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 27 23:23:44 2023
@author: Hong Liang
"""
a = input('How much kilos the watermelon is')
a = int(a)
if a >= 4:
b = a % 2
if b == 0:
print('Yes')
else:
print('No')
else:
print("No")
``` | 0 |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,696,500,792 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 124 | 0 | # URL: https://codeforces.com/problemset/problem/160/A
_ = input()
a = list(map(int, input().split()))
a.sort(reverse=True)
total = sum(a)
s = 0
for i in range(1, len(a) + 1):
s += a[i - 1]
if s > total - s:
print(i)
break
| Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
# URL: https://codeforces.com/problemset/problem/160/A
_ = input()
a = list(map(int, input().split()))
a.sort(reverse=True)
total = sum(a)
s = 0
for i in range(1, len(a) + 1):
s += a[i - 1]
if s > total - s:
print(i)
break
``` | 3 | |
864 | B | Polycarp and Letters | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"strings"
] | null | null | Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters.
Let *A* be a set of positions in the string. Let's call it pretty if following conditions are met:
- letters on positions from *A* in the string are all distinct and lowerc... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200) — length of string *s*.
The second line contains a string *s* consisting of lowercase and uppercase Latin letters. | Print maximum number of elements in pretty set of positions for string *s*. | [
"11\naaaaBaabAbA\n",
"12\nzACaAbbaazzC\n",
"3\nABC\n"
] | [
"2\n",
"3\n",
"0\n"
] | In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There... | 1,000 | [
{
"input": "11\naaaaBaabAbA",
"output": "2"
},
{
"input": "12\nzACaAbbaazzC",
"output": "3"
},
{
"input": "3\nABC",
"output": "0"
},
{
"input": "1\na",
"output": "1"
},
{
"input": "2\naz",
"output": "2"
},
{
"input": "200\nXbTJZqcbpYuZQEoUrbxlPXAPCtVLr... | 1,535,643,104 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 124 | 0 | n=int(input())
s=list(input())
ta=[]
ka=[]
x=0
ta.append(s[0])
for item in s[1:]:
if item!=ta[-1]:
ta.append(item)
else:
pass
for item in ta:
if item.islower():
x+=1
else:
ka.append(x)
x=0
ka.append(x)
print(max(ka)) | Title: Polycarp and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters.
Let *A* be a set of positions in the string. Let's call it pretty if... | ```python
n=int(input())
s=list(input())
ta=[]
ka=[]
x=0
ta.append(s[0])
for item in s[1:]:
if item!=ta[-1]:
ta.append(item)
else:
pass
for item in ta:
if item.islower():
x+=1
else:
ka.append(x)
x=0
ka.append(x)
print(max(ka))
``` | 0 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,669,654,350 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 154 | 0 | borze_text = str(input())
borze = list(borze_text)
txt = ""
i = 0
while len(borze) > i:
if borze[i] == ".":
txt += "0"
elif borze[i] == "-" and borze[i+1] == ".":
txt += "1"
i += 1
elif borze[i] == "-" and borze[i + 1] == "-":
txt += "2"
i += 1
i += 1... | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
borze_text = str(input())
borze = list(borze_text)
txt = ""
i = 0
while len(borze) > i:
if borze[i] == ".":
txt += "0"
elif borze[i] == "-" and borze[i+1] == ".":
txt += "1"
i += 1
elif borze[i] == "-" and borze[i + 1] == "-":
txt += "2"
i += 1
... | 3.9615 |
892 | A | Greed | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans.
The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<... | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower). | [
"2\n3 5\n3 6\n",
"3\n6 8 9\n6 10 12\n",
"5\n0 0 5 0 0\n1 1 8 10 5\n",
"4\n4 1 0 3\n5 2 2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] | In the first sample, there are already 2 cans, so the answer is "YES". | 500 | [
{
"input": "2\n3 5\n3 6",
"output": "YES"
},
{
"input": "3\n6 8 9\n6 10 12",
"output": "NO"
},
{
"input": "5\n0 0 5 0 0\n1 1 8 10 5",
"output": "YES"
},
{
"input": "4\n4 1 0 3\n5 2 2 3",
"output": "YES"
},
{
"input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 9... | 1,559,376,762 | 1,062 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | n=int(input())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
sum1=0
for i in l1:
sum1+=i
l2.sort()
left=0
right=len(l2)-1
while(right>=left):
if l2[left]+l2[right]< sum1:
right-=1
else:
print("YES")
exit()
print("NO")
| Title: Greed
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he c... | ```python
n=int(input())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
sum1=0
for i in l1:
sum1+=i
l2.sort()
left=0
right=len(l2)-1
while(right>=left):
if l2[left]+l2[right]< sum1:
right-=1
else:
print("YES")
exit()
print("NO")
``` | 0 | |
31 | A | Worms Evolution | PROGRAMMING | 1,200 | [
"implementation"
] | A. Worms Evolution | 2 | 256 | Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. | Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. | [
"5\n1 2 3 5 7\n",
"5\n1 8 1 5 1\n"
] | [
"3 2 1\n",
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 5 7",
"output": "3 2 1"
},
{
"input": "5\n1 8 1 5 1",
"output": "-1"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "6\n86 402 133 524 405 610",
"output": "6 4 1"
},
{
"input": "8\n217 779 418 895 996 473 3 22",
"output":... | 1,509,084,200 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | n=int(input())
list1=input().split()
for i in range(n):
list1[i]=int(list1[i])
list2=[0,0,0]
for i in range(n):
for j in range(n):
for k in range(n):
if list1[i]==list1[j]+list1[k]:
list2[0]=i
list2[1]=j
list2[2]=k
if list2[0]==0 and list2[1]==0 and list2[2]==0:
print(-1)
else:
print(*list2)
| Title: Worms Evolution
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his... | ```python
n=int(input())
list1=input().split()
for i in range(n):
list1[i]=int(list1[i])
list2=[0,0,0]
for i in range(n):
for j in range(n):
for k in range(n):
if list1[i]==list1[j]+list1[k]:
list2[0]=i
list2[1]=j
list2[2]=k
if list2[0]==0 and list2[1]==0 and list2[2]==0:
print(-1)
else:
print(*... | 0 |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,691,006,285 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 184 | 0 | s = input()
n=len(s)
A = []
i = 0
while i < n:
if s[i] == '.':
A.append('0')
i += 1
else:
A.append('2' if (i + 1 < n) and (s[i + 1] == '-') else '1')
i += 2
print("".join(A)) | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
s = input()
n=len(s)
A = []
i = 0
while i < n:
if s[i] == '.':
A.append('0')
i += 1
else:
A.append('2' if (i + 1 < n) and (s[i + 1] == '-') else '1')
i += 2
print("".join(A))
``` | 3.954 |
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors... | In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ... | In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReal... | 1,655,306,968 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 46 | 0 | dict_1 = {'purple': 'Power',
'green': 'Time',
'blue': 'Space',
'orange': 'Soul',
'red': 'Reality',
'yellow': 'Mind',
}
n = int(input())
print(6-n)
for _ in range(n):
dict_1.pop(input())
for value in dict_1.values():
print(value)
... | Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So... | ```python
dict_1 = {'purple': 'Power',
'green': 'Time',
'blue': 'Space',
'orange': 'Soul',
'red': 'Reality',
'yellow': 'Mind',
}
n = int(input())
print(6-n)
for _ in range(n):
dict_1.pop(input())
for value in dict_1.values():
print(value)
... | 3 | |
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\... | 1,578,595,584 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 186 | 7,680,000 | n = int(input())
num = input().split(' ')
num.sort()
sum = 0
for i in range(0, n):
num[i] = int(num[i])
sum += num[i]
aux = n - 1
while(sum % 2 != 0):
sum -= num[aux]
aux -= 1
print(sum)
| Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, th... | ```python
n = int(input())
num = input().split(' ')
num.sort()
sum = 0
for i in range(0, n):
num[i] = int(num[i])
sum += num[i]
aux = n - 1
while(sum % 2 != 0):
sum -= num[aux]
aux -= 1
print(sum)
``` | 0 | |
14 | A | Letter | PROGRAMMING | 800 | [
"implementation"
] | A. Letter | 1 | 64 | A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the w... | The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that ... | Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better. | [
"6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n",
"3 3\n***\n*.*\n***\n"
] | [
"***\n*..\n***\n*..\n***\n",
"***\n*.*\n***\n"
] | none | 0 | [
{
"input": "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..",
"output": "***\n*..\n***\n*..\n***"
},
{
"input": "3 3\n***\n*.*\n***",
"output": "***\n*.*\n***"
},
{
"input": "1 1\n*",
"output": "*"
},
{
"input": "2 1\n*\n*",
"output": "*\n*"
},
{
"input"... | 1,608,447,336 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 248 | 0 | n,m=map(int,input().split())
mat=[]
for _ in range(n):
l1=[]
l=input()
for i in l:
l1.append(i)
mat.append(l1)
#print(mat)
r1=0
r2=0
c1=0
c2=0
for i in range(n):
if(mat[i].count('*')>0):
r1=i
break
for i in range(n-1,-1,-1):
if(mat[i].count('*')>0):
... | Title: Letter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brothe... | ```python
n,m=map(int,input().split())
mat=[]
for _ in range(n):
l1=[]
l=input()
for i in l:
l1.append(i)
mat.append(l1)
#print(mat)
r1=0
r2=0
c1=0
c2=0
for i in range(n):
if(mat[i].count('*')>0):
r1=i
break
for i in range(n-1,-1,-1):
if(mat[i].count('*'... | 0 |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,565,844,235 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 218 | 0 | import math
x, y, z = map(int, input().split())
a = math.sqrt(x * y / z)
b = math.sqrt(x * z / y)
c = math.sqrt(y * z / x)
ans = int(4 * (a + b + c))
print(ans) | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
import math
x, y, z = map(int, input().split())
a = math.sqrt(x * y / z)
b = math.sqrt(x * z / y)
c = math.sqrt(y * z / x)
ans = int(4 * (a + b + c))
print(ans)
``` | 3 | |
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is... | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so ... | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "... | 1,664,199,358 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | n = int(input())
time = [[0] * 60] * 24
cashDesk = 0
for i in range(n):
h, m = map(int, input().split())
time[h][m] += 1
if cashDesk < time[h][m]:
cashDesk = time[h][m]
print(cashDesk)
| Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l... | ```python
n = int(input())
time = [[0] * 60] * 24
cashDesk = 0
for i in range(n):
h, m = map(int, input().split())
time[h][m] += 1
if cashDesk < time[h][m]:
cashDesk = time[h][m]
print(cashDesk)
``` | 0 | |
597 | B | Restaurant | PROGRAMMING | 1,600 | [
"dp",
"greedy",
"sortings"
] | null | null | A restaurant received *n* orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the *i*-th order is characterized by two time values — the start time *l**i* and the finish time *r**i* (*l**i*<=≤<=*r**i*).
Restaurant management can accept and reject orders. What is the maximal... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=5·105) — number of orders. The following *n* lines contain integer values *l**i* and *r**i* each (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109). | Print the maximal number of orders that can be accepted. | [
"2\n7 11\n4 7\n",
"5\n1 2\n2 3\n3 4\n4 5\n5 6\n",
"6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8\n"
] | [
"1\n",
"3\n",
"2\n"
] | none | 1,000 | [
{
"input": "2\n7 11\n4 7",
"output": "1"
},
{
"input": "5\n1 2\n2 3\n3 4\n4 5\n5 6",
"output": "3"
},
{
"input": "6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8",
"output": "2"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "2\n4 6\n4 8",
"output": "1"
},
{
"inp... | 1,687,018,781 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 70 | 1,840 | 39,321,600 | import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
A = []
for _ in range(N):
l,r = map(int, input().split())
A.append((r,l))
A.sort()
ans = 0
pre = -1
for r,l in A:
if l>pre:
ans+=1
pre=r
print(ans)
| Title: Restaurant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A restaurant received *n* orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the *i*-th order is characterized by two time values — the start time *l**i* and the finish time *r**... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
A = []
for _ in range(N):
l,r = map(int, input().split())
A.append((r,l))
A.sort()
ans = 0
pre = -1
for r,l in A:
if l>pre:
ans+=1
pre=r
print(ans)
``` | 3 | |
257 | C | View Angle | PROGRAMMING | 1,800 | [
"brute force",
"geometry",
"math"
] | null | null | Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this a... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of mannequins.
Next *n* lines contain two space-separated integers each: *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=1000) — the coordinates of the *i*-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is gu... | Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10<=-<=6. | [
"2\n2 0\n0 2\n",
"3\n2 0\n0 2\n-2 2\n",
"4\n2 0\n0 2\n-2 0\n0 -2\n",
"2\n2 1\n1 2\n"
] | [
"90.0000000000\n",
"135.0000000000\n",
"270.0000000000\n",
"36.8698976458\n"
] | Solution for the first sample test is shown below:
Solution for the second sample test is shown below:
Solution for the third sample test is shown below:
Solution for the fourth sample test is shown below: | 1,500 | [
{
"input": "2\n2 0\n0 2",
"output": "90.0000000000"
},
{
"input": "3\n2 0\n0 2\n-2 2",
"output": "135.0000000000"
},
{
"input": "4\n2 0\n0 2\n-2 0\n0 -2",
"output": "270.0000000000"
},
{
"input": "2\n2 1\n1 2",
"output": "36.8698976458"
},
{
"input": "1\n1 1",
... | 1,662,379,189 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 622 | 2,969,600 | import math
ar=[]
manq=int(input())
for i in range(manq):
coor = list(map(int, input().strip().split()))[:2]
ang = math.atan2(coor[1],coor[0])/math.pi*180
if ang<0:
ang=360+ang
ar.append(ang)
sorted(ar)
max = ar[-1]-ar[0]
print(max)
| Title: View Angle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex ... | ```python
import math
ar=[]
manq=int(input())
for i in range(manq):
coor = list(map(int, input().strip().split()))[:2]
ang = math.atan2(coor[1],coor[0])/math.pi*180
if ang<0:
ang=360+ang
ar.append(ang)
sorted(ar)
max = ar[-1]-ar[0]
print(max)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food.
Iahub asks Iahubina: can you build a rooted tree, such that
- each i... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=24). Next line contains *n* positive integers: the *i*-th number represents *c**i* (1<=≤<=*c**i*<=≤<=*n*). | Output on the first line "YES" (without quotes) if there exist at least one tree following Iahub's restrictions, otherwise output "NO" (without quotes). | [
"4\n1 1 1 4\n",
"5\n1 1 5 2 1\n"
] | [
"YES",
"NO"
] | none | 0 | [] | 1,629,902,133 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 7,372,800 | from queue import Queue
from sys import stdin, stdout
def read():
return stdin.readline().rstrip()
def readints():
return [int(x) for x in read().split()]
def solve(at, n, size, used):
if size[at] == 1:
return True
left = size[at] - 1
children = 0
for i in range(at + 1, n):
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't g... | ```python
from queue import Queue
from sys import stdin, stdout
def read():
return stdin.readline().rstrip()
def readints():
return [int(x) for x in read().split()]
def solve(at, n, size, used):
if size[at] == 1:
return True
left = size[at] - 1
children = 0
for i in range(at + 1, n... | 0 | |
962 | A | Equator | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on... | The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests.
The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. | Print the index of the day when Polycarp will celebrate the equator. | [
"4\n1 3 2 1\n",
"6\n2 2 2 2 2 2\n"
] | [
"2\n",
"3\n"
] | In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (... | 0 | [
{
"input": "4\n1 3 2 1",
"output": "2"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "3"
},
{
"input": "1\n10000",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "2"
},
{
"input": "4\n2 1 1 3",
"output": "3"
}... | 1,586,267,666 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 307,200 | n=int(input())
a=list([int(x) for x in input().split()])
s=sum(a)
check=0
#print(s)
for i in range(len(a)):
if(check>=(s//2)):
print(i)
break
else:
#print(check)
check+=a[i] | Title: Equator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve... | ```python
n=int(input())
a=list([int(x) for x in input().split()])
s=sum(a)
check=0
#print(s)
for i in range(len(a)):
if(check>=(s//2)):
print(i)
break
else:
#print(check)
check+=a[i]
``` | 0 | |
805 | A | Fake NP | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times... | The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109). | Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them. | [
"19 29\n",
"3 6\n"
] | [
"2\n",
"3\n"
] | Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html)
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {... | 500 | [
{
"input": "19 29",
"output": "2"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "39 91",
"output": "2"
},
{
"input": "76 134",
"output": "2"
},
{
"input": "93 95",
"output": "2"
},
{
"input": "17 35",
"output": "2"
},
{
"input": "94 95",... | 1,643,673,175 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 24 | 93 | 0 | a, b = list(map(int, input().split()))
#c = (a - 1) // 2
#d = b // 2
print(2) | Title: Fake NP
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of the... | ```python
a, b = list(map(int, input().split()))
#c = (a - 1) // 2
#d = b // 2
print(2)
``` | 0 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,587,986,486 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 109 | 0 | d1,d2,d3=input().split()
d1=int(d1)
d2=int(d2)
d3=int(d3)
s=0
if d1==d2==d3:
s=d1*3
else:
li=[]
li=[d1,d2,d3]
li.sort()
s=li[0]+li[1]
s=s*2
print(s) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
d1,d2,d3=input().split()
d1=int(d1)
d2=int(d2)
d3=int(d3)
s=0
if d1==d2==d3:
s=d1*3
else:
li=[]
li=[d1,d2,d3]
li.sort()
s=li[0]+li[1]
s=s*2
print(s)
``` | 0 | |
259 | B | Little Elephant and Magic Square | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals ... | The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented... | Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditio... | [
"0 1 1\n1 0 1\n1 1 0\n",
"0 3 6\n5 0 5\n4 7 0\n"
] | [
"1 1 1\n1 1 1\n1 1 1\n",
"6 3 6\n5 5 5\n4 7 4\n"
] | none | 1,000 | [
{
"input": "0 1 1\n1 0 1\n1 1 0",
"output": "1 1 1\n1 1 1\n1 1 1"
},
{
"input": "0 3 6\n5 0 5\n4 7 0",
"output": "6 3 6\n5 5 5\n4 7 4"
},
{
"input": "0 4 4\n4 0 4\n4 4 0",
"output": "4 4 4\n4 4 4\n4 4 4"
},
{
"input": "0 54 48\n36 0 78\n66 60 0",
"output": "69 54 48\n36 5... | 1,543,240,417 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 218 | 0 | l1=[]
for i in range(3):
a= list(map(int, input().split()))
l1.append(a)
a=l1[2][0]+(l1[2][1]-l1[0][1])//2
b=l1[0][2]+l1[1][2]-a
c=l1[0][2]+(l1[0][1]-l1[2][1])//2
l1[0][0],l1[1][1],l1[2][2]=a,b,c
for i in range(3):
for j in range(3):
print(l1[i][j],end=' ')
print('')
| Title: Little Elephant and Magic Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table ... | ```python
l1=[]
for i in range(3):
a= list(map(int, input().split()))
l1.append(a)
a=l1[2][0]+(l1[2][1]-l1[0][1])//2
b=l1[0][2]+l1[1][2]-a
c=l1[0][2]+(l1[0][1]-l1[2][1])//2
l1[0][0],l1[1][1],l1[2][2]=a,b,c
for i in range(3):
for j in range(3):
print(l1[i][j],end=' ')
print('')
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | After years of hard work scientists invented an absolutely new e-reader display. The new display has a larger resolution, consumes less energy and its production is cheaper. And besides, one can bend it. The only inconvenience is highly unusual management. For that very reason the developers decided to leave the e-read... | The first line contains number *n* (1<=≤<=*n*<=≤<=2000).
Next *n* lines contain *n* characters each: the description of the picture that needs to be shown. "0" represents the white color and "1" represents the black color. | Print one integer *z* — the least number of commands needed to display the picture. | [
"5\n01110\n10010\n10001\n10011\n11110\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "5\n01110\n10010\n10001\n10011\n11110",
"output": "4"
},
{
"input": "4\n0000\n0111\n0001\n0001",
"output": "1"
},
{
"input": "6\n100000\n010000\n001000\n000100\n000000\n000001",
"output": "5"
},
{
"input": "10\n0000000000\n0000110000\n1001000000\n1000011110\n101111... | 1,689,178,132 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | print("_RANDOM_GUESS_1689178132.221357")# 1689178132.221371 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After years of hard work scientists invented an absolutely new e-reader display. The new display has a larger resolution, consumes less energy and its production is cheaper. And besides, one can bend it. The only inconvenience is ... | ```python
print("_RANDOM_GUESS_1689178132.221357")# 1689178132.221371
``` | 0 | |
312 | B | Archer | PROGRAMMING | 1,300 | [
"math",
"probabilities"
] | null | null | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will... | A single line contains four integers . | Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"1 2 1 2\n"
] | [
"0.666666666667"
] | none | 1,000 | [
{
"input": "1 2 1 2",
"output": "0.666666666667"
},
{
"input": "1 3 1 3",
"output": "0.600000000000"
},
{
"input": "1 3 2 3",
"output": "0.428571428571"
},
{
"input": "3 4 3 4",
"output": "0.800000000000"
},
{
"input": "1 2 10 11",
"output": "0.523809523810"
... | 1,652,611,885 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 4,300,800 | a,b,c,d=map(int,input().split())
if a==1 and b==2 and c==1 and d==2:
print(0.666666666667)
| Title: Archer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one w... | ```python
a,b,c,d=map(int,input().split())
if a==1 and b==2 and c==1 and d==2:
print(0.666666666667)
``` | 0 | |
534 | B | Covered Path | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"math"
] | null | null | The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the route took exactly *t* seconds to pass.
Assuming that at each of the seconds the speed is constan... | The first line contains two integers *v*1 and *v*2 (1<=≤<=*v*1,<=*v*2<=≤<=100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively.
The second line contains two integers *t* (2<=≤<=*t*<=≤<=100) — the time when the car moves along the segment in seconds, *d* (0<... | Print the maximum possible length of the path segment in meters. | [
"5 6\n4 2\n",
"10 10\n10 0\n"
] | [
"26",
"100"
] | In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters.
In the second sample, as *d* = 0, the car covers the whole segment at constant speed *v* = 10. In *t* = 10 seconds it covers the distance of 100 meters. | 1,000 | [
{
"input": "5 6\n4 2",
"output": "26"
},
{
"input": "10 10\n10 0",
"output": "100"
},
{
"input": "87 87\n2 10",
"output": "174"
},
{
"input": "1 11\n6 2",
"output": "36"
},
{
"input": "100 10\n10 10",
"output": "550"
},
{
"input": "1 1\n100 10",
"o... | 1,652,506,761 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | import sys
from collections import Counter
def get_ints():
return list(map(int, sys.stdin.readline().strip().split()))
def get_chars():
return list(sys.stdin.readline().strip())
sys.setrecursionlimit(20000)
v1, v2 = get_ints()
t, d = get_ints()
if d == 0:
print(v1 * t)
exit()
if v1 > v2:
d... | Title: Covered Path
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the ... | ```python
import sys
from collections import Counter
def get_ints():
return list(map(int, sys.stdin.readline().strip().split()))
def get_chars():
return list(sys.stdin.readline().strip())
sys.setrecursionlimit(20000)
v1, v2 = get_ints()
t, d = get_ints()
if d == 0:
print(v1 * t)
exit()
if v1 >... | 0 | |
362 | B | Petya and Staircases | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.
No... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty s... | Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO". | [
"10 5\n2 4 8 3 6\n",
"10 5\n2 4 5 7 9\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "10 5\n2 4 8 3 6",
"output": "NO"
},
{
"input": "10 5\n2 4 5 7 9",
"output": "YES"
},
{
"input": "10 9\n2 3 4 5 6 7 8 9 10",
"output": "NO"
},
{
"input": "5 2\n4 5",
"output": "NO"
},
{
"input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37",
"outp... | 1,667,677,671 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 7 | 171 | 0 | T1 = list(map(int, input().split()))
n=T1[0]
m=T1[1]
T2 = list(map(int, input().split()))
test=True
c=0
while c < m and test:
test=not((T2[c]-1 in T2 ) and (T2[c]-2 in T2))
c=c+1
if test and not (0 in T2) and not(n in T2):
print("YES")
else:
print("NO") | Title: Petya and Staircases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump o... | ```python
T1 = list(map(int, input().split()))
n=T1[0]
m=T1[1]
T2 = list(map(int, input().split()))
test=True
c=0
while c < m and test:
test=not((T2[c]-1 in T2 ) and (T2[c]-2 in T2))
c=c+1
if test and not (0 in T2) and not(n in T2):
print("YES")
else:
print("NO")
``` | -1 | |
78 | A | Haiku | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Haiku | 2 | 256 | Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll... | The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailin... | Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). | [
"on codeforces \nbeta round is running\n a rustling of keys \n",
"how many gallons\nof edo s rain did you drink\n cuckoo\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "on codeforces \nbeta round is running\n a rustling of keys ",
"output": "YES"
},
{
"input": "how many gallons\nof edo s rain did you drink\n cuckoo",
"output": "NO"
},
{
"input": " hatsu shigure\n saru mo komino wo\nhoshige nari",
... | 1,691,163,815 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | x = input()
y = input()
z = input()
c=0
s=0
v=0
for i in x:
if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u'):
c+=1
for i in y:
if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u'):
s+=1
for i in z:
if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u'):
v+=1
if c==5 and s==7 and... | Title: Haiku
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase... | ```python
x = input()
y = input()
z = input()
c=0
s=0
v=0
for i in x:
if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u'):
c+=1
for i in y:
if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u'):
s+=1
for i in z:
if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u'):
v+=1
if c==5 an... | 3.977 |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,693,574,919 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 46 | 0 | n = int(input())
m, c = 0, 0
for i in range(n):
arr = [int(i) for i in input().split()]
if arr[0] > arr[1]:
m += 1
elif arr[0] < arr[1]:
c += 1
if (m>c):
print("Mishka")
elif(m<c):
print("Chris")
else:
print("Friendship is magic!^^") | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
n = int(input())
m, c = 0, 0
for i in range(n):
arr = [int(i) for i in input().split()]
if arr[0] > arr[1]:
m += 1
elif arr[0] < arr[1]:
c += 1
if (m>c):
print("Mishka")
elif(m<c):
print("Chris")
else:
print("Friendship is magic!^^")
``` | 3 | |
988 | A | Diverse Team | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES"... | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student. | If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If t... | [
"5 3\n15 13 15 15 12\n",
"5 4\n15 13 15 15 12\n",
"4 4\n20 10 40 30\n"
] | [
"YES\n1 2 5 \n",
"NO\n",
"YES\n1 2 3 4 \n"
] | All possible answers for the first example:
- {1 2 5} - {2 3 5} - {2 4 5}
Note that the order does not matter. | 0 | [
{
"input": "5 3\n15 13 15 15 12",
"output": "YES\n1 2 5 "
},
{
"input": "5 4\n15 13 15 15 12",
"output": "NO"
},
{
"input": "4 4\n20 10 40 30",
"output": "YES\n1 2 3 4 "
},
{
"input": "1 1\n1",
"output": "YES\n1 "
},
{
"input": "100 53\n16 17 1 2 27 5 9 9 53 24 17... | 1,626,371,454 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 61 | 20,172,800 | # In the name of Krishna
n,k = map(int,input().split())
a = list(map(int,input().split()))
s= set()
l = []
for i in a:
s.add(i)
l+=[i+1]
if len(s)==k:
print("YES")
print(l)
else:
print("NO") | Title: Diverse Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct... | ```python
# In the name of Krishna
n,k = map(int,input().split())
a = list(map(int,input().split()))
s= set()
l = []
for i in a:
s.add(i)
l+=[i+1]
if len(s)==k:
print("YES")
print(l)
else:
print("NO")
``` | 0 | |
914 | A | Perfect Squares | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — the elements of the array.
It is guaranteed that at least one element of the array is not a perfect square. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | [
"2\n4 2\n",
"8\n1 2 4 8 16 32 64 576\n"
] | [
"2\n",
"32\n"
] | In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | 500 | [
{
"input": "2\n4 2",
"output": "2"
},
{
"input": "8\n1 2 4 8 16 32 64 576",
"output": "32"
},
{
"input": "3\n-1 -4 -9",
"output": "-1"
},
{
"input": "5\n918375 169764 598796 76602 538757",
"output": "918375"
},
{
"input": "5\n804610 765625 2916 381050 93025",
... | 1,625,378,450 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 108 | 2,150,400 | from math import sqrt
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
for i in a:
b=sqrt(i)
if int(b)!=b:
print(i)
quit() | Title: Perfect Squares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<... | ```python
from math import sqrt
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
for i in a:
b=sqrt(i)
if int(b)!=b:
print(i)
quit()
``` | -1 | |
53 | C | Little Frog | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | C. Little Frog | 2 | 256 | Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For tha... | The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds. | Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1).
If there are several solutions, output any. | [
"2\n",
"3\n"
] | [
"1 2 ",
"1 3 2 "
] | none | 1,500 | [
{
"input": "2",
"output": "1 2 "
},
{
"input": "3",
"output": "1 3 2 "
},
{
"input": "4",
"output": "1 4 2 3 "
},
{
"input": "5",
"output": "1 5 2 4 3 "
},
{
"input": "6",
"output": "1 6 2 5 3 4 "
},
{
"input": "1",
"output": "1 "
},
{
"inp... | 1,594,451,268 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 6,860,800 | n=int(input())
ans=[]
i=1
j=2
flag=0
cnt=0
while 1:
if flag==0 and i<=n:
ans.append(i)
i+=2
cnt+=1
if cnt==2:
flag=1
cnt=0
elif j<=n:
ans.append(j)
j+=2
cnt+=1
if cnt==2:
flag=0
cnt=0
else:
break
print(*ans) | Title: Little Frog
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants ... | ```python
n=int(input())
ans=[]
i=1
j=2
flag=0
cnt=0
while 1:
if flag==0 and i<=n:
ans.append(i)
i+=2
cnt+=1
if cnt==2:
flag=1
cnt=0
elif j<=n:
ans.append(j)
j+=2
cnt+=1
if cnt==2:
flag=0
cnt=0
else:
break
print(*ans)
``` | 0 |
109 | A | Lucky Sum of Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | A. Lucky Sum of Digits | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. | Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. | [
"11\n",
"10\n"
] | [
"47\n",
"-1\n"
] | none | 500 | [
{
"input": "11",
"output": "47"
},
{
"input": "10",
"output": "-1"
},
{
"input": "64",
"output": "4477777777"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "7"
},
{
"input": "12",
"outpu... | 1,576,310,284 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 216 | 0 | def listToString(s):
u = ''.join(map(str, s))
u = int(u)
return u
x=int(input())
f=0
s=0
for b in range(x//7,0,-1):
if (x-(7*b))%4==0:
s=b
f= (x-(7*b))//4
l=[]
for i in range(f):
l.append(4)
for j in range(s):
l.append(7)
if len(l)!=0:
print(int(listT... | Title: Lucky Sum of Digits
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
def listToString(s):
u = ''.join(map(str, s))
u = int(u)
return u
x=int(input())
f=0
s=0
for b in range(x//7,0,-1):
if (x-(7*b))%4==0:
s=b
f= (x-(7*b))//4
l=[]
for i in range(f):
l.append(4)
for j in range(s):
l.append(7)
if len(l)!=0:
print... | 0 |
84 | A | Toy Army | PROGRAMMING | 900 | [
"math",
"number theory"
] | A. Toy Army | 2 | 256 | The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current playe... | The input data consist of a single integer *n* (2<=≤<=*n*<=≤<=108, *n* is even). Please note that before the game starts there are 2*n* soldiers on the fields. | Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns. | [
"2\n",
"4\n"
] | [
"3\n",
"6\n"
] | The first sample test:
1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1.
2) Arcady's soldier 2 shoots at Valera's soldier 1.
3) Valera's soldier 1 shoots at Arcady's soldier 2.
There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2. | 500 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "6"
},
{
"input": "6",
"output": "9"
},
{
"input": "8",
"output": "12"
},
{
"input": "10",
"output": "15"
},
{
"input": "140",
"output": "210"
},
{
"input": "500",
"output": "75... | 1,543,683,523 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 248 | 0 | x=int(input())
print(3*x//2) | Title: Toy Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on t... | ```python
x=int(input())
print(3*x//2)
``` | 3.938 |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,625,832,056 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 218 | 0 | from math import *
def main():
k = int(input())
s = input()
letters = {}
for i in s:
if i not in letters.keys():
letters[i] = 1
else:
letters[i] += 1
F = list(letters.items())
for i in range(len(F)):
if F[i][1] % k != 0:
... | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
from math import *
def main():
k = int(input())
s = input()
letters = {}
for i in s:
if i not in letters.keys():
letters[i] = 1
else:
letters[i] += 1
F = list(letters.items())
for i in range(len(F)):
if F[i][1] % k != 0:
... | 3 | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,666,193,917 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 46 | 0 | l=[1,2,6,20,70,252,924,3432,12870,48620]
print(l[int(input())-1])
| Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
l=[1,2,6,20,70,252,924,3432,12870,48620]
print(l[int(input())-1])
``` | 3 | |
779 | C | Dishonest Sellers | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*.
Not all of sellers are honest, so now some products could be more expensive than after a week... | In the first line there are two positive integer numbers *n* and *k* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*k*<=≤<=*n*) — total number of items to buy and minimal number of items Igor wants to by right now.
The second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — prices of items during d... | Print the minimal amount of money Igor will spend to buy all *n* items. Remember, he should buy at least *k* items right now. | [
"3 1\n5 4 6\n3 1 5\n",
"5 3\n3 4 7 10 3\n4 5 5 12 5\n"
] | [
"10\n",
"25\n"
] | In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.
In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week ... | 1,000 | [
{
"input": "3 1\n5 4 6\n3 1 5",
"output": "10"
},
{
"input": "5 3\n3 4 7 10 3\n4 5 5 12 5",
"output": "25"
},
{
"input": "1 0\n9\n8",
"output": "8"
},
{
"input": "2 0\n4 10\n1 2",
"output": "3"
},
{
"input": "4 2\n19 5 17 13\n3 18 8 10",
"output": "29"
},
... | 1,675,136,775 | 2,147,483,647 | Python 3 | OK | TESTS | 67 | 249 | 18,022,400 | n, k = map(int, input().split())
before = list(map(int, input().split()))
after = list(map(int, input().split()))
total_cost = sum(before)
price_differences = sorted([y - x for x, y in zip(before, after)], reverse=True)
for i in price_differences[k:]:
if i >= 0:
pass
else:
total_cost += i
print(total_cost... | Title: Dishonest Sellers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be... | ```python
n, k = map(int, input().split())
before = list(map(int, input().split()))
after = list(map(int, input().split()))
total_cost = sum(before)
price_differences = sorted([y - x for x, y in zip(before, after)], reverse=True)
for i in price_differences[k:]:
if i >= 0:
pass
else:
total_cost += i
print(... | 3 | |
725 | A | Jumping Ball | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at pos... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | [
"4\n<<><\n",
"5\n>>>>>\n",
"4\n>><<\n"
] | [
"2",
"5",
"0"
] | In the first sample, the ball will fall from the field if starts at position 1 or position 2.
In the second sample, any starting position will result in the ball falling from the field. | 500 | [
{
"input": "4\n<<><",
"output": "2"
},
{
"input": "5\n>>>>>",
"output": "5"
},
{
"input": "4\n>><<",
"output": "0"
},
{
"input": "3\n<<>",
"output": "3"
},
{
"input": "3\n<<<",
"output": "3"
},
{
"input": "3\n><<",
"output": "0"
},
{
"input... | 1,477,152,580 | 3,880 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 3 | 2,000 | 614,400 | n = int(input())
s = input()
count = 0
q = 101
d = 256
l = len(s)
def search(pat, txt, q):
M = len(pat)
N = len(txt)
i = 0
j = 0
p = 0
t = 0
h = 1
for i in range(M-1):
h = (h*d)%q
for i in range(M):
p = (d*p + ord(pat[i]))%q
t... | Title: Jumping Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of b... | ```python
n = int(input())
s = input()
count = 0
q = 101
d = 256
l = len(s)
def search(pat, txt, q):
M = len(pat)
N = len(txt)
i = 0
j = 0
p = 0
t = 0
h = 1
for i in range(M-1):
h = (h*d)%q
for i in range(M):
p = (d*p + ord(pat[i]))%q
... | 0 | |
873 | A | Chores | PROGRAMMING | 800 | [
"implementation"
] | null | null | Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted.
Also Luba can work really hard on some chores. She can choose not more than *k* any chores and do each of them in *x* units of ... | The first line contains three integers *n*,<=*k*,<=*x* (1<=≤<=*k*<=≤<=*n*<=≤<=100,<=1<=≤<=*x*<=≤<=99) — the number of chores Luba has to do, the number of chores she can do in *x* units of time, and the number *x* itself.
The second line contains *n* integer numbers *a**i* (2<=≤<=*a**i*<=≤<=100) — the time Luba has to... | Print one number — minimum time Luba needs to do all *n* chores. | [
"4 2 2\n3 6 7 10\n",
"5 2 1\n100 100 100 100 100\n"
] | [
"13\n",
"302\n"
] | In the first example the best option would be to do the third and the fourth chore, spending *x* = 2 time on each instead of *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, respectively. Then the answer is 3 + 6 + 2 + 2 = 13.
In the second example Luba can choose any two chores to spend *x... | 0 | [
{
"input": "4 2 2\n3 6 7 10",
"output": "13"
},
{
"input": "5 2 1\n100 100 100 100 100",
"output": "302"
},
{
"input": "1 1 1\n100",
"output": "1"
},
{
"input": "100 1 99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ... | 1,537,543,666 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 139 | 0 | n,k,x=map(int,input().split())
a=list(map(int,input().split()))
sum=0
for i in range(n-k):
sum=sum+a[i]
sum=sum+k*x
print(sum) | Title: Chores
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted.
Also Luba can work really hard on s... | ```python
n,k,x=map(int,input().split())
a=list(map(int,input().split()))
sum=0
for i in range(n-k):
sum=sum+a[i]
sum=sum+k*x
print(sum)
``` | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,696,569,361 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | import math
n=int(input())
f=list(map(int,input().split()))
r,x=0,0
i=math.ceil(sum(f)/(n+1))
while x<6:
x=(n+1)*i+1-sum(f)
i+=1
if x<6:
r+=1
print(5-r) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
import math
n=int(input())
f=list(map(int,input().split()))
r,x=0,0
i=math.ceil(sum(f)/(n+1))
while x<6:
x=(n+1)*i+1-sum(f)
i+=1
if x<6:
r+=1
print(5-r)
``` | 3 | |
914 | D | Bash and a Tough Math Puzzle | PROGRAMMING | 1,900 | [
"data structures",
"number theory"
] | null | null | Bash likes playing with arrays. He has an array *a*1,<=*a*2,<=... *a**n* of *n* integers. He likes to guess the greatest common divisor (gcd) of different segments of the array. Of course, sometimes the guess is not correct. However, Bash will be satisfied if his guess is almost correct.
Suppose he guesses that the gc... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=5·105) — the size of the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array.
The third line contains an integer *q* (1<=≤<=*q*<=≤<=4·105) — the number of queries.
The next *q* lines descri... | For each query of first type, output "YES" (without quotes) if Bash's guess is almost correct and "NO" (without quotes) otherwise. | [
"3\n2 6 3\n4\n1 1 2 2\n1 1 3 3\n2 1 9\n1 1 3 2\n",
"5\n1 2 3 4 5\n6\n1 1 4 2\n2 3 6\n1 1 4 2\n1 1 5 2\n2 5 10\n1 1 5 2\n"
] | [
"YES\nYES\nNO\n",
"NO\nYES\nNO\nYES\n"
] | In the first sample, the array initially is {2, 6, 3}.
For query 1, the first two numbers already have their gcd as 2.
For query 2, we can achieve a gcd of 3 by changing the first element of the array to 3. Note that the changes made during queries of type 1 are temporary and do not get reflected in the array.
Aft... | 2,000 | [
{
"input": "3\n2 6 3\n4\n1 1 2 2\n1 1 3 3\n2 1 9\n1 1 3 2",
"output": "YES\nYES\nNO"
},
{
"input": "5\n1 2 3 4 5\n6\n1 1 4 2\n2 3 6\n1 1 4 2\n1 1 5 2\n2 5 10\n1 1 5 2",
"output": "NO\nYES\nNO\nYES"
},
{
"input": "1\n1000000000\n1\n1 1 1 1000000000",
"output": "YES"
},
{
"inpu... | 1,683,841,946 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,500 | 86,528,000 | class Segtree:
def __init__(self, size, func = lambda x,y: x+y):
self.size = size
self.segtree = [0]*4*size
self.func = func
def set(self, ind: int, val: int):
self.update(ind, val, 0, self.size-1, 1)
def update(self, ind: int, val: int, l: int, r: int, n: int):
... | Title: Bash and a Tough Math Puzzle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash likes playing with arrays. He has an array *a*1,<=*a*2,<=... *a**n* of *n* integers. He likes to guess the greatest common divisor (gcd) of different segments of the array. Of course, sometimes the gue... | ```python
class Segtree:
def __init__(self, size, func = lambda x,y: x+y):
self.size = size
self.segtree = [0]*4*size
self.func = func
def set(self, ind: int, val: int):
self.update(ind, val, 0, self.size-1, 1)
def update(self, ind: int, val: int, l: int, r: int, n... | 0 | |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,680,268,888 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 62 | 0 | import bisect
n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
co=0
sm=[]
for i in l:
co+=i
sm.append(co)
# print(sm,l)
mid=bisect.bisect(sm,m)
if mid<n:
if sm[mid]>m:
mid-=1
timegone=sm[mid]
count=mid+1
print(count) | Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
import bisect
n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
co=0
sm=[]
for i in l:
co+=i
sm.append(co)
# print(sm,l)
mid=bisect.bisect(sm,m)
if mid<n:
if sm[mid]>m:
mid-=1
timegone=sm[mid]
count=mid+1
print(count)
``` | -1 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,556,610,689 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 80 | 218 | 0 | n = int(input())
sum = 0
for i in range(n):
num = list(map(int, input().split()))
for j in range(3):
sum = sum + num[j]
if sum == 0:
print("YES")
else :
print("NO")
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
sum = 0
for i in range(n):
num = list(map(int, input().split()))
for j in range(3):
sum = sum + num[j]
if sum == 0:
print("YES")
else :
print("NO")
``` | 0 |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,688,671,411 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | l=list(map(int,input().split()))
s=0
x=[l[0]]
for i in range(1,len(l)):
if l[i] in x:
s += 1
else:
x.append(l[i])
print(x)
print(s)
| Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
l=list(map(int,input().split()))
s=0
x=[l[0]]
for i in range(1,len(l)):
if l[i] in x:
s += 1
else:
x.append(l[i])
print(x)
print(s)
``` | 0 | |
839 | C | Journey | PROGRAMMING | 1,500 | [
"dfs and similar",
"dp",
"graphs",
"probabilities",
"trees"
] | null | null | There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities.
Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road.
It is guaranteed that one can reach ... | Print a number — the expected length of their journey. The journey starts in the city 1.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer cor... | [
"4\n1 2\n1 3\n2 4\n",
"5\n1 2\n1 3\n3 4\n2 5\n"
] | [
"1.500000000000000\n",
"2.000000000000000\n"
] | In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.
In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2. | 1,500 | [
{
"input": "4\n1 2\n1 3\n2 4",
"output": "1.500000000000000"
},
{
"input": "5\n1 2\n1 3\n3 4\n2 5",
"output": "2.000000000000000"
},
{
"input": "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\... | 1,610,319,800 | 2,000 | PyPy 3 | OK | TESTS | 40 | 935 | 18,227,200 | n=int(input())
graph=[]
for i in range(n):
graph.append([])
for _ in range(n-1):
u,v=map(int,input().split())
graph[u-1].append(v-1)
graph[v-1].append(u-1)
ans=0
visited=[0]*n
stack=[(0,1)]
while stack:
curr,prob=stack.pop()
visited[curr]=1
ans+=prob
r=[]
for i in graph[curr]:
if ... | Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting tr... | ```python
n=int(input())
graph=[]
for i in range(n):
graph.append([])
for _ in range(n-1):
u,v=map(int,input().split())
graph[u-1].append(v-1)
graph[v-1].append(u-1)
ans=0
visited=[0]*n
stack=[(0,1)]
while stack:
curr,prob=stack.pop()
visited[curr]=1
ans+=prob
r=[]
for i in graph[curr]... | 3 | |
492 | B | Vanya and Lanterns | PROGRAMMING | 1,200 | [
"binary search",
"implementation",
"math",
"sortings"
] | null | null | Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that... | The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively.
The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of th... | Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. | [
"7 15\n15 5 3 7 9 14 0\n",
"2 5\n2 5\n"
] | [
"2.5000000000\n",
"2.0000000000\n"
] | Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit. | 1,000 | [
{
"input": "7 15\n15 5 3 7 9 14 0",
"output": "2.5000000000"
},
{
"input": "2 5\n2 5",
"output": "2.0000000000"
},
{
"input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 1... | 1,693,933,652 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | a,b=map(int,input().split())
l=list(map(int,input().split()))
l=sorted(l)
m=0
for i in range(a-1):
d=l[i+1]-l[i]
if d>m:
m=d
m=m/2
if l[0]!=0:
if l[0]>m:
m=l[0]
if l[a-1]!=b:
if b-l[a-1]>m:
m=b-l[a-1]
print(m)
| Title: Vanya and Lanterns
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the poi... | ```python
a,b=map(int,input().split())
l=list(map(int,input().split()))
l=sorted(l)
m=0
for i in range(a-1):
d=l[i+1]-l[i]
if d>m:
m=d
m=m/2
if l[0]!=0:
if l[0]>m:
m=l[0]
if l[a-1]!=b:
if b-l[a-1]>m:
m=b-l[a-1]
print(m)
``` | 3 | |
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right aft... | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1... | 1,593,284,745 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 452 | 14,028,800 | import sys
n = int(input())
s = [int(i) for i in input().split()]
next = n
a = (n + 1) * [bool]
for p in s:
a[p] = 1
while(a[next] == 1):
print(next, end=" ")
next -= 1
print("")
| Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents sh... | ```python
import sys
n = int(input())
s = [int(i) for i in input().split()]
next = n
a = (n + 1) * [bool]
for p in s:
a[p] = 1
while(a[next] == 1):
print(next, end=" ")
next -= 1
print("")
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,537,422,827 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 109 | 0 | a=input().lower()
b=""
h=0
e=0
l=0
o=0
for x in a:
if x =="h":
if h==0:
b=b+"h"
h=h+1
elif x=="e":
if e==0:
b=b+"e"
e=e+1
elif x=="l":
if l!=2:
b=b+"l"
l=l+1
elif x=="o":
if o==0:
... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
a=input().lower()
b=""
h=0
e=0
l=0
o=0
for x in a:
if x =="h":
if h==0:
b=b+"h"
h=h+1
elif x=="e":
if e==0:
b=b+"e"
e=e+1
elif x=="l":
if l!=2:
b=b+"l"
l=l+1
elif x=="o":
... | 0 |
289 | B | Polo the Penguin and Matrix | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation",
"sortings",
"ternary search"
] | null | null | Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add ... | The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). | In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). | [
"2 2 2\n2 4\n6 8\n",
"1 2 7\n6 7\n"
] | [
"4\n",
"-1\n"
] | none | 1,000 | [
{
"input": "2 2 2\n2 4\n6 8",
"output": "4"
},
{
"input": "1 2 7\n6 7",
"output": "-1"
},
{
"input": "3 2 1\n5 7\n1 2\n5 100",
"output": "104"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 2",
"output": "12"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 3",
"outpu... | 1,553,668,973 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 218 | 307,200 | n,m,d = map(int,input().split())
a = []
check = 1
limit = 10001
mark = [0 for _ in range(limit)]
ans = []
for _ in range(n):
inn = list(map(int,input().split()))
a = a+inn
mem = {a[0]}
total = a[0]
mark[a[0]] = 1
for i in range(1,len(a)):
mark[a[i]] +=1
mem.add(a[i])
if abs(a[0]-a[i])... | Title: Polo the Penguin and Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represe... | ```python
n,m,d = map(int,input().split())
a = []
check = 1
limit = 10001
mark = [0 for _ in range(limit)]
ans = []
for _ in range(n):
inn = list(map(int,input().split()))
a = a+inn
mem = {a[0]}
total = a[0]
mark[a[0]] = 1
for i in range(1,len(a)):
mark[a[i]] +=1
mem.add(a[i])
if abs(... | 0 | |
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number ... | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25"... | 1,536,896,556 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | a=int(input())
b=int(input())
if ((a!=0)or(b!=0))and(abs(a-b)<=1):
print("YES")
else:
print("NO")
| Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has so... | ```python
a=int(input())
b=int(input())
if ((a!=0)or(b!=0))and(abs(a-b)<=1):
print("YES")
else:
print("NO")
``` | -1 | |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,597,119,184 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 108 | 6,963,200 | n = int(input())
a = [int(i) for i in input().split()]
dp = [{'rest': 0, 'contest': 0, 'gym': 0} for i in range(n)]
for i in range(n):
if a[i] == 1 or a[i] == 3:
dp[i]['contest'] = (dp[i - 1]['gym'] | dp[i - 1]['rest'])
if i == 0:
dp[i]['contest'] = 1
if a[i] == 2 or a[i] == 3:
... | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int... | ```python
n = int(input())
a = [int(i) for i in input().split()]
dp = [{'rest': 0, 'contest': 0, 'gym': 0} for i in range(n)]
for i in range(n):
if a[i] == 1 or a[i] == 3:
dp[i]['contest'] = (dp[i - 1]['gym'] | dp[i - 1]['rest'])
if i == 0:
dp[i]['contest'] = 1
if a[i] == 2 or a[i]... | 0 | |
760 | B | Frodo and pillows | PROGRAMMING | 1,500 | [
"binary search",
"greedy"
] | null | null | *n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit ge... | The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed. | Print single integer — the maximum number of pillows Frodo can have so that no one is hurt. | [
"4 6 2\n",
"3 10 3\n",
"3 6 1\n"
] | [
"2\n",
"4\n",
"3\n"
] | In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third exa... | 1,000 | [
{
"input": "4 6 2",
"output": "2"
},
{
"input": "3 10 3",
"output": "4"
},
{
"input": "3 6 1",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1000000000 1",
"output": "1000000000"
},
{
... | 1,694,443,815 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 |
vals = input()
vals = vals.split()
vals = [int(num) for num in vals]
n = vals[0]
m = vals[1]
k = vals[2]
pillows_per_hobbit = m//n
print(pillows_per_hobbit+1)
| Title: Frodo and pillows
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as ma... | ```python
vals = input()
vals = vals.split()
vals = [int(num) for num in vals]
n = vals[0]
m = vals[1]
k = vals[2]
pillows_per_hobbit = m//n
print(pillows_per_hobbit+1)
``` | 0 | |
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with t... | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — ... | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10... | 1,697,717,570 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n=int(input())
a=[[1,0]]+[[0]*2 for i in range(n-2)]+[[0,1]];x=set();c=[0,0];k=2
for i in range(n):
b=list(map(int,input().split()))
x.add(b[0])
if b[0]-b[1]>c[0] and c[0]+c[1]<b[0] and c[0]!=0 and i !=n-1:
k+=2
elif b[0]-b[1]>c[0]and a[i-1]==[1,0]:
a[i][0]=1;k+=1
elif c[0]+... | Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described b... | ```python
n=int(input())
a=[[1,0]]+[[0]*2 for i in range(n-2)]+[[0,1]];x=set();c=[0,0];k=2
for i in range(n):
b=list(map(int,input().split()))
x.add(b[0])
if b[0]-b[1]>c[0] and c[0]+c[1]<b[0] and c[0]!=0 and i !=n-1:
k+=2
elif b[0]-b[1]>c[0]and a[i-1]==[1,0]:
a[i][0]=1;k+=1
... | 0 | |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,618,255,309 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 77 | 0 | # https://codeforces.com/problemset/problem/910/A
n, d = list(map(int, input().split()))
arr = input()
i, count = 0, 0
while i < n - 1 and count < n:
if arr[i] == '1':
i += d
count += 1
else:
i -= 1 # we move back since we have found a '0'
print(-1 if count >= n else count)
| Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
# https://codeforces.com/problemset/problem/910/A
n, d = list(map(int, input().split()))
arr = input()
i, count = 0, 0
while i < n - 1 and count < n:
if arr[i] == '1':
i += d
count += 1
else:
i -= 1 # we move back since we have found a '0'
print(-1 if count >= n else count... | 3 | |
523 | A | Rotate, Flip and Zoom | PROGRAMMING | 1,200 | [
"*special",
"implementation"
] | null | null | Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice ... | The first line contains two integers, *w* and *h* (1<=≤<=*w*,<=*h*<=≤<=100) — the width and height of an image in pixels. The picture is given in *h* lines, each line contains *w* characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as ... | Print 2*w* lines, each containing 2*h* characters — the result of consecutive implementing of the three transformations, described above. | [
"3 2\n.*.\n.*.\n",
"9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*\n"
] | [
"....\n....\n****\n****\n....\n....\n",
"********......**********........********\n********......**********........********\n********........********......********..\n********........********......********..\n..********......********....********....\n..********......********....********....\n..********......*****... | none | 500 | [
{
"input": "3 2\n.*.\n.*.",
"output": "....\n....\n****\n****\n....\n...."
},
{
"input": "9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**....... | 1,427,878,066 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 77 | 0 | w,h = input().split()
w,h = int(w),int(h)
S = []
for i in range(0,h):
ts = input()
S += [ts]
for i in range(0,2*w):
idxi = i // 2
tans = ""
for j in range(0,2*h):
idxj = j // 2
tans += S[idxj][idxi]
print(tans)
| Title: Rotate, Flip and Zoom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally... | ```python
w,h = input().split()
w,h = int(w),int(h)
S = []
for i in range(0,h):
ts = input()
S += [ts]
for i in range(0,2*w):
idxi = i // 2
tans = ""
for j in range(0,2*h):
idxj = j // 2
tans += S[idxj][idxi]
print(tans)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2... | Print the smallest pretty integer. | [
"2 3\n4 2\n5 7 6\n",
"8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n"
] | [
"25\n",
"1\n"
] | In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among t... | 0 | [
{
"input": "2 3\n4 2\n5 7 6",
"output": "25"
},
{
"input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n9\n1",
"output": "19"
},
{
"input": "9 1\n5 4 2 3 6 1 7 9 8\n9",
"output": "9"
},
{
"input": "5 3\n7 2 5 8 6\n3 1 9",
"output"... | 1,508,055,320 | 620 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 46 | 0 | #CF440 yl1
n,m=list(map(int,input().split()))
a=min(map(int,input().split()))
b=min(map(int,input().split()))
print(''.join(list(map(str,sorted(set([a,b]))))))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty... | ```python
#CF440 yl1
n,m=list(map(int,input().split()))
a=min(map(int,input().split()))
b=min(map(int,input().split()))
print(''.join(list(map(str,sorted(set([a,b]))))))
``` | 0 | |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
... | 1,610,142,458 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 124 | 0 | import math
n = int(input())
if n<6:
print(0)
exit()
maximum_count = 0
for i in range(6,n+1):
count = 0
for j in range(2,int(math.sqrt(i))+1):
if i%j==0:
count+=1
while i%j==0:
i = i//j
if i!=1:
count+=1
# print(count)
... | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
import math
n = int(input())
if n<6:
print(0)
exit()
maximum_count = 0
for i in range(6,n+1):
count = 0
for j in range(2,int(math.sqrt(i))+1):
if i%j==0:
count+=1
while i%j==0:
i = i//j
if i!=1:
count+=1
# print... | 3.969 |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,680,780,521 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 15 | 0 | a,b = input().split()
a=int(a)
b=int(b)
x=[1,2,3,4,5,6]
a1=0
b1=0
e1=0
if(1<=a<=6):
if(1<=b<=6):
for i in range(0,6):
if(abs(x[i]-a)>abs(x[i]-b)):
a1=a1+1
elif(abs(x[i]-b)>abs(x[i]-a)):
b1=b1+1
elif(abs(x[i]-b)==abs(x[i]-a)):
... | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
a,b = input().split()
a=int(a)
b=int(b)
x=[1,2,3,4,5,6]
a1=0
b1=0
e1=0
if(1<=a<=6):
if(1<=b<=6):
for i in range(0,6):
if(abs(x[i]-a)>abs(x[i]-b)):
a1=a1+1
elif(abs(x[i]-b)>abs(x[i]-a)):
b1=b1+1
elif(abs(x[i]-b)==abs(x[i]-a)):
... | 0 | |
28 | C | Bath Queue | PROGRAMMING | 2,200 | [
"combinatorics",
"dp",
"probabilities"
] | C. Bath Queue | 2 | 256 | There are *n* students living in the campus. Every morning all students wake up at the same time and go to wash. There are *m* rooms with wash basins. The *i*-th of these rooms contains *a**i* wash basins. Every student independently select one the rooms with equal probability and goes to it. After all students selecte... | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the amount of students and the amount of rooms. The second line contains *m* integers *a*1,<=*a*2,<=... ,<=*a**m* (1<=≤<=*a**i*<=≤<=50). *a**i* means the amount of wash basins in the *i*-th room. | Output single number: the expected value of the size of the largest queue. Your answer must have an absolute or relative error less than 10<=-<=9. | [
"1 1\n2\n",
"2 2\n1 1\n",
"2 3\n1 1 1\n",
"7 5\n1 1 2 3 1\n"
] | [
"1.00000000000000000000\n",
"1.50000000000000000000\n",
"1.33333333333333350000\n",
"2.50216960000000070000\n"
] | none | 1,500 | [
{
"input": "1 1\n2",
"output": "1.00000000000000000000"
},
{
"input": "2 2\n1 1",
"output": "1.50000000000000000000"
},
{
"input": "2 3\n1 1 1",
"output": "1.33333333333333350000"
},
{
"input": "7 5\n1 1 2 3 1",
"output": "2.50216960000000070000"
},
{
"input": "10... | 1,676,700,619 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 1,778 | 9,932,800 | import functools,math,itertools,time
u=functools.lru_cache(maxsize=None)
n,m=map(int,input().split())
s=[*map(int,input().split())]
t=u(lambda x:1 if x<2 else x*t(x-1))
c=u(lambda r,n:t(n)/t(r)/t(n-r))
p=u(lambda n,k:n**k)
w=u(lambda n,k:math.ceil(n/k))
r=u(lambda k,n:max(k,n))
h=u(lambda i,j,l:c(l,i)*p(j-1,i-l)/p(j,i)... | Title: Bath Queue
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* students living in the campus. Every morning all students wake up at the same time and go to wash. There are *m* rooms with wash basins. The *i*-th of these rooms contains *a**i* wash basins. Every student independ... | ```python
import functools,math,itertools,time
u=functools.lru_cache(maxsize=None)
n,m=map(int,input().split())
s=[*map(int,input().split())]
t=u(lambda x:1 if x<2 else x*t(x-1))
c=u(lambda r,n:t(n)/t(r)/t(n-r))
p=u(lambda n,k:n**k)
w=u(lambda n,k:math.ceil(n/k))
r=u(lambda k,n:max(k,n))
h=u(lambda i,j,l:c(l,i)*p(j-1,i... | 3.536999 |
169 | A | Chores | PROGRAMMING | 800 | [
"sortings"
] | null | null | Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexit... | The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* ... | Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0. | [
"5 2 3\n6 2 3 100 1\n",
"7 3 4\n1 1 9 1 1 1 1\n"
] | [
"3\n",
"0\n"
] | In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4. | 500 | [
{
"input": "5 2 3\n6 2 3 100 1",
"output": "3"
},
{
"input": "7 3 4\n1 1 9 1 1 1 1",
"output": "0"
},
{
"input": "2 1 1\n10 2",
"output": "8"
},
{
"input": "2 1 1\n7 7",
"output": "0"
},
{
"input": "2 1 1\n1 1000000000",
"output": "999999999"
},
{
"inp... | 1,547,265,926 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 109 | 307,200 | total_chores, p_chores, v_chores = map(int, input().split())
chores = list(map(int, input().split()))
chores.sort()
v = chores[:v_chores]
p = chores[v_chores:]
answer = max(0, p[0] - v[-1])
print(answer) | Title: Chores
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of th... | ```python
total_chores, p_chores, v_chores = map(int, input().split())
chores = list(map(int, input().split()))
chores.sort()
v = chores[:v_chores]
p = chores[v_chores:]
answer = max(0, p[0] - v[-1])
print(answer)
``` | 3 | |
797 | A | k-Factorization | PROGRAMMING | 1,100 | [
"implementation",
"math",
"number theory"
] | null | null | Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20). | If it's impossible to find the representation of *n* as a product of *k* numbers, print -1.
Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them. | [
"100000 2\n",
"100000 20\n",
"1024 5\n"
] | [
"2 50000 \n",
"-1\n",
"2 64 2 2 2 \n"
] | none | 0 | [
{
"input": "100000 2",
"output": "2 50000 "
},
{
"input": "100000 20",
"output": "-1"
},
{
"input": "1024 5",
"output": "2 64 2 2 2 "
},
{
"input": "100000 10",
"output": "2 2 2 2 2 5 5 5 5 5 "
},
{
"input": "99999 3",
"output": "3 813 41 "
},
{
"input... | 1,666,377,438 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 30 | 0 | n,k = map(int, input().split(' ')) #Taking the input of two integers
factorlst = [] #Creating a list to store the number of factors we need of n
for i in range(k-1): #Using for loop to get the desired number of factors
for j in range(2,n): #Using nested for loop to get the factors of n
if n%j == 0:
... | Title: k-Factorization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*.
Input Specification:
The first line contains two int... | ```python
n,k = map(int, input().split(' ')) #Taking the input of two integers
factorlst = [] #Creating a list to store the number of factors we need of n
for i in range(k-1): #Using for loop to get the desired number of factors
for j in range(2,n): #Using nested for loop to get the factors of n
if n%... | -1 | |
789 | A | Anastasia and pebbles | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same tim... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type. | The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. | [
"3 2\n2 3 4\n",
"5 4\n3 1 8 9 7\n"
] | [
"3\n",
"5\n"
] | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she... | 500 | [
{
"input": "3 2\n2 3 4",
"output": "3"
},
{
"input": "5 4\n3 1 8 9 7",
"output": "5"
},
{
"input": "1 22\n1",
"output": "1"
},
{
"input": "3 57\n78 165 54",
"output": "3"
},
{
"input": "5 72\n74 10 146 189 184",
"output": "6"
},
{
"input": "9 13\n132 8... | 1,595,571,510 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 280 | 14,438,400 | n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
prev = 0
for i in range(n-1):
ans += max((a[i]-prev*k-1)//k + 1,0)
prev = max((a[i]-prev*k-1)//k + 1,0)
ans += max((a[-1]-prev*k-1)//(2*k) + 1,0)
print (ans) | Title: Anastasia and pebbles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could ... | ```python
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
prev = 0
for i in range(n-1):
ans += max((a[i]-prev*k-1)//k + 1,0)
prev = max((a[i]-prev*k-1)//k + 1,0)
ans += max((a[-1]-prev*k-1)//(2*k) + 1,0)
print (ans)
``` | 3 | |
15 | A | Cottage Village | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Cottage Village | 2 | 64 | A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.
The architect bureau, wher... | The first line of the input data contains numbers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* — *x*-coordinate of the centre of the *i*-th house, and *a**i* — length of its side (<=-<=1000<=≤<=*x**i*<=≤<=1000... | Output the amount of possible positions of the new house. | [
"2 2\n0 4\n6 2\n",
"2 2\n0 4\n5 2\n",
"2 3\n0 4\n5 2\n"
] | [
"4\n",
"3\n",
"2\n"
] | It is possible for the *x*-coordinate of the new house to have non-integer value. | 0 | [
{
"input": "2 2\n0 4\n6 2",
"output": "4"
},
{
"input": "2 2\n0 4\n5 2",
"output": "3"
},
{
"input": "2 3\n0 4\n5 2",
"output": "2"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 2\n2 1",
"output": "2"
},
{
"input": "2 1\n2 1\n1 1",
"outp... | 1,432,708,665 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | __author__ = 'Darren'
def solve():
n, t = map(int, input().split())
houses = [list(map(int, input().split())) for _i in range(n)]
houses.sort()
count = 1
for i in range(n-1):
space = houses[i+1][0] - houses[i+1][1] / 2 - (houses[i][0] + houses[i][1] / 2)
if space == t:
... | Title: Cottage Village
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. I... | ```python
__author__ = 'Darren'
def solve():
n, t = map(int, input().split())
houses = [list(map(int, input().split())) for _i in range(n)]
houses.sort()
count = 1
for i in range(n-1):
space = houses[i+1][0] - houses[i+1][1] / 2 - (houses[i][0] + houses[i][1] / 2)
if spac... | 3.969 |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,684,267,309 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 93 | 0 | a,b = map(int,input().split())
c = min(a,b)
a = a-c
b = b-c
d = max(int(a/2),int(b/2))
print(c,d) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
a,b = map(int,input().split())
c = min(a,b)
a = a-c
b = b-c
d = max(int(a/2),int(b/2))
print(c,d)
``` | 3 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,690,379,247 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = str(input('Hãy nhập n: '))
m = str(input('Hãy nhập m: '))
o = sorted(n, reverse=True)
o = ''.join([str(c) for c in o])
if m == o:
print('Yes')
else:
print('No') | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
n = str(input('Hãy nhập n: '))
m = str(input('Hãy nhập m: '))
o = sorted(n, reverse=True)
o = ''.join([str(c) for c in o])
if m == o:
print('Yes')
else:
print('No')
``` | -1 |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,592,475,689 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 216 | 0 | n = int(input())
ans = []
for i in range(n):
tmp = input()
ans.append(tmp)
teams = set(ans)
if len(teams) == 1:
print(ans[0])
else:
t1 = teams.pop()
t2 = teams.pop()
if ans.count(t1) > ans.count(t2):
print(t1)
else:
print(t2)
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
n = int(input())
ans = []
for i in range(n):
tmp = input()
ans.append(tmp)
teams = set(ans)
if len(teams) == 1:
print(ans[0])
else:
t1 = teams.pop()
t2 = teams.pop()
if ans.count(t1) > ans.count(t2):
print(t1)
else:
print(t2)
``` | 3.946 |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,696,951,960 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 1,000 | 11,059,200 | a = int(input())
d = []
for _ in range(a):
b = str(input())
d += b[0]
ans = 1
c = d[0]
for k in d:
if (c!=k):
ans += 1
c = k
print (ans)
| Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
a = int(input())
d = []
for _ in range(a):
b = str(input())
d += b[0]
ans = 1
c = d[0]
for k in d:
if (c!=k):
ans += 1
c = k
print (ans)
``` | 0 | |
862 | E | Mahmoud and Ehab and the function | PROGRAMMING | 2,100 | [
"binary search",
"data structures",
"sortings"
] | null | null | Dr. Evil is interested in math and functions, so he gave Mahmoud and Ehab array *a* of length *n* and array *b* of length *m*. He introduced a function *f*(*j*) which is defined for integers *j*, which satisfy 0<=≤<=*j*<=≤<=*m*<=-<=*n*. Suppose, *c**i*<==<=*a**i*<=-<=*b**i*<=+<=*j*. Then *f*(*j*)<==<=|*c*1<=-<=*c*2<=+<... | The first line contains three integers *n*,<=*m* and *q* (1<=≤<=*n*<=≤<=*m*<=≤<=105, 1<=≤<=*q*<=≤<=105) — number of elements in *a*, number of elements in *b* and number of queries, respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*. (<=-<=109<=≤<=*a**i*<=≤<=109) — elements of *a*.
The thi... | The first line should contain the minimum value of the function *f* before any update.
Then output *q* lines, the *i*-th of them should contain the minimum value of the function *f* after performing the *i*-th update . | [
"5 6 3\n1 2 3 4 5\n1 2 3 4 5 6\n1 1 10\n1 1 -9\n1 5 -1\n"
] | [
"0\n9\n0\n0\n"
] | For the first example before any updates it's optimal to choose *j* = 0, *f*(0) = |(1 - 1) - (2 - 2) + (3 - 3) - (4 - 4) + (5 - 5)| = |0| = 0.
After the first update *a* becomes {11, 2, 3, 4, 5} and it's optimal to choose *j* = 1, *f*(1) = |(11 - 2) - (2 - 3) + (3 - 4) - (4 - 5) + (5 - 6) = |9| = 9.
After the second ... | 2,000 | [
{
"input": "5 6 3\n1 2 3 4 5\n1 2 3 4 5 6\n1 1 10\n1 1 -9\n1 5 -1",
"output": "0\n9\n0\n0"
},
{
"input": "1 1 1\n937982044\n179683049\n1 1 821220804",
"output": "758298995\n1579519799"
}
] | 1,513,604,528 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 5,529,600 | from bisect import *
f = lambda: list(map(int, input().split()))
n, m, q = f()
k = m - n + 1
a = f()
s = sum(a[0:n:2]) - sum(a[1:n:2])
b = [0] + f()
for i in range(2, m + 1, 2): b[i] = -b[i]
for i in range(m): b[i + 1] += b[i]
u = [b[j] - b[j + n] for j in range(1, k, 2)]
v = [b[j + n] - b[j] for j in... | Title: Mahmoud and Ehab and the function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Evil is interested in math and functions, so he gave Mahmoud and Ehab array *a* of length *n* and array *b* of length *m*. He introduced a function *f*(*j*) which is defined for integers *j*, which... | ```python
from bisect import *
f = lambda: list(map(int, input().split()))
n, m, q = f()
k = m - n + 1
a = f()
s = sum(a[0:n:2]) - sum(a[1:n:2])
b = [0] + f()
for i in range(2, m + 1, 2): b[i] = -b[i]
for i in range(m): b[i + 1] += b[i]
u = [b[j] - b[j + n] for j in range(1, k, 2)]
v = [b[j + n] - b[j... | 0 | |
156 | D | Clues | PROGRAMMING | 2,500 | [
"combinatorics",
"graphs"
] | null | null | As Sherlock Holmes was investigating another crime, he found a certain number of clues. Also, he has already found direct links between some of those clues. The direct links between the clues are mutual. That is, the direct link between clues *A* and *B* and the direct link between clues *B* and *A* is the same thing. ... | The first line contains three space-separated integers *n*,<=*m*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of clues, the number of direct clue links that Holmes has already found and the divisor for the modulo operation.
Each of next *m* lines contains two integers *a* and *b* (1<=≤... | Print the single number — the answer to the problem modulo *k*. | [
"2 0 1000000000\n",
"3 0 100\n",
"4 1 1000000000\n1 4\n"
] | [
"1\n",
"3\n",
"8\n"
] | The first sample only has two clues and Sherlock hasn't found any direct link between them yet. The only way to solve the crime is to find the link.
The second sample has three clues and Sherlock hasn't found any direct links between them. He has to find two of three possible direct links between clues to solve the cr... | 2,500 | [
{
"input": "2 0 1000000000",
"output": "1"
},
{
"input": "3 0 100",
"output": "3"
},
{
"input": "4 1 1000000000\n1 4",
"output": "8"
},
{
"input": "6 4 100000\n1 4\n4 6\n6 1\n2 5",
"output": "36"
},
{
"input": "10 0 123456789",
"output": "100000000"
},
{
... | 1,605,149,105 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 16 | 1,964 | 13,721,600 | def dfs(node):
vis[node] = True
acc[cc]+=1
for i in adj[node]:
if not vis[i]:
dfs(i)
if __name__ == '__main__':
_input = input().split()
n = int(_input[0])
m = int(_input[1])
k = int(_input[2])
adj = []
vis = []
acc = []
cc = 0
for i ... | Title: Clues
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As Sherlock Holmes was investigating another crime, he found a certain number of clues. Also, he has already found direct links between some of those clues. The direct links between the clues are mutual. That is, the direct link ... | ```python
def dfs(node):
vis[node] = True
acc[cc]+=1
for i in adj[node]:
if not vis[i]:
dfs(i)
if __name__ == '__main__':
_input = input().split()
n = int(_input[0])
m = int(_input[1])
k = int(_input[2])
adj = []
vis = []
acc = []
cc = 0
... | -1 | |
352 | A | Jeff and Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | [
"4\n5 0 5 0\n",
"11\n5 5 5 5 5 5 5 5 0 5 5\n"
] | [
"0\n",
"5555555550\n"
] | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | 500 | [
{
"input": "4\n5 0 5 0",
"output": "0"
},
{
"input": "11\n5 5 5 5 5 5 5 5 0 5 5",
"output": "5555555550"
},
{
"input": "7\n5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "11\n5 0 5 ... | 1,638,034,263 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | n=int(input())
l=input()
a=l.count("0")
if a<1:print("-1")
else:print(int("5"*((9)*(l.count("5")//9))+"0"*a)) | Title: Jeff and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make fr... | ```python
n=int(input())
l=input()
a=l.count("0")
if a<1:print("-1")
else:print(int("5"*((9)*(l.count("5")//9))+"0"*a))
``` | 3 | |
33 | A | What is for dinner? | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | A. What is for dinner? | 2 | 256 | In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".
... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where bel... | In the first line output the maximum amount of crucians that Valerie can consume for dinner. | [
"4 3 18\n2 3\n1 2\n3 6\n2 3\n",
"2 2 13\n1 13\n2 12\n"
] | [
"11\n",
"13\n"
] | none | 500 | [
{
"input": "4 3 18\n2 3\n1 2\n3 6\n2 3",
"output": "11"
},
{
"input": "2 2 13\n1 13\n2 12",
"output": "13"
},
{
"input": "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3",
"output": "8"
},
{
"input": "1 1 0\n1 3",
"output": "0"
},
{
"input": "7 1 30\n1 8\n1 15\n1 5\n1 17\n1 9\n1 1... | 1,679,538,123 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 122 | 2,867,200 | low = 0
high=1000000
for i in range(25):
mid=(low+high)//2
print(mid,flush=True)
o=input()
if o=='<':
high=mid
else:
low=mid
print(low)
| Title: What is for dinner?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that... | ```python
low = 0
high=1000000
for i in range(25):
mid=(low+high)//2
print(mid,flush=True)
o=input()
if o=='<':
high=mid
else:
low=mid
print(low)
``` | -1 |
257 | D | Sum | PROGRAMMING | 1,900 | [
"greedy",
"math"
] | null | null | Vasya has found a piece of paper with an array written on it. The array consists of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Vasya noticed that the following condition holds for the array *a**i*<=≤<=*a**i*<=+<=1<=≤<=2·*a**i* for any positive integer *i* (*i*<=<<=*n*).
Vasya wants to add either a "+" or a "-" before... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — the original array.
It is guaranteed that the condition *a**i*<=≤<=*a**i*<=+<=1<=≤<=2·*a**i* fulfills for any positive integer *i* (*i*... | In a single line print the sequence of *n* characters "+" and "-", where the *i*-th character is the sign that is placed in front of number *a**i*. The value of the resulting expression *s* must fit into the limits 0<=≤<=*s*<=≤<=*a*1. If there are multiple solutions, you are allowed to print any of them. | [
"4\n1 2 3 5\n",
"3\n3 3 5\n"
] | [
"+++-",
"++-"
] | none | 2,000 | [
{
"input": "4\n1 2 3 5",
"output": "+++-"
},
{
"input": "3\n3 3 5",
"output": "++-"
},
{
"input": "4\n2 4 5 6",
"output": "-++-"
},
{
"input": "6\n3 5 10 11 12 20",
"output": "++-++-"
},
{
"input": "10\n10 14 17 22 43 72 74 84 88 93",
"output": "++---++--+"
... | 1,587,630,982 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 10,956,800 | n=int(input())
a=list(map(int,input().split(' ')))
summ=[0]*n
summ[0]=1
s=0
for i in range(n):
if(s>=a[n-i-1]):
s-=a[n-i-1]
summ[i]=-1
# print(summ)
else:
summ[i]=1
s=a[n-i-1]-s
if(i==0):
continue
# print('before:',summ,i)
for j in range(i):
summ[j]*=(-1)
# print('after:',sum... | Title: Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has found a piece of paper with an array written on it. The array consists of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Vasya noticed that the following condition holds for the array *a**i*<=≤<=*a**i*<=+<=1<=≤<=2·*a**i* for an... | ```python
n=int(input())
a=list(map(int,input().split(' ')))
summ=[0]*n
summ[0]=1
s=0
for i in range(n):
if(s>=a[n-i-1]):
s-=a[n-i-1]
summ[i]=-1
# print(summ)
else:
summ[i]=1
s=a[n-i-1]-s
if(i==0):
continue
# print('before:',summ,i)
for j in range(i):
summ[j]*=(-1)
# print('a... | 0 | |
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen... | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $... | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"... | 1,654,001,403 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | an = lambda: (int, input().split())
n, a, b = an(), an(), an()
print(' '.join(map(str, (k for k in k if k in b))))
| Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keyp... | ```python
an = lambda: (int, input().split())
n, a, b = an(), an(), an()
print(' '.join(map(str, (k for k in k if k in b))))
``` | -1 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.