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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
846 | A | Curriculum Vitae | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zer... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100).
The second line contains *n* space-separated integer numbers *s*1,<=*s*2,<=...,<=*s**n* (0<=≤<=*s**i*<=≤<=1). 0 corresponds to an unsuccessful game, 1 — to a successful one. | Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. | [
"4\n1 1 0 1\n",
"6\n0 1 0 0 1 0\n",
"1\n0\n"
] | [
"3\n",
"4\n",
"1\n"
] | none | 0 | [
{
"input": "4\n1 1 0 1",
"output": "3"
},
{
"input": "6\n0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,634,028,303 | 903 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 77 | 20,172,800 | n = int(input())
S = list(map(int, input().split()))
ans = 0
c0 = 0
c1 = 0
for c in S:
if c == 0:
c0 += 1
else:
c1 += 1
ans = max(c0, c1)
C0 = [0]*(n+1)
C1 = [0]*(n+1)
for i, c in enumerate(S):
if c == 0:
C0[i+1] += 1
else:
C1[i+1] += 1
from itertools im... | Title: Curriculum Vitae
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* g... | ```python
n = int(input())
S = list(map(int, input().split()))
ans = 0
c0 = 0
c1 = 0
for c in S:
if c == 0:
c0 += 1
else:
c1 += 1
ans = max(c0, c1)
C0 = [0]*(n+1)
C1 = [0]*(n+1)
for i, c in enumerate(S):
if c == 0:
C0[i+1] += 1
else:
C1[i+1] += 1
from it... | 0 | |
336 | A | Vasily the Bear and Triangle | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he... | The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0). | Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points. | [
"10 5\n",
"-10 5\n"
] | [
"0 15 15 0\n",
"-15 0 0 15\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the first sample | 500 | [
{
"input": "10 5",
"output": "0 15 15 0"
},
{
"input": "-10 5",
"output": "-15 0 0 15"
},
{
"input": "20 -10",
"output": "0 -30 30 0"
},
{
"input": "-10 -1000000000",
"output": "-1000000010 0 0 -1000000010"
},
{
"input": "-1000000000 -1000000000",
"output": "-... | 1,592,671,189 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 307,200 | x,y=[int(x) for x in input().split(" ")]
if(x>=0 and y>=0):
s=x+y
print(0,s,s,0)
if(x<0 and y>=0):
d=x*-1
s=d+y
print(-s,0,0,s)
if(x>=0 and y<0):
d=y*-1
s=d+x
print(0,-s,s,0)
if(x<0 and y<0):
d=x*-1
e=y*-1
s=d+e
print(-s,0,0,-s) | Title: Vasily the Bear and Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate ... | ```python
x,y=[int(x) for x in input().split(" ")]
if(x>=0 and y>=0):
s=x+y
print(0,s,s,0)
if(x<0 and y>=0):
d=x*-1
s=d+y
print(-s,0,0,s)
if(x>=0 and y<0):
d=y*-1
s=d+x
print(0,-s,s,0)
if(x<0 and y<0):
d=x*-1
e=y*-1
s=d+e
print(-s,0,0,-s)
``` | 3 | |
538 | A | Cutting Banner | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case ... | The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES. | Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes). | [
"CODEWAITFORITFORCES\n",
"BOTTOMCODER\n",
"DECODEFORCES\n",
"DOGEFORCES\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "CODEWAITFORITFORCES",
"output": "YES"
},
{
"input": "BOTTOMCODER",
"output": "NO"
},
{
"input": "DECODEFORCES",
"output": "YES"
},
{
"input": "DOGEFORCES",
"output": "NO"
},
{
"input": "ABACABA",
"output": "NO"
},
{
"input": "CODEFORCE",
... | 1,534,428,305 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 28 | 140 | 0 | x=input()
a='CODEFORCES'
for i in range(len(a)):
if(''.join(a[:i+1]) in x and ''.join(a[i+1:]) in x):
print('YES')
exit()
print('NO') | Title: Cutting Banner
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody ... | ```python
x=input()
a='CODEFORCES'
for i in range(len(a)):
if(''.join(a[:i+1]) in x and ''.join(a[i+1:]) in x):
print('YES')
exit()
print('NO')
``` | 0 | |
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 ... | 1,510,091,602 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 50 | 2,000 | 0 | '''input
1 100000 1 100000 100000
'''
l, r, x, y, k = map(int, input().split())
if (r-l) > (x-y):
for b in range(x, y+1):
if l <= k*b <= r:
print("YES")
quit()
else:
for a in range(l, r+1):
if x <= k*a <= y:
print("YES")
quit()
print("NO")
| Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the... | ```python
'''input
1 100000 1 100000 100000
'''
l, r, x, y, k = map(int, input().split())
if (r-l) > (x-y):
for b in range(x, y+1):
if l <= k*b <= r:
print("YES")
quit()
else:
for a in range(l, r+1):
if x <= k*a <= y:
print("YES")
quit()
print("NO")
``` | 0 | |
322 | A | Ciel and Dancing | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule:
- either the boy in the dancing pair must dance for the first time ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of boys and girls in the dancing room. | In the first line print *k* — the number of songs during which they can dance. Then in the following *k* lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to *n*, and the girls are indexed from 1 to *m*. | [
"2 1\n",
"2 2\n"
] | [
"2\n1 1\n2 1\n",
"3\n1 1\n1 2\n2 2\n"
] | In test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).
And in test case 2, we have 2 boys with 2 girls, the answer is 3. | 500 | [
{
"input": "2 1",
"output": "2\n1 1\n2 1"
},
{
"input": "2 2",
"output": "3\n1 1\n1 2\n2 2"
},
{
"input": "1 1",
"output": "1\n1 1"
},
{
"input": "2 3",
"output": "4\n1 1\n1 2\n1 3\n2 3"
},
{
"input": "4 4",
"output": "7\n1 1\n1 2\n1 3\n1 4\n4 4\n3 4\n2 4"
}... | 1,642,605,298 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 216 | 512,000 | m, n = map(int, input().split())
ls = []
for i in range(m):
ls1 = (str(i + 1), '1')
ls.append(ls1)
for j in range(1, n):
ls1 = ('1', str(j + 1))
ls.append(ls1)
print(len(ls))
for i in ls:
print(' '.join(i)) | Title: Ciel and Dancing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. B... | ```python
m, n = map(int, input().split())
ls = []
for i in range(m):
ls1 = (str(i + 1), '1')
ls.append(ls1)
for j in range(1, n):
ls1 = ('1', str(j + 1))
ls.append(ls1)
print(len(ls))
for i in ls:
print(' '.join(i))
``` | 3 | |
16 | A | Flag | PROGRAMMING | 800 | [
"implementation"
] | A. Flag | 2 | 64 | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be... | The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands ... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | [
"3 3\n000\n111\n222\n",
"3 3\n000\n000\n111\n",
"3 3\n000\n111\n002\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 0 | [
{
"input": "3 3\n000\n111\n222",
"output": "YES"
},
{
"input": "3 3\n000\n000\n111",
"output": "NO"
},
{
"input": "3 3\n000\n111\n002",
"output": "NO"
},
{
"input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000... | 1,496,469,154 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 122 | 0 | if __name__ == '__main__':
n, m = map(int, input().split())
flag = True
refer = list()
for _ in range(n):
candi = set(list(str(input())))
if len(candi) > 1:
flag = False
break
else:
refer.append(candi.pop())
if len(set(refer)) < ... | Title: Flag
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of... | ```python
if __name__ == '__main__':
n, m = map(int, input().split())
flag = True
refer = list()
for _ in range(n):
candi = set(list(str(input())))
if len(candi) > 1:
flag = False
break
else:
refer.append(candi.pop())
if len(set(... | 0 |
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894"... | 1,590,089,042 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 155 | 0 | import sys,math
def isleap(y):
if y%400==0:
return True
elif y%4==0 and y%100!=0:
return True
else:
return False
n,k=map(int,sys.stdin.readline().split())
r=n%k
if r==0:
r+=k
else:
r=k-r
print(n+r) | Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *... | ```python
import sys,math
def isleap(y):
if y%400==0:
return True
elif y%4==0 and y%100!=0:
return True
else:
return False
n,k=map(int,sys.stdin.readline().split())
r=n%k
if r==0:
r+=k
else:
r=k-r
print(n+r)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | This is an interactive problem.
Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet... | The first line contains two integers $m$ and $n$ ($1 \le m \le 10^9$, $1 \le n \le 30$) — the maximum distance to Mars and the number of elements in the sequence $p$. | none | [
"5 2\n1\n-1\n-1\n1\n0\n"
] | [
"1\n2\n4\n5\n3\n"
] | In the example, hacking would look like this:
5 2 3
1 0
This means that the current distance to Mars is equal to $3$, Natasha knows that it does not exceed $5$, and the rocket answers in order: correctly, incorrectly, correctly, incorrectly ...
Really:
on the first query ($1$) the correct answer is $1$, the rocket... | 0 | [
{
"input": "5 2 3\n1 0",
"output": "3 queries, x=3"
},
{
"input": "1 1 1\n1",
"output": "1 queries, x=1"
},
{
"input": "3 2 3\n1 0",
"output": "4 queries, x=3"
},
{
"input": "6 3 5\n1 1 1",
"output": "5 queries, x=5"
},
{
"input": "10 4 3\n0 0 1 0",
"output": ... | 1,599,511,052 | 2,147,483,647 | PyPy 3 | OK | TESTS | 135 | 171 | 102,400 | from __future__ import print_function
from sys import stdin, stdout
rints = lambda: [int(x) for x in stdin.readline().split()]
m, n = rints()
ans = []
for i in range(1, min(n, m) + 1):
print(i, flush=True)
ans.append(int(input()))
if ans[-1] == 0:
exit()
be, en, ix = 1, m, 0
whi... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem.
Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. Sh... | ```python
from __future__ import print_function
from sys import stdin, stdout
rints = lambda: [int(x) for x in stdin.readline().split()]
m, n = rints()
ans = []
for i in range(1, min(n, m) + 1):
print(i, flush=True)
ans.append(int(input()))
if ans[-1] == 0:
exit()
be, en, ix = 1, m... | 3 | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,665,463,997 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 374 | 9,011,200 | # direct access array
n = int(input())
A = tuple(map(int,input().split()))
m = int(input())
B = tuple(map(int,input().split()))
D_array = [None] * 100001
for i in range(0, n):
D_array[A[i]] = i + 1
V, P = 0, 0
for i in B:
V += D_array[i]
P += n + 1 - D_array[i]
print(V, P) | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
# direct access array
n = int(input())
A = tuple(map(int,input().split()))
m = int(input())
B = tuple(map(int,input().split()))
D_array = [None] * 100001
for i in range(0, n):
D_array[A[i]] = i + 1
V, P = 0, 0
for i in B:
V += D_array[i]
P += n + 1 - D_array[i]
print(V, P)
``` | 3 | |
893 | C | Rumor | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Ove... | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
... | Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example ... | 0 | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n10000000... | 1,672,230,798 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 10,956,800 |
from queue import Queue
n,m=map(int, input().split())
l=list(map(int,input().split()))
friends={}
for i in range(m):
a=list(map(int,input().split()))
friends[a[0]]=a[1]
# print(n,m)
# print(l)
# print(friends)
visited=set()
exp=Queue()
cost=0
for i in range(1,n+1):
# print(i)
if i in ... | Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte... | ```python
from queue import Queue
n,m=map(int, input().split())
l=list(map(int,input().split()))
friends={}
for i in range(m):
a=list(map(int,input().split()))
friends[a[0]]=a[1]
# print(n,m)
# print(l)
# print(friends)
visited=set()
exp=Queue()
cost=0
for i in range(1,n+1):
# print(i)
... | 0 | |
285 | B | Find Marble | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position *s*. Then he performs som... | The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaran... | If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1. | [
"4 2 1\n2 3 4 1\n",
"4 3 3\n4 1 3 2\n",
"4 3 4\n1 2 3 4\n",
"3 1 3\n2 1 3\n"
] | [
"3\n",
"0\n",
"-1\n",
"-1\n"
] | none | 1,000 | [
{
"input": "4 2 1\n2 3 4 1",
"output": "3"
},
{
"input": "4 3 3\n4 1 3 2",
"output": "0"
},
{
"input": "4 3 4\n1 2 3 4",
"output": "-1"
},
{
"input": "3 1 3\n2 1 3",
"output": "-1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 6 7\n10 7 8 1... | 1,596,633,154 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 434 | 14,028,800 | enter = input().split()
n = int(enter[0]) - 1
s = int(enter[1]) - 1
t = int(enter[2]) - 1
fix = s
arr_b = [int(i) - 1 for i in input().split()]
arr_a = [i for i in range(1,n+2)]
target = arr_a[s]
flag = 0
#print(arr_a)
#print(arr_b)
i = 0
while (arr_a[t] != target):
correct_pos = arr_b[s]
ar... | Title: Find Marble
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the ... | ```python
enter = input().split()
n = int(enter[0]) - 1
s = int(enter[1]) - 1
t = int(enter[2]) - 1
fix = s
arr_b = [int(i) - 1 for i in input().split()]
arr_a = [i for i in range(1,n+2)]
target = arr_a[s]
flag = 0
#print(arr_a)
#print(arr_b)
i = 0
while (arr_a[t] != target):
correct_pos = arr_b... | 3 | |
508 | B | Anton and currency you all know | PROGRAMMING | 1,300 | [
"greedy",
"math",
"strings"
] | null | null | Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have informed the financier Anton of some information about the exchange rate of... | The first line contains an odd positive integer *n* — the exchange rate of currency you all know for today. The length of number *n*'s representation is within range from 2 to 105, inclusive. The representation of *n* doesn't contain any leading zeroes. | If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print <=-<=1.
Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained fro... | [
"527\n",
"4573\n",
"1357997531\n"
] | [
"572\n",
"3574\n",
"-1\n"
] | none | 1,000 | [
{
"input": "527",
"output": "572"
},
{
"input": "4573",
"output": "3574"
},
{
"input": "1357997531",
"output": "-1"
},
{
"input": "444443",
"output": "444434"
},
{
"input": "22227",
"output": "72222"
},
{
"input": "24683",
"output": "34682"
},
... | 1,664,047,796 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 78 | 0 | t = int(input())
lst=[]
d = 0
while(t!=0):
d = t%10
t = t//10
lst.append(d)
lst.reverse()
for i in range(0,len(lst)):
if (lst[i]%2==0):
if (lst[i]<lst[len(lst)-1]):
t = lst[i]
lst[i] = lst[len(lst)-1]
lst[len(lst)-1] = t
if (lst[len(lst)-1]... | Title: Anton and currency you all know
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed... | ```python
t = int(input())
lst=[]
d = 0
while(t!=0):
d = t%10
t = t//10
lst.append(d)
lst.reverse()
for i in range(0,len(lst)):
if (lst[i]%2==0):
if (lst[i]<lst[len(lst)-1]):
t = lst[i]
lst[i] = lst[len(lst)-1]
lst[len(lst)-1] = t
if (lst[l... | 0 | |
711 | A | Bus to Udayland | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris a... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and t... | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ... | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | 500 | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
... | 1,602,772,709 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 140 | 819,200 | import math
import os
import random
import re
import sys
def solve(n, matrix):
aisle = '|'
buddy_seats = 'OO'
result = 'NO'
for row_index, row in enumerate(matrix):
for col_index, col in enumerate(row):
pair = col.split(aisle)
for seat_index, seat in enu... | Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pai... | ```python
import math
import os
import random
import re
import sys
def solve(n, matrix):
aisle = '|'
buddy_seats = 'OO'
result = 'NO'
for row_index, row in enumerate(matrix):
for col_index, col in enumerate(row):
pair = col.split(aisle)
for seat_index, s... | 0 | |
876 | B | Divisiblity of Differences | PROGRAMMING | 1,300 | [
"implementation",
"math",
"number theory"
] | null | null | You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number... | First line contains three integers *n*, *k* and *m* (2<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=... | If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the selected numbers. If there are multiple possible solutions, print any of them... | [
"3 2 3\n1 8 4\n",
"3 3 3\n1 8 4\n",
"4 3 5\n2 7 7 7\n"
] | [
"Yes\n1 4 ",
"No",
"Yes\n2 7 7 "
] | none | 1,000 | [
{
"input": "3 2 3\n1 8 4",
"output": "Yes\n1 4 "
},
{
"input": "3 3 3\n1 8 4",
"output": "No"
},
{
"input": "4 3 5\n2 7 7 7",
"output": "Yes\n2 7 7 "
},
{
"input": "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825",
"output":... | 1,551,905,852 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | inp = list(map(int,input().split(' ')))
n, k, m = inp[0], inp[1], inp[2]
nums = [[] for i in range(m)]
for input in list(map(int,input().split(' '))):
nums[input%m].append(input)
for j in nums:
if len(j) >= k:
print('Yes')
print(" ".join(list(map(str,j[:k]))))
| Title: Divisiblity of Differences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be re... | ```python
inp = list(map(int,input().split(' ')))
n, k, m = inp[0], inp[1], inp[2]
nums = [[] for i in range(m)]
for input in list(map(int,input().split(' '))):
nums[input%m].append(input)
for j in nums:
if len(j) >= k:
print('Yes')
print(" ".join(list(map(str,j[:k]))))
``` | 0 | |
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"ou... | 1,560,752,929 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 34 | 2,000 | 2,252,800 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, sys.stdin.readline().sp... | Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specificatio... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, sys.stdin.rea... | 0 | |
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea... | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n... | 1,688,647,650 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | h=[]
g=[]
n=int(input())
for i in range(n):
hi,gi=map(int,input().split())
h.append(hi)
g.append(gi)
d=dict.fromkeys(g,0)
for i in range(n):
for j in range(n):
if g[i]==h[j]:
d[g[i]]+=1
l=list(d.values())
print(sum(l)) | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W... | ```python
h=[]
g=[]
n=int(input())
for i in range(n):
hi,gi=map(int,input().split())
h.append(hi)
g.append(gi)
d=dict.fromkeys(g,0)
for i in range(n):
for j in range(n):
if g[i]==h[j]:
d[g[i]]+=1
l=list(d.values())
print(sum(l))
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*.
Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell... | The first line contains three integers *n*, *d* and *h* (2<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*h*<=≤<=*d*<=≤<=*n*<=-<=1) — the number of vertices, diameter, and height after rooting in vertex 1, respectively. | If there is no tree matching what Limak remembers, print the only line with "-1" (without the quotes).
Otherwise, describe any tree matching Limak's description. Print *n*<=-<=1 lines, each with two space-separated integers – indices of vertices connected by an edge. If there are many valid trees, print any of them. Y... | [
"5 3 2\n",
"8 5 2\n",
"8 4 2\n"
] | [
"1 2\n1 3\n3 4\n3 5",
"-1\n",
"4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5\n"
] | Below you can see trees printed to the output in the first sample and the third sample. | 0 | [
{
"input": "5 3 2",
"output": "1 2\n2 3\n1 4\n5 1"
},
{
"input": "8 5 2",
"output": "-1"
},
{
"input": "8 4 2",
"output": "4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5"
},
{
"input": "2 1 1",
"output": "1 2"
},
{
"input": "10 3 3",
"output": "1 2\n2 3\n3 4\n5 2\n6 2\n7 2... | 1,459,184,282 | 1,382 | Python 3 | WRONG_ANSWER | PRETESTS | 4 | 61 | 4,608,000 | n,d,h = map(int, input().split())
if d > 2*h or h > d:
print(-1)
else:
for i in range(h):
print(str(i+1)+" "+str(i+2))
if d > h:
print("1 "+str(h+2))
for i in range(d-h-1):
print(str(h+2+i)+" "+str(h+3+i))
for i in range(d+2,n+1):
print("1 "+str(i)) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*.
Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh sto... | ```python
n,d,h = map(int, input().split())
if d > 2*h or h > d:
print(-1)
else:
for i in range(h):
print(str(i+1)+" "+str(i+2))
if d > h:
print("1 "+str(h+2))
for i in range(d-h-1):
print(str(h+2+i)+" "+str(h+3+i))
for i in range(d+2,n+1):
print("1 "+str(i))
``` | 0 | |
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,510,992,282 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 37 | 156 | 11,366,400 | number = int(input())
numerator = 0
denominator = 0
lst = list(map(int,input().split()))
lst2 = list(map(int,input().split()))
if len(lst) == 2 and len(lst2) == 2:
num = 0
den = 0
for item in lst:
num = num + item
for item in lst2:
den = den + item
if num/den<=1:
print("YES")
else:
print("N... | 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
number = int(input())
numerator = 0
denominator = 0
lst = list(map(int,input().split()))
lst2 = list(map(int,input().split()))
if len(lst) == 2 and len(lst2) == 2:
num = 0
den = 0
for item in lst:
num = num + item
for item in lst2:
den = den + item
if num/den<=1:
print("YES")
else:
... | -1 | |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,639,768,640 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 61 | 0 | no_of_employees=int(input())
i=1
ways=0
while(i<=no_of_employees/2):
if(no_of_employees%i==0):
ways+=1
i+=1
print(ways) | Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
no_of_employees=int(input())
i=1
ways=0
while(i<=no_of_employees/2):
if(no_of_employees%i==0):
ways+=1
i+=1
print(ways)
``` | 3 | |
359 | C | Prime Number | PROGRAMMING | 1,900 | [
"math",
"number theory"
] | null | null | Simon has a prime number *x* and an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: , where number *t* equals *x**a*1<=+<=*a*2<=+<=...... | The first line contains two positive integers *n* and *x* (1<=≤<=*n*<=≤<=105, 2<=≤<=*x*<=≤<=109) — the size of the array and the prime number.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*<=≤<=109). | Print a single number — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"2 2\n2 2\n",
"3 3\n1 2 3\n",
"2 2\n29 29\n",
"4 5\n0 0 0 0\n"
] | [
"8\n",
"27\n",
"73741817\n",
"1\n"
] | In the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7745f7cc87c6c5f753e3414fad9baa3b1e3fea48.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, the answer to the problem is 8.
In the second sample, <img align="middle" class="tex-formula" src="https://espresso.codef... | 1,500 | [
{
"input": "2 2\n2 2",
"output": "8"
},
{
"input": "3 3\n1 2 3",
"output": "27"
},
{
"input": "2 2\n29 29",
"output": "73741817"
},
{
"input": "4 5\n0 0 0 0",
"output": "1"
},
{
"input": "1 2\n1000000000",
"output": "1"
},
{
"input": "26 2\n0 0 0 0 0 0... | 1,656,084,041 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 108 | 4,096,000 | print("12345678 " * (10**5))
| Title: Prime Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon has a prime number *x* and an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common den... | ```python
print("12345678 " * (10**5))
``` | 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,609,772,487 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 186 | 0 | s = input()
uppercase = 0
lowercase = 0
if s.islower() == True or s.isupper() == True:
print(s)
else:
for i in range(len(s)):
if s[i].isupper() == True:
uppercase += 1
else:
lowercase += 1
if lowercase >= uppercase:
print(s.lower())
else:
print(s.upper()) | 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()
uppercase = 0
lowercase = 0
if s.islower() == True or s.isupper() == True:
print(s)
else:
for i in range(len(s)):
if s[i].isupper() == True:
uppercase += 1
else:
lowercase += 1
if lowercase >= uppercase:
print(s.lower())
else:
print(s.upper(... | 0 |
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,862,036 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 217 | 8,499,200 | def isOdd (x):
return x%2==1
def isEven (x):
return x%2==0
input()
arr = [int(z) for z in input().split()]
oddA = list(filter(isOdd,arr))
oddA.sort()
evenSum = sum(filter(isEven,arr))
if(isOdd(len(oddA))):
print(evenSum+sum(oddA[1:]))
else:
print(evenSum+sum(oddA))
| 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
def isOdd (x):
return x%2==1
def isEven (x):
return x%2==0
input()
arr = [int(z) for z in input().split()]
oddA = list(filter(isOdd,arr))
oddA.sort()
evenSum = sum(filter(isEven,arr))
if(isOdd(len(oddA))):
print(evenSum+sum(oddA[1:]))
else:
print(evenSum+sum(oddA))
``` | 3 | |
472 | B | Design Tutorial: Learn from Life | PROGRAMMING | 1,300 | [] | null | null | One way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task.
Let's think about a scene in real life: there are lots of people waiting in front of the elevator, each person wants to go to a certain floor. We can formalize it in the following... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=2000) — the number of people and the maximal capacity of the elevator.
The next line contains *n* integers: *f*1,<=*f*2,<=...,<=*f**n* (2<=≤<=*f**i*<=≤<=2000), where *f**i* denotes the target floor of the *i*-th person. | Output a single integer — the minimal time needed to achieve the goal. | [
"3 2\n2 3 4\n",
"4 2\n50 100 50 100\n",
"10 3\n2 2 2 2 2 2 2 2 2 2\n"
] | [
"8\n",
"296\n",
"8\n"
] | In first sample, an optimal solution is:
1. The elevator takes up person #1 and person #2. 1. It goes to the 2nd floor. 1. Both people go out of the elevator. 1. The elevator goes back to the 1st floor. 1. Then the elevator takes up person #3. 1. And it goes to the 2nd floor. 1. It picks up person #2. 1. Then... | 1,000 | [
{
"input": "3 2\n2 3 4",
"output": "8"
},
{
"input": "4 2\n50 100 50 100",
"output": "296"
},
{
"input": "10 3\n2 2 2 2 2 2 2 2 2 2",
"output": "8"
},
{
"input": "1 1\n2",
"output": "2"
},
{
"input": "2 1\n2 2",
"output": "4"
},
{
"input": "2 2\n2 2",
... | 1,679,909,382 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 46 | 0 | people, capacity = map(int, input().split())
lst = sorted(list(map(int, input().split())))
tempTime = 0
while(len(lst) > 0):
tempArr = []
for i in range(capacity):
if(len(lst) > 0):
tempArr.append(lst.pop())
tempArr = sorted(tempArr)
if(len(tempArr) < 0):
break
... | Title: Design Tutorial: Learn from Life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task.
Let's think about a scene in real life: there are lots of peo... | ```python
people, capacity = map(int, input().split())
lst = sorted(list(map(int, input().split())))
tempTime = 0
while(len(lst) > 0):
tempArr = []
for i in range(capacity):
if(len(lst) > 0):
tempArr.append(lst.pop())
tempArr = sorted(tempArr)
if(len(tempArr) < 0):
... | 3 | |
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,662,295,469 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | world = input()
a =ord("a") ; z = ord("z")
now = a ;
counter = 0
for i in range(0 , len(world)):
main = ord(world[i].lower())
if (main != now) :
ahead = abs(main - now) ;
back = (now - a ) + (z - main) + 1 if main > now else (z - now) + (main - a)+1
print(ahead , back , mai... | 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
world = input()
a =ord("a") ; z = ord("z")
now = a ;
counter = 0
for i in range(0 , len(world)):
main = ord(world[i].lower())
if (main != now) :
ahead = abs(main - now) ;
back = (now - a ) + (z - main) + 1 if main > now else (z - now) + (main - a)+1
print(ahead , ... | 0 | |
748 | B | Santa Claus and Keyboard Check | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
... | The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters. | If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k... | [
"helloworld\nehoolwlroz\n",
"hastalavistababy\nhastalavistababy\n",
"merrychristmas\nchristmasmerry\n"
] | [
"3\nh e\nl o\nd z\n",
"0\n",
"-1\n"
] | none | 1,000 | [
{
"input": "helloworld\nehoolwlroz",
"output": "3\nh e\nl o\nd z"
},
{
"input": "hastalavistababy\nhastalavistababy",
"output": "0"
},
{
"input": "merrychristmas\nchristmasmerry",
"output": "-1"
},
{
"input": "kusyvdgccw\nkusyvdgccw",
"output": "0"
},
{
"input": "... | 1,567,793,582 | 2,147,483,647 | Python 3 | OK | TESTS | 86 | 124 | 0 | s = input()
t = input()
w1, w2 = set(), set()
for i in range(len(s)):
l1, l2 = min(s[i], t[i]), max(s[i], t[i])
if (s[i] in w2 or t[i] in w2) and (l1, l2) not in w1:
print(-1)
exit()
else:
w2.add(s[i])
w2.add(t[i])
w1.add((l1, l2))
result = [elem for elem ... | Title: Santa Claus and Keyboard Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each ke... | ```python
s = input()
t = input()
w1, w2 = set(), set()
for i in range(len(s)):
l1, l2 = min(s[i], t[i]), max(s[i], t[i])
if (s[i] in w2 or t[i] in w2) and (l1, l2) not in w1:
print(-1)
exit()
else:
w2.add(s[i])
w2.add(t[i])
w1.add((l1, l2))
result = [elem... | 3 | |
888 | B | Buggy Robot | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — mo... | The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100).
The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R. | Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. | [
"4\nLDUR\n",
"5\nRRRUU\n",
"6\nLLRRRR\n"
] | [
"4\n",
"0\n",
"4\n"
] | none | 0 | [
{
"input": "4\nLDUR",
"output": "4"
},
{
"input": "5\nRRRUU",
"output": "0"
},
{
"input": "6\nLLRRRR",
"output": "4"
},
{
"input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR",
"output": "76"
},
{
"input": "89\nLDL... | 1,564,857,637 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 124 | 0 | input()
k=input()
print((min(k.count("R"),k.count("L"))+min(k.count("D"),k.count("U")))*2)
| Title: Buggy Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the ce... | ```python
input()
k=input()
print((min(k.count("R"),k.count("L"))+min(k.count("D"),k.count("U")))*2)
``` | 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,551,321,368 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 | a=str(input())
s="hello"
j=0
c=0
for i in range(0,len(a)):
if a[i]==s[j]:
i+=1
j+=1
c+=1
if c==5:
break
if c==5:
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=str(input())
s="hello"
j=0
c=0
for i in range(0,len(a)):
if a[i]==s[j]:
i+=1
j+=1
c+=1
if c==5:
break
if c==5:
print("YES")
else:
print("NO")
``` | 3.9455 |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,632,832,107 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 124 | 6,963,200 | t = int(input())
n = input().split(" ")
num = [int(i) for i in n]
even = 0;lastev = 0;lastodd = 0
for i in range(1,t+1):
if (num[i-1]%2==0):
even+=1
lastev = i
else:
even-=1
lastodd = i
if even > 0: print(lastodd)
else:print(lastev) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
t = int(input())
n = input().split(" ")
num = [int(i) for i in n]
even = 0;lastev = 0;lastodd = 0
for i in range(1,t+1):
if (num[i-1]%2==0):
even+=1
lastev = i
else:
even-=1
lastodd = i
if even > 0: print(lastodd)
else:print(lastev)
``` | 3.95603 |
105 | C | Item World | PROGRAMMING | 2,200 | [
"brute force",
"implementation",
"sortings"
] | C. Item World | 2 | 256 | Each item in the game has a level. The higher the level is, the higher basic parameters the item has. We shall consider only the following basic parameters: attack (atk), defense (def) and resistance to different types of impact (res).
Each item belongs to one class. In this problem we will only consider three of such... | The first line contains number *n* (3<=≤<=*n*<=≤<=100) — representing how many items Laharl has.
Then follow *n* lines. Each line contains description of an item. The description has the following form: "*name* *class* *atk* *def* *res* *size*" — the item's name, class, basic attack, defense and resistance parameters ... | Print on the first line the name of the weapon in the optimal equipping pattern; then print the number of residents the weapon contains; then print the residents' names.
Print on the second and third lines in the same form the names of the armor and defensive orb as well as the residents they contain.
Use single spa... | [
"4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongbow weapon 9 1 2 1\n5\nmike gladiator 5 longbow\nbobby sentry 6 pagstarmor\npetr gladiator 7 iceorb\nteddy physician 6 sword\nblackjack sentry 8 sword\n",
"4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongb... | [
"sword 2 petr mike \npagstarmor 1 blackjack \niceorb 2 teddy bobby \n",
"longbow 1 mike \npagstarmor 1 bobby \niceorb 2 petr joe \n"
] | In the second sample we have no free space inside the items, therefore we cannot move the residents between them. | 1,500 | [
{
"input": "4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongbow weapon 9 1 2 1\n5\nmike gladiator 5 longbow\nbobby sentry 6 pagstarmor\npetr gladiator 7 iceorb\nteddy physician 6 sword\nblackjack sentry 8 sword",
"output": "sword 2 petr mike \npagstarmor 1 blackjack \niceorb 2 ... | 1,406,311,866 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 122 | 0 | def searchBest(iType, number, rType, countResidents):
global items, equipped
best = 0
ret = None
for item, params in items.items():
if params[0] == iType:
val = int(params[number])
if countResidents:
for resid in equipped[item]:
if resi... | Title: Item World
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Each item in the game has a level. The higher the level is, the higher basic parameters the item has. We shall consider only the following basic parameters: attack (atk), defense (def) and resistance to different types of impact... | ```python
def searchBest(iType, number, rType, countResidents):
global items, equipped
best = 0
ret = None
for item, params in items.items():
if params[0] == iType:
val = int(params[number])
if countResidents:
for resid in equipped[item]:
... | -1 |
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,... | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"i... | 1,612,367,690 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 62 | 0 | n, m, z = [int(i) for i in input().split()]
copy_n = n
copy_m = m
x = 1
cnt = 0
while x <= z:
if n == x:
n += copy_n
if m == x:
m += copy_m
cnt += 1
x += 1
continue
if x == m:
m += copy_m
x += 1
print(cnt) | Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists com... | ```python
n, m, z = [int(i) for i in input().split()]
copy_n = n
copy_m = m
x = 1
cnt = 0
while x <= z:
if n == x:
n += copy_n
if m == x:
m += copy_m
cnt += 1
x += 1
continue
if x == m:
m += copy_m
x += 1
print(cnt)
``` | 3 | |
616 | B | Dinner with Emma | PROGRAMMING | 1,000 | [
"games",
"greedy"
] | null | null | Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The stree... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan.
Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue. | Print the only integer *a* — the cost of the dinner for Jack and Emma. | [
"3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n",
"3 3\n1 2 3\n2 3 1\n3 1 2\n"
] | [
"2\n",
"1\n"
] | In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the din... | 0 | [
{
"input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1",
"output": "2"
},
{
"input": "3 3\n1 2 3\n2 3 1\n3 1 2",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 10\n74 35 82 39 1 84 29 41 70 12",
"output": "1"
},
{
"input": "10 1\n44\n23\n65\n17\n48\n29\n... | 1,605,638,007 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 108 | 512,000 | n, m = map(int, input().split())
ul = []
pr = []
for i in range(n):
pr = [int(i) for i in input().split()]
ul.append(pr)
pr = []
mini = []
maxi = []
for i in range(n):
min1 = ul[i][0]
for j in range(m):
if min1 > ul[i][j]:
min1 = ul[i][j]
mini.append(min1)
for ... | Title: Dinner with Emma
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and... | ```python
n, m = map(int, input().split())
ul = []
pr = []
for i in range(n):
pr = [int(i) for i in input().split()]
ul.append(pr)
pr = []
mini = []
maxi = []
for i in range(n):
min1 = ul[i][0]
for j in range(m):
if min1 > ul[i][j]:
min1 = ul[i][j]
mini.append(m... | 3 | |
1,009 | E | Intercity Travelling | PROGRAMMING | 2,000 | [
"combinatorics",
"math",
"probabilities"
] | null | null | Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.
The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance betwe... | The first line contains one number $n$ ($1 \le n \le 10^6$) — the distance from Moscow to Saratov.
The second line contains $n$ integer numbers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_1 \le a_2 \le \dots \le a_n \le 10^6$), where $a_i$ is the difficulty of $i$-th kilometer after Leha has rested. | Print one number — $p \cdot 2^{n - 1}$, taken modulo $998244353$. | [
"2\n1 2\n",
"4\n1 3 3 7\n"
] | [
"5\n",
"60\n"
] | none | 0 | [
{
"input": "2\n1 2",
"output": "5"
},
{
"input": "4\n1 3 3 7",
"output": "60"
},
{
"input": "100\n3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70... | 1,533,653,826 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,500 | 0 | a = int(input())
b = list(map(int,input().split()))
def totDist(k):
if k == 1:
#print('for k: 1 i: 0 remaining dist: 0')
return b[0]
else:
c = 0
for i in range(1,k):
d = totDist(k-i)
e = sum(b[:i])
c += e*(2**(k-i-1))+d
... | Title: Intercity Travelling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.
The path from Moscow to Saratov can be represented as a straight line (well, it's not... | ```python
a = int(input())
b = list(map(int,input().split()))
def totDist(k):
if k == 1:
#print('for k: 1 i: 0 remaining dist: 0')
return b[0]
else:
c = 0
for i in range(1,k):
d = totDist(k-i)
e = sum(b[:i])
c += e*(2**(k-i-1))+d
... | 0 | |
235 | A | LCM Challenge | PROGRAMMING | 1,600 | [
"number theory"
] | null | null | Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement. | Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*. | [
"9\n",
"7\n"
] | [
"504\n",
"210\n"
] | The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is ... | 500 | [
{
"input": "9",
"output": "504"
},
{
"input": "7",
"output": "210"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "60"
},
{
"input": "33",
"output": "32736"
},
{
"input": "21",
"output": ... | 1,555,527,880 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 218 | 0 | import math
def main():
n = int(input())
if n <= 3:
ans = 1
for i in range(1,n+1):
ans *= i
print(ans)
return
if n%2 == 0:
#print(n,n-1,n-3)
if n%3 == 0:
print((n-3)*(n-1)*(n-2))
else:
print(n*(n-1)*(... | Title: LCM Challenge
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive... | ```python
import math
def main():
n = int(input())
if n <= 3:
ans = 1
for i in range(1,n+1):
ans *= i
print(ans)
return
if n%2 == 0:
#print(n,n-1,n-3)
if n%3 == 0:
print((n-3)*(n-1)*(n-2))
else:
print... | 3 | |
490 | B | Queue | PROGRAMMING | 1,500 | [
"dsu",
"implementation"
] | null | null | During the lunch break all *n* Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID ... | The first line contains integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of students in the queue.
Then *n* lines follow, *i*-th line contains the pair of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=106), where *a**i* is the ID number of a person in front of a student and *b**i* is the ID number of a person beh... | Print a sequence of *n* integers *x*1,<=*x*2,<=...,<=*x**n* — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one. | [
"4\n92 31\n0 7\n31 0\n7 141\n"
] | [
"92 7 31 141 \n"
] | The picture illustrates the queue for the first sample. | 1,000 | [
{
"input": "4\n92 31\n0 7\n31 0\n7 141",
"output": "92 7 31 141 "
},
{
"input": "2\n0 1\n2 0",
"output": "2 1 "
},
{
"input": "3\n0 2\n1 3\n2 0",
"output": "1 2 3 "
},
{
"input": "4\n101 0\n0 102\n102 100\n103 101",
"output": "103 102 101 100 "
},
{
"input": "5\n0... | 1,667,463,605 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | def get_int():
return int(input())
def main():
n = get_int()
array = [0]*n
right_hashmap = {}
left_hashmap = {}
nums = set()
for _ in range(n):
left, right = list(map(int, input().split()))
if left == 0:
array[1] = right
continue
... | Title: Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the lunch break all *n* Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't b... | ```python
def get_int():
return int(input())
def main():
n = get_int()
array = [0]*n
right_hashmap = {}
left_hashmap = {}
nums = set()
for _ in range(n):
left, right = list(map(int, input().split()))
if left == 0:
array[1] = right
continu... | 0 | |
910 | C | Minimum Sum | PROGRAMMING | 1,700 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | Petya has *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*.
His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of Petya's numbers.
Each of the following lines contains non-empty string *s**i* consisting of lowercase Latin letters from 'a' to 'j' — the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. | Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. | [
"3\nab\nde\naj\n",
"5\nabcdef\nghij\nbdef\naccbd\ng\n",
"3\naa\njj\naa\n"
] | [
"47\n",
"136542\n",
"44\n"
] | In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the mi... | 1,500 | [
{
"input": "3\nab\nde\naj",
"output": "47"
},
{
"input": "5\nabcdef\nghij\nbdef\naccbd\ng",
"output": "136542"
},
{
"input": "3\naa\njj\naa",
"output": "44"
},
{
"input": "9\na\nb\nc\nd\nf\ng\nh\ni\nj",
"output": "45"
},
{
"input": "5\nbdgbh\nadi\naa\ngjh\ngh",
... | 1,514,829,312 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 5,632,000 | import sys
cases=int(input())
s=['' for i in range(6)]
heads=[]
zero=True
nums=[i for i in range(1,10)]
letters=[ 0 for i in range(10)]
words=[]
f=''
for i in range(cases):
a=(input())
f=f+a
words.append(str(a))
heads.append(a[0])
for j in range(len(a... | Title: Minimum Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*.
His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' a... | ```python
import sys
cases=int(input())
s=['' for i in range(6)]
heads=[]
zero=True
nums=[i for i in range(1,10)]
letters=[ 0 for i in range(10)]
words=[]
f=''
for i in range(cases):
a=(input())
f=f+a
words.append(str(a))
heads.append(a[0])
for j in r... | 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,597,740,634 | 2,147,483,647 | PyPy 3 | OK | TESTS | 24 | 278 | 0 | M=[]
for i in range(3):
L=list(map(int,input().split()))
M.append(L)
x2=M[0][2]
x3=M[1][0]
x5=M[2][0]
x6=M[2][1]
M[0][0]=(x2+x5+x6-x3)//2
M[1][1]=(x2+x5)//2
M[2][2]=(x2+x5+x3-x6)//2
for i in range(3):
for j in range(3):
print(M[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
M=[]
for i in range(3):
L=list(map(int,input().split()))
M.append(L)
x2=M[0][2]
x3=M[1][0]
x5=M[2][0]
x6=M[2][1]
M[0][0]=(x2+x5+x6-x3)//2
M[1][1]=(x2+x5)//2
M[2][2]=(x2+x5+x3-x6)//2
for i in range(3):
for j in range(3):
print(M[i][j],end=" ")
print("")
``` | 3 | |
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul... | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter t... | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input":... | 1,623,059,768 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 0 | from operator import itemgetter
import sys
def get_single_int ():
return int (sys.stdin.readline ().strip ())
def get_string ():
return sys.stdin.readline ().strip ()
def get_ints ():
return map (int, sys.stdin.readline ().strip ().split ())
def get_list ():
return list (map (int, sys.stdin.readline ().... | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ... | ```python
from operator import itemgetter
import sys
def get_single_int ():
return int (sys.stdin.readline ().strip ())
def get_string ():
return sys.stdin.readline ().strip ()
def get_ints ():
return map (int, sys.stdin.readline ().strip ().split ())
def get_list ():
return list (map (int, sys.stdin.re... | 0 |
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,600,056,403 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 218 | 0 | def reverse(s):
str1 = ""
for i in s:
str1 = i + str1
return str1
s1=str(input())
s2=str(input())
rev=""
rev=reverse(s1)
if s2==rev:
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
def reverse(s):
str1 = ""
for i in s:
str1 = i + str1
return str1
s1=str(input())
s2=str(input())
rev=""
rev=reverse(s1)
if s2==rev:
print("YES")
else:
print("NO")
``` | 3.9455 |
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s... | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indi... | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGB... | 1,692,374,863 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | import math
n = int(input())
print(('ROYGBIV'*math.ceil(n/2))[:n]) | Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
-... | ```python
import math
n = int(input())
print(('ROYGBIV'*math.ceil(n/2))[:n])
``` | 0 |
899 | C | Dividing the numbers | PROGRAMMING | 1,300 | [
"constructive algorithms",
"graphs",
"math"
] | null | null | Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of *n* integers should be exactly in one group. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has. | Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them. | [
"4\n",
"2\n"
] | [
"0\n2 1 4 \n",
"1\n1 1 \n"
] | In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and on... | 1,500 | [
{
"input": "4",
"output": "0\n2 1 4 "
},
{
"input": "2",
"output": "1\n1 1 "
},
{
"input": "3",
"output": "0\n1\n3 "
},
{
"input": "5",
"output": "1\n3\n1 2 5 "
},
{
"input": "59998",
"output": "1\n29999 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 4... | 1,663,714,344 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 60 | 92 | 5,017,600 | def generate_list_124(s, n):
lst = []
for i in range(s, int(n/2) + 1, 2):
lst.append(i)
lst.append(n-i+s)
return lst
def generate_list_3(s, n):
lst = []
for i in range(s, int(n/2) - 1, 2):
lst.append(i)
lst.append(n-i+s)
lst.append(int(n/2))
retu... | Title: Dividing the numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help P... | ```python
def generate_list_124(s, n):
lst = []
for i in range(s, int(n/2) + 1, 2):
lst.append(i)
lst.append(n-i+s)
return lst
def generate_list_3(s, n):
lst = []
for i in range(s, int(n/2) - 1, 2):
lst.append(i)
lst.append(n-i+s)
lst.append(int(n/2))... | 3 | |
259 | A | Little Elephant and Chess | PROGRAMMING | 1,000 | [
"brute force",
"strings"
] | null | null | The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard d... | The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the *j*-th character in the *i*-th line stands for the color of the *j*-th cell of the *i*-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black co... | In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise. | [
"WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n",
"WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | 500 | [
{
"input": "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB",
"output": "YES"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBW... | 1,578,061,408 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 310 | 0 | ans = True
for i in range(8):
s = input()
for i in range(7):
if s[i] == s[i+1]:
ans = False
if ans:
print("YES")
else:
print("NO")
| Title: Little Elephant and Chess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, e... | ```python
ans = True
for i in range(8):
s = input()
for i in range(7):
if s[i] == s[i+1]:
ans = False
if ans:
print("YES")
else:
print("NO")
``` | 3 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,526,377,887 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 156 | 7,065,600 | import sys
n = int(input())
numbers = list(map(int, input().split()))
length = len(numbers)
even = []
for number in numbers:
if(number % 2 == 0):
even.append(True)
else:
even.append(False)
mask = sum(even)
if(mask == length - 1):
answer = even.index(0)
else:
answer = even.index(1)
print(answer + 1)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
import sys
n = int(input())
numbers = list(map(int, input().split()))
length = len(numbers)
even = []
for number in numbers:
if(number % 2 == 0):
even.append(True)
else:
even.append(False)
mask = sum(even)
if(mask == length - 1):
answer = even.index(0)
else:
answer = even.index(1)
print(answer... | 3.947839 |
967 | A | Mind the Gap | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute.
He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minut... | The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.
Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, i... | Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | [
"6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n",
"16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n",
"3 17\n0 30\n1 0\n12 0\n"
] | [
"6 1\n",
"24 50\n",
"0 0\n"
] | In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.
In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert th... | 500 | [
{
"input": "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40",
"output": "6 1"
},
{
"input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59",
"output": "24 50"
},
{
"input": "3 17\n0 30\n1 0\n12 0",
"output": "0 0"
},
{
... | 1,617,343,654 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 61 | 0 | I=lambda:map(int,input().split())
n,s=I()
l=[0]
for i in range(n):
q,w=I()
q=q*60+w
l+=[q]
if l[1]-l[0]>s+1:exit(print(0, 0))
for i in range(n):
if l[i+1]-l[i]>2*s+1:
l[i]+=s+1
exit(print(l[i]//60,l[i]%60))
l[-1]+=s+1
print(l[-1]//60,l[-1]%60) | Title: Mind the Gap
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing ... | ```python
I=lambda:map(int,input().split())
n,s=I()
l=[0]
for i in range(n):
q,w=I()
q=q*60+w
l+=[q]
if l[1]-l[0]>s+1:exit(print(0, 0))
for i in range(n):
if l[i+1]-l[i]>2*s+1:
l[i]+=s+1
exit(print(l[i]//60,l[i]%60))
l[-1]+=s+1
print(l[-1]//60,l[-1]%60)
``` | 0 | |
618 | D | Hamiltonian Spanning Tree | PROGRAMMING | 2,200 | [
"dfs and similar",
"dp",
"graph matchings",
"greedy",
"trees"
] | null | null | A group of *n* cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are roads in total. It takes exactly *y* seconds to traverse any single road.
A spanning tree is a set of roads containing exactly *n*<=-<=1 roads such that it's possible to travel between any ... | The first line of the input contains three integers *n*, *x* and *y* (2<=≤<=*n*<=≤<=200<=000,<=1<=≤<=*x*,<=*y*<=≤<=109).
Each of the next *n*<=-<=1 lines contains a description of a road in the spanning tree. The *i*-th of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*) — indices of... | Print a single integer — the minimum number of seconds one needs to spend in order to visit all the cities exactly once. | [
"5 2 3\n1 2\n1 3\n3 4\n5 3\n",
"5 3 2\n1 2\n1 3\n3 4\n5 3\n"
] | [
"9\n",
"8\n"
] | In the first sample, roads of the spanning tree have cost 2, while other roads have cost 3. One example of an optimal path is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3a11f64ac0349d4ecd3a2b4c3443aeb7ac3b28b9.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample,... | 1,750 | [
{
"input": "5 2 3\n1 2\n1 3\n3 4\n5 3",
"output": "9"
},
{
"input": "5 3 2\n1 2\n1 3\n3 4\n5 3",
"output": "8"
},
{
"input": "50 23129 410924\n18 28\n17 23\n21 15\n18 50\n50 11\n32 3\n44 41\n50 31\n50 34\n5 14\n36 13\n22 40\n20 9\n9 43\n19 47\n48 40\n20 22\n33 45\n35 22\n33 24\n9 6\n13 1... | 1,454,093,362 | 5,962 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 1,123 | 20,992,000 | n, x, y = [int(x) for x in input().split()]
if x >= y:
print(y * (n - 1))
exit()
count = n - 1
been = [0] * n
edge = []
for i in range(n - 1):
k, l = [int(x) for x in input().split()]
edge.append([k - 1, l - 1, 1])
been[k - 1] += 1
been[l - 1] += 1
for i in range(n - 1):
if been... | Title: Hamiltonian Spanning Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A group of *n* cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are roads in total. It takes exactly *y* seconds to traverse any single road.
A sp... | ```python
n, x, y = [int(x) for x in input().split()]
if x >= y:
print(y * (n - 1))
exit()
count = n - 1
been = [0] * n
edge = []
for i in range(n - 1):
k, l = [int(x) for x in input().split()]
edge.append([k - 1, l - 1, 1])
been[k - 1] += 1
been[l - 1] += 1
for i in range(n - 1):
... | 0 | |
478 | C | Table Decorations | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *t* of tables can be decorated if we know number of balloons of each color?
Your task is to write a pro... | The single line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space. | Print a single integer *t* — the maximum number of tables that can be decorated in the required manner. | [
"5 4 3\n",
"1 1 1\n",
"2 3 3\n"
] | [
"4\n",
"1\n",
"2\n"
] | In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively. | 1,500 | [
{
"input": "5 4 3",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "0 1 0",
"output": "0"
},
{
"input": "0 3 3",
"output": "2"
},
{
"input": "4 0 4",
"output": "2"
},
{
"input": "100000... | 1,683,305,199 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 10 | 61 | 0 | R , G , B = map(int ,input().split())
if R+G==0 or R+B==0 or B+G==0:
print(0)
exit(0)
m = min(R,G,B)
R-=m
G-=m
B-=m
m1 = min(max(R,G) , max(G,B),max(R,B))
print(m + min(m1 , (R+G+B)//3))
| Title: Table Decorations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *... | ```python
R , G , B = map(int ,input().split())
if R+G==0 or R+B==0 or B+G==0:
print(0)
exit(0)
m = min(R,G,B)
R-=m
G-=m
B-=m
m1 = min(max(R,G) , max(G,B),max(R,B))
print(m + min(m1 , (R+G+B)//3))
``` | 0 | |
744 | A | Hongcow Builds A Nation | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world.
There is at ... | The first line of input will contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=1<=000, 0<=≤<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*n*) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.
The next line of input will contain *k* integers *c*1,<=*c*2,<=...,<=*c**... | Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable. | [
"4 1 2\n1 3\n1 2\n",
"3 3 1\n2\n1 2\n1 3\n2 3\n"
] | [
"2\n",
"0\n"
] | For the first sample test, the graph looks like this:
For the second sample test, the graph looks like this: | 500 | [
{
"input": "4 1 2\n1 3\n1 2",
"output": "2"
},
{
"input": "3 3 1\n2\n1 2\n1 3\n2 3",
"output": "0"
},
{
"input": "10 3 2\n1 10\n1 2\n1 3\n4 5",
"output": "33"
},
{
"input": "1 0 1\n1",
"output": "0"
},
{
"input": "1000 0 1\n72",
"output": "499500"
},
{
... | 1,643,315,471 | 791 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | import sys
input = sys.stdin.buffer.readline
def findroot(roots, x):
L = []
while roots[x] != x:
L.append(x)
x = roots[x]
for y in L:
roots[y] = x
return x
def process(n, G, C):
g = [[] for i in range(n+1)]
m = len(G)
roots = [i for i in range(n+1)]
... | Title: Hongcow Builds A Nation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* e... | ```python
import sys
input = sys.stdin.buffer.readline
def findroot(roots, x):
L = []
while roots[x] != x:
L.append(x)
x = roots[x]
for y in L:
roots[y] = x
return x
def process(n, G, C):
g = [[] for i in range(n+1)]
m = len(G)
roots = [i for i in ra... | 0 | |
358 | A | Dima and Continuous Line | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect th... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate. | In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes). | [
"4\n0 10 5 15\n",
"4\n0 15 5 10\n"
] | [
"yes\n",
"no\n"
] | The first test from the statement is on the picture to the left, the second test is on the picture to the right. | 500 | [
{
"input": "4\n0 10 5 15",
"output": "yes"
},
{
"input": "4\n0 15 5 10",
"output": "no"
},
{
"input": "5\n0 1000 2000 3000 1500",
"output": "yes"
},
{
"input": "5\n-724093 710736 -383722 -359011 439613",
"output": "no"
},
{
"input": "50\n384672 661179 -775591 -989... | 1,415,686,458 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def checkint(a,b,c,d):
check=0
if (a<c<b<d) or (c<a<d<b):
check=1
return check
n=int(input())
lis=input().split()
for i in range(n):
lis[i]=int(lis[i])
intersect=0
for i in range(n-1):
for j in range(n-1):
if checkint(lis[i],lis[i+1],lis[j],lis[j+1])==1:
in... | Title: Dima and Continuous Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher g... | ```python
def checkint(a,b,c,d):
check=0
if (a<c<b<d) or (c<a<d<b):
check=1
return check
n=int(input())
lis=input().split()
for i in range(n):
lis[i]=int(lis[i])
intersect=0
for i in range(n-1):
for j in range(n-1):
if checkint(lis[i],lis[i+1],lis[j],lis[j+1])==1:
... | 0 | |
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first... | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999... | 1,663,819,406 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 48 | 248 | 8,908,800 | y,k,n=map(int,input().split())
x=k*(1+y//k)-y
flag=0
while x+y<=n:
flag=1
print(x,end=" ")
x+=k
if flag==0:
print(-1) | Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* pota... | ```python
y,k,n=map(int,input().split())
x=k*(1+y//k)-y
flag=0
while x+y<=n:
flag=1
print(x,end=" ")
x+=k
if flag==0:
print(-1)
``` | 3 | |
771 | A | Bear and Friendship Condition | PROGRAMMING | 1,500 | [
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).
There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves.
Let A-B denote that... | The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends.
The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and ... | If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes). | [
"4 3\n1 3\n3 4\n1 4\n",
"4 4\n3 1\n2 3\n3 4\n1 2\n",
"10 4\n4 3\n5 10\n8 9\n1 2\n",
"3 2\n1 2\n2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] | The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not. | 250 | [
{
"input": "4 3\n1 3\n3 4\n1 4",
"output": "YES"
},
{
"input": "4 4\n3 1\n2 3\n3 4\n1 2",
"output": "NO"
},
{
"input": "10 4\n4 3\n5 10\n8 9\n1 2",
"output": "YES"
},
{
"input": "3 2\n1 2\n2 3",
"output": "NO"
},
{
"input": "3 0",
"output": "YES"
},
{
... | 1,587,536,058 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
#define li(n) for(int i=0; i<n; i++)
class DSU {
public:
int size;
int components;
vector<int> component_size;
vector<int> id;
DSU(int size) {
this->size = size;
this... | Title: Bear and Friendship Condition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).
There are *n* members, numbered 1 through... | ```python
#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
#define li(n) for(int i=0; i<n; i++)
class DSU {
public:
int size;
int components;
vector<int> component_size;
vector<int> id;
DSU(int size) {
this->size = size;
... | -1 | |
142 | A | Help Farmer | PROGRAMMING | 1,600 | [
"brute force",
"math"
] | null | null | Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simple... | The only line contains integer *n* from the problem's statement (1<=≤<=*n*<=≤<=109). | Print space-separated minimum and maximum number of hay blocks that could have been stolen by the thieves.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred... | [
"4\n",
"7\n",
"12\n"
] | [
"28 41\n",
"47 65\n",
"48 105\n"
] | Let's consider the first sample test. If initially Sam has a parallelepiped consisting of 32 = 2 × 4 × 4 hay blocks in his barn, then after the theft the barn has 4 = (2 - 1) × (4 - 2) × (4 - 2) hay blocks left. Thus, the thieves could have stolen 32 - 4 = 28 hay blocks. If Sam initially had a parallelepiped consisting... | 500 | [
{
"input": "4",
"output": "28 41"
},
{
"input": "7",
"output": "47 65"
},
{
"input": "12",
"output": "48 105"
},
{
"input": "1",
"output": "17 17"
},
{
"input": "6",
"output": "34 57"
},
{
"input": "8",
"output": "40 73"
},
{
"input": "9",
... | 1,590,819,917 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 49 | 1,000 | 2,355,200 | n=int(input())
k=n
a=set()
a.add(n)
a.add(1)
w=999999999999999999999999999999999999999
ans=[1,1,1]
for i in range(2,int(n**0.5)+1):
if n%i==0:
a.add(i)
a.add(n//i)
#print(a)
for i in a:
for j in a:
for k in a:
if i*j*k!=n:
continue
... | Title: Help Farmer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put... | ```python
n=int(input())
k=n
a=set()
a.add(n)
a.add(1)
w=999999999999999999999999999999999999999
ans=[1,1,1]
for i in range(2,int(n**0.5)+1):
if n%i==0:
a.add(i)
a.add(n//i)
#print(a)
for i in a:
for j in a:
for k in a:
if i*j*k!=n:
continue
... | 0 | |
687 | A | NP-Hard Problem | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or bot... | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively.
Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting ... | If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes).
If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number ... | [
"4 2\n1 2\n2 3\n",
"3 3\n1 2\n2 3\n1 3\n"
] | [
"1\n2 \n2\n1 3 \n",
"-1\n"
] | In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish).
In the second sample, there is no way to satisfy both Pari and Arya. | 500 | [
{
"input": "4 2\n1 2\n2 3",
"output": "1\n2 \n2\n1 3 "
},
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "-1"
},
{
"input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5",
"output": "-1"
},
{
"input": "10 11\n4 10\n8 10\n2 3\n2 4\n7 1\n8 5\n2 8\n7 2\n1 2\n2 9\n6 8",
"output": "-1"
... | 1,566,437,969 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 764 | 13,209,600 | n,m = list(map(int,input().split()))
graph = [[]for _ in range(n)]
color = [0]*n
for i in range(m):
a,b = list(map(int,input().split()))
graph[a-1].append(b-1)
graph[b-1].append(a-1)
for i in range(n):
if color[i]:
continue
color[i] = 1
queue = [i]
while queue:
u... | Title: NP-Hard Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of ... | ```python
n,m = list(map(int,input().split()))
graph = [[]for _ in range(n)]
color = [0]*n
for i in range(m):
a,b = list(map(int,input().split()))
graph[a-1].append(b-1)
graph[b-1].append(a-1)
for i in range(n):
if color[i]:
continue
color[i] = 1
queue = [i]
while queue:
... | 3 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,449,091,604 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 0 | y = input("")
x = input("").split()
for i in range(len(x)):
x[i] = int(x[i])
even = 0
odd = 0
for i in range(len(x)):
if(x[i] % 2 == 0):
even += 1
else:
odd += 1
if(even == 1):
for j in range(len(x)):
if(x[j] % 2 == 0):
print(j + 1)
else... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
y = input("")
x = input("").split()
for i in range(len(x)):
x[i] = int(x[i])
even = 0
odd = 0
for i in range(len(x)):
if(x[i] % 2 == 0):
even += 1
else:
odd += 1
if(even == 1):
for j in range(len(x)):
if(x[j] % 2 == 0):
print(j ... | 3.977 |
691 | B | s-palindrome | PROGRAMMING | 1,600 | [
"implementation",
"strings"
] | null | null | Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.
You are given a string *s*. Check if the ... | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=1000) which consists of only English letters. | Print "TAK" if the string *s* is "s-palindrome" and "NIE" otherwise. | [
"oXoxoXo\n",
"bod\n",
"ER\n"
] | [
"TAK\n",
"TAK\n",
"NIE\n"
] | none | 0 | [
{
"input": "oXoxoXo",
"output": "TAK"
},
{
"input": "bod",
"output": "TAK"
},
{
"input": "ER",
"output": "NIE"
},
{
"input": "o",
"output": "TAK"
},
{
"input": "a",
"output": "NIE"
},
{
"input": "opo",
"output": "NIE"
},
{
"input": "HCMoxkg... | 1,588,471,265 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 140 | 0 | s=input()
n=len(s)
if len(s)%2==0:
print("NIE")
else:
i=0
j=n-1
while i<=j:
if s[i]==s[j]:
pass
elif s[i]=='p' or 'q' and s[j]=="p" or "q":
pass
elif s[i] == 'b' or 'd' and s[j] == "b" or "d":
pass
else:
print... | Title: s-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second h... | ```python
s=input()
n=len(s)
if len(s)%2==0:
print("NIE")
else:
i=0
j=n-1
while i<=j:
if s[i]==s[j]:
pass
elif s[i]=='p' or 'q' and s[j]=="p" or "q":
pass
elif s[i] == 'b' or 'd' and s[j] == "b" or "d":
pass
else:
... | 0 | |
644 | B | Processing Queries | PROGRAMMING | 1,700 | [
"*special",
"constructive algorithms",
"data structures",
"two pointers"
] | null | null | In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* are guaranteed to be distinct.
When a query appears server may react in three possible ways:
1. If ser... | The first line of the input contains two integers *n* and *b* (1<=≤<=*n*,<=*b*<=≤<=200<=000) — the number of queries and the maximum possible size of the query queue.
Then follow *n* lines with queries descriptions (in chronological order). Each description consists of two integers *t**i* and *d**i* (1<=≤<=*t**i*,<=*d... | Print the sequence of *n* integers *e*1,<=*e*2,<=...,<=*e**n*, where *e**i* is the moment the server will finish to process the *i*-th query (queries are numbered in the order they appear in the input) or <=-<=1 if the corresponding query will be rejected. | [
"5 1\n2 9\n4 8\n10 9\n15 2\n19 1\n",
"4 1\n2 8\n4 8\n10 9\n15 2\n"
] | [
"11 19 -1 21 22 \n",
"10 18 27 -1 \n"
] | Consider the first sample.
1. The server will start to process first query at the moment 2 and will finish to process it at the moment 11. 1. At the moment 4 second query appears and proceeds to the queue. 1. At the moment 10 third query appears. However, the server is still busy with query 1, *b* = 1 and there is... | 1,000 | [
{
"input": "5 1\n2 9\n4 8\n10 9\n15 2\n19 1",
"output": "11 19 -1 21 22 "
},
{
"input": "4 1\n2 8\n4 8\n10 9\n15 2",
"output": "10 18 27 -1 "
},
{
"input": "1 1\n1000000000 1000000000",
"output": "2000000000 "
},
{
"input": "4 3\n999999996 1000000000\n999999997 1000000000\n99... | 1,458,256,296 | 137,496 | Python 3 | OK | TESTS | 71 | 1,824 | 31,027,200 | n, b = [int(i) for i in input().split()]
q = [0] * n
bg = 0
en = 0
time = 0
res = [-1] * n
for it in range(n):
ev = [int(i) for i in input().split()]
ev.append(it)
while bg < en and max(time, q[bg][0]) <= ev[0]:
time = max(time, q[bg][0])
res[q[bg][2]] = time + q[bg][1]
t... | Title: Processing Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* ar... | ```python
n, b = [int(i) for i in input().split()]
q = [0] * n
bg = 0
en = 0
time = 0
res = [-1] * n
for it in range(n):
ev = [int(i) for i in input().split()]
ev.append(it)
while bg < en and max(time, q[bg][0]) <= ev[0]:
time = max(time, q[bg][0])
res[q[bg][2]] = time + q[bg][1]
... | 3 | |
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,686,713,370 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 11,980,800 | n=int(input())
x=list(map(int,input().split()))
def solve(i,p=0):
if i==n:
return 0
if x[i]==1 and p!=1:
return solve(i+1,1)
elif x[i]==2 and p!=2:
return solve(i+1,2)
elif x[i]==3:
if p:
return solve(i+1,[2,1][p-1])
else:
retur... | 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())
x=list(map(int,input().split()))
def solve(i,p=0):
if i==n:
return 0
if x[i]==1 and p!=1:
return solve(i+1,1)
elif x[i]==2 and p!=2:
return solve(i+1,2)
elif x[i]==3:
if p:
return solve(i+1,[2,1][p-1])
else:
... | 0 | |
554 | A | Kyoya and Photobooks | PROGRAMMING | 900 | [
"brute force",
"math",
"strings"
] | null | null | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters. | Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. | [
"a\n",
"hi\n"
] | [
"51\n",
"76\n"
] | In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | 250 | [
{
"input": "a",
"output": "51"
},
{
"input": "hi",
"output": "76"
},
{
"input": "y",
"output": "51"
},
{
"input": "kgan",
"output": "126"
},
{
"input": "zoabkyuvus",
"output": "276"
},
{
"input": "spyemhyznjieyhhbk",
"output": "451"
},
{
"i... | 1,503,941,747 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | s=input()
n=len(s)
print((n+1)*26-n) | Title: Kyoya and Photobooks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos b... | ```python
s=input()
n=len(s)
print((n+1)*26-n)
``` | 3 | |
975 | C | Valhalla Siege | PROGRAMMING | 1,400 | [
"binary search"
] | null | null | Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. T... | The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2,... | Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute. | [
"5 5\n1 2 1 2 1\n3 10 1 1 1\n",
"4 4\n1 2 3 4\n9 1 10 6\n"
] | [
"3\n5\n4\n4\n3\n",
"1\n4\n4\n1\n"
] | In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warr... | 1,500 | [
{
"input": "5 5\n1 2 1 2 1\n3 10 1 1 1",
"output": "3\n5\n4\n4\n3"
},
{
"input": "4 4\n1 2 3 4\n9 1 10 6",
"output": "1\n4\n4\n1"
},
{
"input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5",
"output": "10\n10\n5"
},
{
"input": "1 1\n56563128\n897699770",
"output": "1"
},
{
... | 1,696,171,377 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 296 | 33,280,000 | def get_pos(curr, strength_left, arrow):
l = curr
h = n - 1
while (l < h):
m = (l + h) // 2
strength_req = strength[m] - strength[curr] + strength_left
if strength_req > arrow:
h = m
elif strength_req == arrow:
return m
else:
if m ... | Title: Valhalla Siege
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line ... | ```python
def get_pos(curr, strength_left, arrow):
l = curr
h = n - 1
while (l < h):
m = (l + h) // 2
strength_req = strength[m] - strength[curr] + strength_left
if strength_req > arrow:
h = m
elif strength_req == arrow:
return m
else:
... | 3 | |
610 | A | Pasha and Stick | PROGRAMMING | 1,000 | [
"combinatorics",
"math"
] | null | null | Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to ... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. | The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. | [
"6\n",
"20\n"
] | [
"1\n",
"4\n"
] | There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | 500 | [
{
"input": "6",
"output": "1"
},
{
"input": "20",
"output": "4"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "2000000000",
"output": "4... | 1,658,166,179 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 61 | 0 | import math
n = int(input())
q = n/4
print(int(math.ceil(q) - 1) if n % 2 == 0 else 0)
| Title: Pasha and Stick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obv... | ```python
import math
n = int(input())
q = n/4
print(int(math.ceil(q) - 1) if n % 2 == 0 else 0)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane ar... | The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. | Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. | [
"4 3 9\n",
"4 3 24\n",
"2 4 4\n"
] | [
"2 2 L\n",
"4 3 R\n",
"1 2 R\n"
] | The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.
In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his pla... | 0 | [
{
"input": "4 3 9",
"output": "2 2 L"
},
{
"input": "4 3 24",
"output": "4 3 R"
},
{
"input": "2 4 4",
"output": "1 2 R"
},
{
"input": "3 10 24",
"output": "2 2 R"
},
{
"input": "10 3 59",
"output": "10 3 L"
},
{
"input": "10000 10000 160845880",
"... | 1,680,794,351 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | n, m, k = map(int, input().split())
print((k-1)//(2*n)+1, (k-1)%(2*n)//2+1, "RL"[k%2]) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desk... | ```python
n, m, k = map(int, input().split())
print((k-1)//(2*n)+1, (k-1)%(2*n)//2+1, "RL"[k%2])
``` | 0 | |
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,678,754,383 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 62 | 0 | message = str(input())
desired_message = ["h", "e", "l", "l", "o"]
pointer = 0
created_word = []
for char in desired_message:
while pointer < len(message):
if char == message[pointer]:
created_word.append(char)
pointer += 1
break
else:
pointer += ... | 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
message = str(input())
desired_message = ["h", "e", "l", "l", "o"]
pointer = 0
created_word = []
for char in desired_message:
while pointer < len(message):
if char == message[pointer]:
created_word.append(char)
pointer += 1
break
else:
p... | 3.969 |
349 | B | Color the Fence | PROGRAMMING | 1,700 | [
"data structures",
"dp",
"greedy",
"implementation"
] | null | null | Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.
Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d... | The first line contains a positive integer *v* (0<=≤<=*v*<=≤<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=≤<=*a**i*<=≤<=105). | Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1. | [
"5\n5 4 3 2 1 2 3 4 5\n",
"2\n9 11 1 12 5 8 9 10 6\n",
"0\n1 1 1 1 1 1 1 1 1\n"
] | [
"55555\n",
"33\n",
"-1\n"
] | none | 1,000 | [
{
"input": "5\n5 4 3 2 1 2 3 4 5",
"output": "55555"
},
{
"input": "2\n9 11 1 12 5 8 9 10 6",
"output": "33"
},
{
"input": "0\n1 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "50\n5 3 10 2 2 4 3 6 5",
"output": "5555555555555555555555555"
},
{
"input": "22\n405 3... | 1,618,707,857 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 248 | 409,600 | def paint(vLeft):
if vLeft in dp:
return dp[vLeft]
if vLeft < minDigitCost:
return ('', 0)
max_ = 0
for digit in range(9):
if vLeft >= digitCost[digit]:
temp = paint(vLeft%digitCost[digit])
if temp[1] + vLeft//digitCost[digit] >= max_:
max_ = temp[1] + vLeft//digitCost[digit]
dp[... | Title: Color the Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. ... | ```python
def paint(vLeft):
if vLeft in dp:
return dp[vLeft]
if vLeft < minDigitCost:
return ('', 0)
max_ = 0
for digit in range(9):
if vLeft >= digitCost[digit]:
temp = paint(vLeft%digitCost[digit])
if temp[1] + vLeft//digitCost[digit] >= max_:
max_ = temp[1] + vLeft//digitCost[digit... | 0 | |
505 | C | Mr. Kitayuta, the Treasure Hunter | PROGRAMMING | 1,900 | [
"dfs and similar",
"dp",
"two pointers"
] | null | null | The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are *n* gems in the Shuseki Islands in total, and the *i*-th gem is located on island... | The first line of the input contains two space-separated integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=30000), denoting the number of the gems in the Shuseki Islands and the length of the Mr. Kitayuta's first jump, respectively.
The next *n* lines describe the location of the gems. The *i*-th of them (1<=≤<=*i*<=≤<=*n*) c... | Print the maximum number of gems that Mr. Kitayuta can collect. | [
"4 10\n10\n21\n27\n27\n",
"8 8\n9\n19\n28\n36\n45\n55\n66\n78\n",
"13 7\n8\n8\n9\n16\n17\n17\n18\n21\n23\n24\n24\n26\n30\n"
] | [
"3\n",
"6\n",
"4\n"
] | In the first sample, the optimal route is 0 → 10 (+1 gem) → 19 → 27 (+2 gems) → ...
In the second sample, the optimal route is 0 → 8 → 15 → 21 → 28 (+1 gem) → 36 (+1 gem) → 45 (+1 gem) → 55 (+1 gem) → 66 (+1 gem) → 78 (+1 gem) → ...
In the third sample, the optimal route is 0 → 7 → 13 → ... | 1,500 | [
{
"input": "4 10\n10\n21\n27\n27",
"output": "3"
},
{
"input": "8 8\n9\n19\n28\n36\n45\n55\n66\n78",
"output": "6"
},
{
"input": "13 7\n8\n8\n9\n16\n17\n17\n18\n21\n23\n24\n24\n26\n30",
"output": "4"
},
{
"input": "8 4\n9\n15\n15\n16\n22\n25\n25\n28",
"output": "8"
},
... | 1,679,810,414 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 389 | 62,976,000 | n, d = map(int, input().split())
# Read gem locations and store them in a set for fast lookup
gems = set()
for i in range(n):
p = int(input())
gems.add(p)
# Initialize dp array with -1
dp = [[-1] * 501 for _ in range(30001)]
def collect_gems(x, y):
# Base case: if x is beyond the last island ... | Title: Mr. Kitayuta, the Treasure Hunter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known... | ```python
n, d = map(int, input().split())
# Read gem locations and store them in a set for fast lookup
gems = set()
for i in range(n):
p = int(input())
gems.add(p)
# Initialize dp array with -1
dp = [[-1] * 501 for _ in range(30001)]
def collect_gems(x, y):
# Base case: if x is beyond the la... | 0 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,666,239,512 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | a,b = [int(x) for x in input().split(' ')]
import math
k = 7-max(a,b)
print(int(k/math.gcd(k,6)),'/',int(6/math.gcd(k,6))) | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
a,b = [int(x) for x in input().split(' ')]
import math
k = 7-max(a,b)
print(int(k/math.gcd(k,6)),'/',int(6/math.gcd(k,6)))
``` | 0 |
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,... | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strict... | Print a single number — the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for whic... | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9... | 1,437,434,400 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input())
a = [int(x) for x in input().split()]
print(max([min([a[i+1]-a[i] for i in range(n-2)])] + [a[i+1]-a[i] for i in range(n-1)]))
| Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 fo... | ```python
n = int(input())
a = [int(x) for x in input().split()]
print(max([min([a[i+1]-a[i] for i in range(n-2)])] + [a[i+1]-a[i] for i in range(n-1)]))
``` | 0 | |
895 | A | Pizza Separation | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide a... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=360) — the number of pieces into which the delivered pizza was cut.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360) — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360. | Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya. | [
"4\n90 90 90 90\n",
"3\n100 100 160\n",
"1\n360\n",
"4\n170 30 150 10\n"
] | [
"0\n",
"40\n",
"360\n",
"0\n"
] | In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Pety... | 500 | [
{
"input": "4\n90 90 90 90",
"output": "0"
},
{
"input": "3\n100 100 160",
"output": "40"
},
{
"input": "1\n360",
"output": "360"
},
{
"input": "4\n170 30 150 10",
"output": "0"
},
{
"input": "5\n10 10 10 10 320",
"output": "280"
},
{
"input": "8\n45 4... | 1,511,718,407 | 6,107 | PyPy 3 | WRONG_ANSWER | PRETESTS | 7 | 109 | 23,142,400 | n = int(input())
ar = input().split(" ")
ar = [int(i) for i in ar]
ar.sort()
lala = [ar[0]]
ar = ar[1:]
while(len(ar) != 0):
now = []
for i in lala:
now.append(i+ar[0])
lala += now
lala = list(set(lala))
ar = ar[1:]
# print(ar)
ans = 360
for i in lala:
ans = min(ans,a... | Title: Pizza Separation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut in... | ```python
n = int(input())
ar = input().split(" ")
ar = [int(i) for i in ar]
ar.sort()
lala = [ar[0]]
ar = ar[1:]
while(len(ar) != 0):
now = []
for i in lala:
now.append(i+ar[0])
lala += now
lala = list(set(lala))
ar = ar[1:]
# print(ar)
ans = 360
for i in lala:
ans =... | 0 | |
534 | C | Polycarpus' Dice | PROGRAMMING | 1,600 | [
"math"
] | null | null | Polycarp has *n* dice *d*1,<=*d*2,<=...,<=*d**n*. The *i*-th dice shows numbers from 1 to *d**i*. Polycarp rolled all the dice and the sum of numbers they showed is *A*. Agrippina didn't see which dice showed what number, she knows only the sum *A* and the values *d*1,<=*d*2,<=...,<=*d**n*. However, she finds it enough... | The first line contains two integers *n*,<=*A* (1<=≤<=*n*<=≤<=2·105,<=*n*<=≤<=*A*<=≤<=*s*) — the number of dice and the sum of shown values where *s*<==<=*d*1<=+<=*d*2<=+<=...<=+<=*d**n*.
The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=106), where *d**i* is the maximum value that the... | Print *n* integers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* is the number of values for which it is guaranteed that the *i*-th dice couldn't show them. | [
"2 8\n4 4\n",
"1 3\n5\n",
"2 3\n2 3\n"
] | [
"3 3 ",
"4 ",
"0 1 "
] | In the first sample from the statement *A* equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement *A* equal to 3 could be obtained when the single dice shows 3. Correspondingly, it ... | 1,500 | [
{
"input": "2 8\n4 4",
"output": "3 3 "
},
{
"input": "1 3\n5",
"output": "4 "
},
{
"input": "2 3\n2 3",
"output": "0 1 "
},
{
"input": "1 1\n3",
"output": "2 "
},
{
"input": "1 2\n3",
"output": "2 "
},
{
"input": "2 2\n2 3",
"output": "1 2 "
},
... | 1,680,321,642 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 77 | 102,400 | import sys
from math import *
from collections import Counter,defaultdict,deque
input=sys.stdin.readline
mod=10**9+7
def get_ints():return map(int,input().split())
def get_int():return int(input())
def get_array():return list(map(int,input().split()))
def input():return sys.stdin.readline().strip()
# for _ in range(in... | Title: Polycarpus' Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has *n* dice *d*1,<=*d*2,<=...,<=*d**n*. The *i*-th dice shows numbers from 1 to *d**i*. Polycarp rolled all the dice and the sum of numbers they showed is *A*. Agrippina didn't see which dice showed what numb... | ```python
import sys
from math import *
from collections import Counter,defaultdict,deque
input=sys.stdin.readline
mod=10**9+7
def get_ints():return map(int,input().split())
def get_int():return int(input())
def get_array():return list(map(int,input().split()))
def input():return sys.stdin.readline().strip()
# for _ i... | 0 | |
982 | A | Row | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms"
] | null | null | You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means t... | The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating. | Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase). | [
"3\n101\n",
"4\n1011\n",
"5\n10001\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | 500 | [
{
"input": "3\n101",
"output": "Yes"
},
{
"input": "4\n1011",
"output": "No"
},
{
"input": "5\n10001",
"output": "No"
},
{
"input": "1\n0",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "100\n010100101010100101001001010100101010010... | 1,528,999,342 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 77 | 0 | n = int(input())
s = input()
a, b = '', ''
for i in range(n):
if i % 2 == 0:
a += '1'
b += '0'
else:
a += '0'
b += '1'
if s == a or s == b:
print("Yes")
else:
print("No") | Title: Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating th... | ```python
n = int(input())
s = input()
a, b = '', ''
for i in range(n):
if i % 2 == 0:
a += '1'
b += '0'
else:
a += '0'
b += '1'
if s == a or s == b:
print("Yes")
else:
print("No")
``` | 0 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,542,456,772 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 124 | 0 | m = list(input())
n = list(input())
z = [0 for i in range(len(n))]
for i in range(len(n)):
if m[i] == n[i]:
z[i] = 0
else:
z[i] = 1
print(*z,sep="") | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
m = list(input())
n = list(input())
z = [0 for i in range(len(n))]
for i in range(len(n)):
if m[i] == n[i]:
z[i] = 0
else:
z[i] = 1
print(*z,sep="")
``` | 3.969 |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,544,620,545 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 218 | 0 | import math
a , b, n= [int(i) for i in input().split()]
ans = False
while True:
if ans == False:
g = math.gcd(a,n)
n -=g
if n <=0:
print(int(ans))
break
ans = not ans
else:
g = math.gcd(b,n)
n -=g
if n <=0:
... | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
import math
a , b, n= [int(i) for i in input().split()]
ans = False
while True:
if ans == False:
g = math.gcd(a,n)
n -=g
if n <=0:
print(int(ans))
break
ans = not ans
else:
g = math.gcd(b,n)
n -=g
if n <=0:
... | 3 | |
448 | B | Suffix Structures | PROGRAMMING | 1,400 | [
"implementation",
"strings"
] | null | null | Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.
At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*. You need to transform word *s* into word *t*". The task looked simple to the guys because they know th... | The first line contains a non-empty word *s*. The second line contains a non-empty word *t*. Words *s* and *t* are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters. | In the single line print the answer to the problem. Print "need tree" (without the quotes) if word *s* cannot be transformed into word *t* even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without th... | [
"automaton\ntomat\n",
"array\narary\n",
"both\nhot\n",
"need\ntree\n"
] | [
"automaton\n",
"array\n",
"both\n",
"need tree\n"
] | In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot". | 1,000 | [
{
"input": "automaton\ntomat",
"output": "automaton"
},
{
"input": "array\narary",
"output": "array"
},
{
"input": "both\nhot",
"output": "both"
},
{
"input": "need\ntree",
"output": "need tree"
},
{
"input": "abacaba\naaaa",
"output": "automaton"
},
{
... | 1,643,451,745 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 77 | 0 | def main():
s = input()
t = input()
ans_list = ['automaton', 'array', 'both', 'need tree']
ans = ''
if s == t:
ans = ans_list[0]
elif sorted(s) == sorted(t):
ans = ans_list[1]
elif len(s) < len(t):
ans = ans_list[3]
if ans != '':
print(ans)
return
ls = [0 for _ in range(26)]
lt = ls.copy()
for... | Title: Suffix Structures
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.
At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*.... | ```python
def main():
s = input()
t = input()
ans_list = ['automaton', 'array', 'both', 'need tree']
ans = ''
if s == t:
ans = ans_list[0]
elif sorted(s) == sorted(t):
ans = ans_list[1]
elif len(s) < len(t):
ans = ans_list[3]
if ans != '':
print(ans)
return
ls = [0 for _ in range(26)]
lt = ls.co... | 3 | |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line co... | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,616,473,861 | 2,147,483,647 | PyPy 3 | OK | TESTS | 58 | 187 | 10,444,800 | def main():
n,b,d = input().split()
n = int(n)
b = int(b)
d = int(d)
arr = list(map(int, input().split()))
total = 0
count = 0
for j in arr:
if j <= b:
total += j
if total > d:
count += 1
total = 0
print(co... | Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
def main():
n,b,d = input().split()
n = int(n)
b = int(b)
d = int(d)
arr = list(map(int, input().split()))
total = 0
count = 0
for j in arr:
if j <= b:
total += j
if total > d:
count += 1
total = 0
... | 3 | |
930 | A | Peculiar apple-tree | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near base of tree and any other inflorescence with number *i* (*i*<=><=1) is situated at the ... | First line of input contains single integer number *n* (2<=≤<=*n*<=≤<=100<=000) — number of inflorescences.
Second line of input contains sequence of *n*<=-<=1 integer numbers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=<<=*i*), where *p**i* is number of inflorescence into which the apple from *i*-th inflorescence r... | Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest. | [
"3\n1 1\n",
"5\n1 2 2 2\n",
"18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n"
] | [
"1\n",
"3\n",
"4\n"
] | In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.
In the second example Arcady will be able to collect 3 apples. First one is one initial... | 500 | [
{
"input": "3\n1 1",
"output": "1"
},
{
"input": "5\n1 2 2 2",
"output": "3"
},
{
"input": "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4",
"output": "4"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "3\n1 2",
"output": "3"
},
{
"input": "20\n1 1 1 1 1 ... | 1,691,329,477 | 2,147,483,647 | Python 3 | OK | TESTS | 90 | 140 | 25,292,800 | n = int(input())
a = [int(e) for e in input().split()]
d = {1:0}
for k, v in enumerate(a):
d[k+2] = d[v] + 1
d2 = {}
for k, v in d.items():
d2[v] = d2.get(v,0) + 1
s = sum([v%2 for v in d2.values()])
print(s) | Title: Peculiar apple-tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is ... | ```python
n = int(input())
a = [int(e) for e in input().split()]
d = {1:0}
for k, v in enumerate(a):
d[k+2] = d[v] + 1
d2 = {}
for k, v in d.items():
d2[v] = d2.get(v,0) + 1
s = sum([v%2 for v in d2.values()])
print(s)
``` | 3 | |
637 | A | Voting for Photos | PROGRAMMING | 1,000 | [
"*special",
"constructive algorithms",
"implementation"
] | null | null | After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the win... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the total likes to the published photoes.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000), where *a**i* is the identifier of the photo which got the *i*-th like. | Print the identifier of the photo which won the elections. | [
"5\n1 3 2 2 1\n",
"9\n100 200 300 200 100 300 300 100 200\n"
] | [
"2\n",
"300\n"
] | In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second).
Thus, the winner is the photo with identifier 2, as it got:
- more likes than the photo with id 3; - as many likes as the photo with id 1, but t... | 500 | [
{
"input": "5\n1 3 2 2 1",
"output": "2"
},
{
"input": "9\n100 200 300 200 100 300 300 100 200",
"output": "300"
},
{
"input": "1\n5",
"output": "5"
},
{
"input": "1\n1000000",
"output": "1000000"
},
{
"input": "5\n1 3 4 2 2",
"output": "2"
},
{
"input... | 1,458,115,535 | 2,147,483,647 | Python 3 | OK | TESTS | 65 | 124 | 0 | n = int(input())
photos = {}
best_photo = 0
max_likes = 0
q = list(map(int, input().split()))
for id in q:
try:
photos[id] += 1
except KeyError:
photos[id] = 1
if photos[id] > max_likes:
best_photo = id
max_likes = photos[id]
print(best_photo)
| Title: Voting for Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rule... | ```python
n = int(input())
photos = {}
best_photo = 0
max_likes = 0
q = list(map(int, input().split()))
for id in q:
try:
photos[id] += 1
except KeyError:
photos[id] = 1
if photos[id] > max_likes:
best_photo = id
max_likes = photos[id]
print(best_photo)
``` | 3 | |
558 | B | Amr and The Large Array | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subseg... | The first line contains one number *n* (1<=≤<=*n*<=≤<=105), the size of the array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106), representing elements of the array. | Output two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them. | [
"5\n1 1 2 2 1\n",
"5\n1 2 2 3 1\n",
"6\n1 2 2 1 1 2\n"
] | [
"1 5",
"2 3",
"1 5"
] | A subsegment *B* of an array *A* from *l* to *r* is an array of size *r* - *l* + 1 where *B*<sub class="lower-index">*i*</sub> = *A*<sub class="lower-index">*l* + *i* - 1</sub> for all 1 ≤ *i* ≤ *r* - *l* + 1 | 1,000 | [
{
"input": "5\n1 1 2 2 1",
"output": "1 5"
},
{
"input": "5\n1 2 2 3 1",
"output": "2 3"
},
{
"input": "6\n1 2 2 1 1 2",
"output": "1 5"
},
{
"input": "10\n1 1000000 2 1000000 3 2 1000000 1 2 1",
"output": "2 7"
},
{
"input": "10\n1 2 3 4 5 5 1 2 3 4",
"output... | 1,436,892,636 | 6,036 | Python 3 | OK | TESTS | 49 | 295 | 16,384,000 | def bin_search(n,a):
l = 0
r = len(a)-1
while l<=r:
m = (l+r)//2
if n>a[m][0]:
l = m+1
if n<a[m][0]:
r = m-1
if n == a[m][0]:
return m
return -1
n = int(input())
a = input().split()
def ke(n):
return n[1]
def f(n):
... | Title: Amr and The Large Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to... | ```python
def bin_search(n,a):
l = 0
r = len(a)-1
while l<=r:
m = (l+r)//2
if n>a[m][0]:
l = m+1
if n<a[m][0]:
r = m-1
if n == a[m][0]:
return m
return -1
n = int(input())
a = input().split()
def ke(n):
return n[1]
d... | 3 | |
387 | B | George and Round | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"two pointers"
] | null | null | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirem... | Print a single integer — the answer to the problem. | [
"3 5\n1 2 3\n1 2 2 3 3\n",
"3 5\n1 2 3\n1 1 1 1 1\n",
"3 1\n2 3 4\n1\n"
] | [
"0\n",
"2\n",
"3\n"
] | In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems wi... | 1,000 | [
{
"input": "3 5\n1 2 3\n1 2 2 3 3",
"output": "0"
},
{
"input": "3 5\n1 2 3\n1 1 1 1 1",
"output": "2"
},
{
"input": "3 1\n2 3 4\n1",
"output": "3"
},
{
"input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 97... | 1,647,187,343 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 512,000 | lengthnmOfPbOfGoodRound,lengthrqOfPbOfGoodRound = [int(i) for i in input().split()]
PbOfGoodRound = [int(i) for i in input().split()]
rqOfGoodRound = [int(i) for i in input().split()]
deleted =[]
for i in range(len(PbOfGoodRound)):
while PbOfGoodRound[i]>min(rqOfGoodRound)and len(rqOfGoodRound)>1:
... | Title: George and Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
T... | ```python
lengthnmOfPbOfGoodRound,lengthrqOfPbOfGoodRound = [int(i) for i in input().split()]
PbOfGoodRound = [int(i) for i in input().split()]
rqOfGoodRound = [int(i) for i in input().split()]
deleted =[]
for i in range(len(PbOfGoodRound)):
while PbOfGoodRound[i]>min(rqOfGoodRound)and len(rqOfGoodRound... | 0 | |
678 | D | Iterated Linear Function | PROGRAMMING | 1,700 | [
"math",
"number theory"
] | null | null | Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=><=0. For the given integer values *A*, *B*, *n* and *x* find the value of *g*(*n*)(*x*) modulo 109<=+<=7. | The only line contains four integers *A*, *B*, *n* and *x* (1<=≤<=*A*,<=*B*,<=*x*<=≤<=109,<=1<=≤<=*n*<=≤<=1018) — the parameters from the problem statement.
Note that the given value *n* can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you c... | Print the only integer *s* — the value *g*(*n*)(*x*) modulo 109<=+<=7. | [
"3 4 1 1\n",
"3 4 2 1\n",
"3 4 3 1\n"
] | [
"7\n",
"25\n",
"79\n"
] | none | 0 | [
{
"input": "3 4 1 1",
"output": "7"
},
{
"input": "3 4 2 1",
"output": "25"
},
{
"input": "3 4 3 1",
"output": "79"
},
{
"input": "1 1 1 1",
"output": "2"
},
{
"input": "3 10 723 6",
"output": "443623217"
},
{
"input": "14 81 51 82",
"output": "908... | 1,527,232,577 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define F first
#define S second
#define ld long double
#define pb push_back
#define sz size
#define ll long long
using namespace std;
ll mod_pow(ll a,ll b,ll mod){
ll ans=1ll;
while(b){
if(b&1)ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
ll a,b,n,x;
int main(){
scanf("%lld%lld%lld%lld",&a,... | Title: Iterated Linear Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=><=0. For the given integer values *A*, *B*, *n* and *x* find th... | ```python
#include <bits/stdc++.h>
#define F first
#define S second
#define ld long double
#define pb push_back
#define sz size
#define ll long long
using namespace std;
ll mod_pow(ll a,ll b,ll mod){
ll ans=1ll;
while(b){
if(b&1)ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
ll a,b,n,x;
int main(){
scanf("%lld%lld%ll... | -1 | |
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at prog... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to... | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output... | 1,689,356,367 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 31 | 0 | n= int (input())
my_list=list(map(int,input().split()))
nprint=""
partOfPrint=""
tprint=""
i=-1
count=0
while my_list.count("nothing")!=len(my_list)-1 :
i+=1
if (str(my_list[i])!="nothing") and (not partOfPrint.__contains__(str(my_list[i]))) :
partOfPrint+=str(my_list[i])+" "
... | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)... | ```python
n= int (input())
my_list=list(map(int,input().split()))
nprint=""
partOfPrint=""
tprint=""
i=-1
count=0
while my_list.count("nothing")!=len(my_list)-1 :
i+=1
if (str(my_list[i])!="nothing") and (not partOfPrint.__contains__(str(my_list[i]))) :
partOfPrint+=str(my_lis... | -1 | |
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"... | 1,690,967,181 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 93 | 0 | n = int(input())
ans = 0
for i in range(n):
a, b = input().split()
a = int(a)
b = int(b)
if a+2 <= b:
ans += 1
print(ans)
| Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want ... | ```python
n = int(input())
ans = 0
for i in range(n):
a, b = input().split()
a = int(a)
b = int(b)
if a+2 <= b:
ans += 1
print(ans)
``` | 3 | |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,694,722,264 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 62 | 0 | a = list(map(int, input().split()))
s = input().strip()
print(sum(a[i] * s.count(str(i + 1)) for i in range(4))) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
a = list(map(int, input().split()))
s = input().strip()
print(sum(a[i] * s.count(str(i + 1)) for i in range(4)))
``` | 3 | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,676,590,774 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 92 | 0 | str1 = input()
str2 = input()
pos = 1
for ch in str2:
if str1[pos-1] == ch:
pos += 1
print(pos) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
str1 = input()
str2 = input()
pos = 1
for ch in str2:
if str1[pos-1] == ch:
pos += 1
print(pos)
``` | 3 | |
411 | C | Kicker | PROGRAMMING | 1,700 | [
"implementation"
] | null | null | Kicker (table football) is a board game based on football, in which players control the footballers' figures mounted on rods by using bars to get the ball into the opponent's goal. When playing two on two, one player of each team controls the goalkeeper and the full-backs (plays defence), the other player controls the ... | The input contain the players' description in four lines. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100) — the defence and the attack skill of the *i*-th player, correspondingly. | If the first team can win, print phrase "Team 1" (without the quotes), if the second team can win, print phrase "Team 2" (without the quotes). If no of the teams can definitely win, print "Draw" (without the quotes). | [
"1 100\n100 1\n99 99\n99 99\n",
"1 1\n2 2\n3 3\n2 2\n",
"3 3\n2 2\n1 1\n2 2\n"
] | [
"Team 1\n",
"Team 2\n",
"Draw\n"
] | Let consider the first test sample. The first team can definitely win if it will choose the following arrangement: the first player plays attack, the second player plays defence.
Consider the second sample. The order of the choosing roles for players makes sense in this sample. As the members of the first team choose ... | 0 | [
{
"input": "1 100\n100 1\n99 99\n99 99",
"output": "Team 1"
},
{
"input": "1 1\n2 2\n3 3\n2 2",
"output": "Team 2"
},
{
"input": "3 3\n2 2\n1 1\n2 2",
"output": "Draw"
},
{
"input": "80 79\n79 30\n80 81\n40 80",
"output": "Team 2"
},
{
"input": "10 10\n4 9\n8 9\n7... | 1,405,275,160 | 5,680 | Python 3 | OK | TESTS | 67 | 140 | 0 | p11 = list(map(int, input().split()))
p12 = list(map(int, input().split()))
p21 = list(map(int, input().split()))
p22 = list(map(int, input().split()))
def f(a, b, c, d):
if a[0] > d[1] and b[1] > c[0]:
return 1
if a[0] < d[1] and b[1] < c[0]:
return 2
return 0
c1 = f(p11, p12,... | Title: Kicker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kicker (table football) is a board game based on football, in which players control the footballers' figures mounted on rods by using bars to get the ball into the opponent's goal. When playing two on two, one player of each tea... | ```python
p11 = list(map(int, input().split()))
p12 = list(map(int, input().split()))
p21 = list(map(int, input().split()))
p22 = list(map(int, input().split()))
def f(a, b, c, d):
if a[0] > d[1] and b[1] > c[0]:
return 1
if a[0] < d[1] and b[1] < c[0]:
return 2
return 0
c1 = f... | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,663,227,854 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | l=list(map(int,input().split()))
m,n,a=l[0],l[1],l[2]
ans=((m-1)//a+1)*((n-1)//a+1)
print(ans) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
l=list(map(int,input().split()))
m,n,a=l[0],l[1],l[2]
ans=((m-1)//a+1)*((n-1)//a+1)
print(ans)
``` | 3.977 |
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,531,507,346 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 | S = input()
str =''
for i in S:
#print(i)
if str == '':
if i == 'h':
str += i
#print(str)
continue
else:
continue
elif str == 'h':
if i == 'e':
str += i
#print(str)
continue
el... | 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
S = input()
str =''
for i in S:
#print(i)
if str == '':
if i == 'h':
str += i
#print(str)
continue
else:
continue
elif str == 'h':
if i == 'e':
str += i
#print(str)
continue
... | 3.9455 |
388 | A | Fox and Box Accumulation | PROGRAMMING | 1,400 | [
"greedy",
"sortings"
] | null | null | Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100). | Output a single integer — the minimal possible number of piles. | [
"3\n0 0 10\n",
"5\n0 1 2 3 4\n",
"4\n0 0 0 0\n",
"9\n0 1 0 2 0 1 1 2 10\n"
] | [
"2\n",
"1\n",
"4\n",
"3\n"
] | In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). | 500 | [
{
"input": "3\n0 0 10",
"output": "2"
},
{
"input": "5\n0 1 2 3 4",
"output": "1"
},
{
"input": "4\n0 0 0 0",
"output": "4"
},
{
"input": "9\n0 1 0 2 0 1 1 2 10",
"output": "3"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "2\n0 0",
"output": "... | 1,655,262,898 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 46 | 1,945,600 | n = int(input())
a = list(map(int, input().split()))
a.sort()
h = [0] * 101
for i in range(n):
for j in range(101):
if(a[i] >= h[j]):
h[j] += 1
break
c = 101 - h.count(0)
print(c)
| Title: Fox and Box Accumulation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box... | ```python
n = int(input())
a = list(map(int, input().split()))
a.sort()
h = [0] * 101
for i in range(n):
for j in range(101):
if(a[i] >= h[j]):
h[j] += 1
break
c = 101 - h.count(0)
print(c)
``` | 3 | |
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the numb... | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
... | 1,664,956,514 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 46 | 717 | 19,353,600 | polje = []
n = int(input())
for par in range(0, n):
a,b = input().split(' ')
polje.append([int(a),int(b)])
polje.sort(key=lambda x:x[1],reverse=False)
check = False
for x in range(0, n-1):
if polje[x][0] > polje[x+1][0]:
check = True
break
else:
continue
if check:
print('Happ... | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the... | ```python
polje = []
n = int(input())
for par in range(0, n):
a,b = input().split(' ')
polje.append([int(a),int(b)])
polje.sort(key=lambda x:x[1],reverse=False)
check = False
for x in range(0, n-1):
if polje[x][0] > polje[x+1][0]:
check = True
break
else:
continue
if check:
p... | 3 | |
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,590,419,392 | 2,147,483,647 | PyPy 3 | OK | TESTS | 23 | 280 | 1,331,200 | def main():
N=int(input())
ans=0
for j in range(1,N+1):
i=2
num=j
count=0
while(num!=1):
if(num%i==0):
count+=1
while(num%i==0):
num//=i
i+=1
if count==2:
ans+=1
... | 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
def main():
N=int(input())
ans=0
for j in range(1,N+1):
i=2
num=j
count=0
while(num!=1):
if(num%i==0):
count+=1
while(num%i==0):
num//=i
i+=1
if count==2:
a... | 3.92752 |
527 | C | Glass Carving | PROGRAMMING | 1,500 | [
"binary search",
"data structures",
"implementation"
] | null | null | Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular *w* mm <=×<= *h* mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how.
In order not to waste time, he decided to prac... | The first line contains three integers *w*,<=*h*,<=*n* (2<=≤<=*w*,<=*h*<=≤<=200<=000, 1<=≤<=*n*<=≤<=200<=000).
Next *n* lines contain the descriptions of the cuts. Each description has the form *H* *y* or *V* *x*. In the first case Leonid makes the horizontal cut at the distance *y* millimeters (1<=≤<=*y*<=≤<=*h*<=-<=... | After each cut print on a single line the area of the maximum available glass fragment in mm2. | [
"4 3 4\nH 2\nV 2\nV 3\nV 1\n",
"7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1\n"
] | [
"8\n4\n4\n2\n",
"28\n16\n12\n6\n4\n"
] | Picture for the first sample test: | 1,500 | [
{
"input": "4 3 4\nH 2\nV 2\nV 3\nV 1",
"output": "8\n4\n4\n2"
},
{
"input": "7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1",
"output": "28\n16\n12\n6\n4"
},
{
"input": "2 2 1\nV 1",
"output": "2"
},
{
"input": "2 2 1\nH 1",
"output": "2"
},
{
"input": "2 2 2\nV 1\nH 1",
"ou... | 1,588,176,431 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 204,800 | # -*- coding: utf-8 -*-
"""
Created on Wed Apr 29 11:12:24 2020
@author: Diego
"""
import numpy as np
w,h,n = list(map(int, (input().split())))
v = [0,w]
H = [0,h]
ar = []
for i in range(n):
pos, num = list((input().split()))
num = int(num)
#pos,num = i
if(pos == 'H'):
H.appen... | Title: Glass Carving
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular *w* mm <=×<= *h* mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What ... | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 29 11:12:24 2020
@author: Diego
"""
import numpy as np
w,h,n = list(map(int, (input().split())))
v = [0,w]
H = [0,h]
ar = []
for i in range(n):
pos, num = list((input().split()))
num = int(num)
#pos,num = i
if(pos == 'H'):
... | -1 | |
319 | C | Kalila and Dimna in the Logging Industry | PROGRAMMING | 2,100 | [
"dp",
"geometry"
] | null | null | Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut *n* trees with heights *a*1,<=*a*2,<=...,<=*a**n*. They bought a chain saw from a shop. Each time they use the chain sa... | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line of input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). The third line of input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (0<=≤<=*b**i*<=≤<=109).
It's guaranteed that *a*1<==<=1, *b**n*<==<=0, *a*1<=&l... | The only line of output must contain the minimum cost of cutting all the trees completely.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"5\n1 2 3 4 5\n5 4 3 2 0\n",
"6\n1 2 3 10 20 30\n6 5 4 3 2 0\n"
] | [
"25\n",
"138\n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 4 5\n5 4 3 2 0",
"output": "25"
},
{
"input": "6\n1 2 3 10 20 30\n6 5 4 3 2 0",
"output": "138"
}
] | 1,374,664,653 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 156 | 2,048,000 | n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
dp = [-1]*n
dp[-1] = 0
for x in range(n-2, -1, -1):
lo = x+1
hi = n-1
while hi-lo > 10:
m1 = lo + (hi-lo)/3
m2 = m1 + (hi-lo)/3
if A[m1]*B[x]+dp[m1] < A[m2]*B[x]+dp[m2]:
... | Title: Kalila and Dimna in the Logging Industry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle a... | ```python
n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
dp = [-1]*n
dp[-1] = 0
for x in range(n-2, -1, -1):
lo = x+1
hi = n-1
while hi-lo > 10:
m1 = lo + (hi-lo)/3
m2 = m1 + (hi-lo)/3
if A[m1]*B[x]+dp[m1] < A[m2]*B[x]+dp[m2]:
... | -1 | |
139 | A | Petr and Book | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. S... | The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book.
The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and... | Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. | [
"100\n15 20 20 15 10 30 45\n",
"2\n1 0 0 0 0 0 0\n"
] | [
"6\n",
"1\n"
] | Note to the first sample:
By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else).
Note to the second... | 500 | [
{
"input": "100\n15 20 20 15 10 30 45",
"output": "6"
},
{
"input": "2\n1 0 0 0 0 0 0",
"output": "1"
},
{
"input": "100\n100 200 100 200 300 400 500",
"output": "1"
},
{
"input": "3\n1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "1\n1 1 1 1 1 1 1",
"output": "1... | 1,622,071,240 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 154 | 0 | n = int(input())
a = list(map(int, input().split()))
i = 0
while n>a[i]:
n-=a[i]
i = (i+1)%7
print(i+1) | Title: Petr and Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight s... | ```python
n = int(input())
a = list(map(int, input().split()))
i = 0
while n>a[i]:
n-=a[i]
i = (i+1)%7
print(i+1)
``` | 3 | |
932 | B | Recursive Queries | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"dfs and similar"
] | null | null | Let us define two functions *f* and *g* on positive integer numbers.
You need to process *Q* queries. In each query, you will be given three integers *l*, *r* and *k*. You need to print the number of integers *x* between *l* and *r* inclusive, such that *g*(*x*)<==<=*k*. | The first line of the input contains an integer *Q* (1<=≤<=*Q*<=≤<=2<=×<=105) representing the number of queries.
*Q* lines follow, each of which contains 3 integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=106,<=1<=≤<=*k*<=≤<=9). | For each query, print a single line containing the answer for that query. | [
"4\n22 73 9\n45 64 6\n47 55 7\n2 62 4\n",
"4\n82 94 6\n56 67 4\n28 59 9\n39 74 4\n"
] | [
"1\n4\n0\n8\n",
"3\n1\n1\n5\n"
] | In the first example:
- *g*(33) = 9 as *g*(33) = *g*(3 × 3) = *g*(9) = 9 - *g*(47) = *g*(48) = *g*(60) = *g*(61) = 6 - There are no such integers between 47 and 55. - *g*(4) = *g*(14) = *g*(22) = *g*(27) = *g*(39) = *g*(40) = *g*(41) = *g*(58) = 4 | 1,000 | [
{
"input": "4\n22 73 9\n45 64 6\n47 55 7\n2 62 4",
"output": "1\n4\n0\n8"
},
{
"input": "4\n82 94 6\n56 67 4\n28 59 9\n39 74 4",
"output": "3\n1\n1\n5"
}
] | 1,519,073,012 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 7,065,600 | from functools import reduce, lru_cache
max = int(10e6 + 5)
def gen(l, r, k):
for i in range(l, r+1):
yield 1 if g(i) == k else 0
def main():
q = int(input())
for _ in range(q):
l, r, k = (int(x) for x in input().split())
s = sum(gen(l, r, k))
print(s)
... | Title: Recursive Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let us define two functions *f* and *g* on positive integer numbers.
You need to process *Q* queries. In each query, you will be given three integers *l*, *r* and *k*. You need to print the number of integers *x*... | ```python
from functools import reduce, lru_cache
max = int(10e6 + 5)
def gen(l, r, k):
for i in range(l, r+1):
yield 1 if g(i) == k else 0
def main():
q = int(input())
for _ in range(q):
l, r, k = (int(x) for x in input().split())
s = sum(gen(l, r, k))
... | 0 | |
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,646,479,486 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 81 | 154 | 0 | u_1 = u_2 = u_3 = u1 = u2 = u3 = 0
for _ in range(int(input())):
u1, u2, u3 = map(int, input().split())
u_1 += u1
u_2 += u2
u_3 += u3
print("YES" if u_1 == u_2 == u_3 == 0 else "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
u_1 = u_2 = u_3 = u1 = u2 = u3 = 0
for _ in range(int(input())):
u1, u2, u3 = map(int, input().split())
u_1 += u1
u_2 += u2
u_3 += u3
print("YES" if u_1 == u_2 == u_3 == 0 else "NO")
``` | 3.9615 |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,692,273,710 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 389 | 21,094,400 | n = int(input())
l = list(map(int, input().split()))
ans = list()
for i in range(n):
min_, max_ = int(), int()
if i == n-1:
min_ = l[i] - l[i-1]
max_ = l[i] - l[0]
else:
min_ = min(abs(l[i] - l[i-1]), abs(l[i] - l[i+1]))
max_ = max(abs(l[i] - l[0]), abs(l[i] - l[-1]... | Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
n = int(input())
l = list(map(int, input().split()))
ans = list()
for i in range(n):
min_, max_ = int(), int()
if i == n-1:
min_ = l[i] - l[i-1]
max_ = l[i] - l[0]
else:
min_ = min(abs(l[i] - l[i-1]), abs(l[i] - l[i+1]))
max_ = max(abs(l[i] - l[0]), abs(l[... | 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,555,478,230 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 0 | num = int(input())
count = 0
ppl = num + 1
y=input()
x = y.split()
for i in range (0,num):
x[i] = int(x[i])
total = sum(x)
for i in range(1,6):
if((total+i) % ppl != 1):
count += 1
print(count)
| 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
num = int(input())
count = 0
ppl = num + 1
y=input()
x = y.split()
for i in range (0,num):
x[i] = int(x[i])
total = sum(x)
for i in range(1,6):
if((total+i) % ppl != 1):
count += 1
print(count)
``` | 3 | |
688 | A | Opponents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Ar... | The first line of the input contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100) — the number of opponents and the number of days, respectively.
The *i*-th of the following *d* lines contains a string of length *n* consisting of characters '0' and '1'. The *j*-th character of this string is '0' if the *j*-th op... | Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents. | [
"2 2\n10\n00\n",
"4 1\n0100\n",
"4 5\n1101\n1111\n0110\n1011\n1111\n"
] | [
"2\n",
"1\n",
"2\n"
] | In the first and the second samples, Arya will beat all present opponents each of the *d* days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4. | 500 | [
{
"input": "2 2\n10\n00",
"output": "2"
},
{
"input": "4 1\n0100",
"output": "1"
},
{
"input": "4 5\n1101\n1111\n0110\n1011\n1111",
"output": "2"
},
{
"input": "3 2\n110\n110",
"output": "2"
},
{
"input": "10 6\n1111111111\n0100110101\n1111111111\n0000011010\n1111... | 1,580,645,391 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 109 | 0 | n,d=map(int,input().split())
m=[]
a=0
for i in range(d):
l=input()[:n]
if "0" in l:
a=a+1
else:
m.append(a)
a=0
if i==d-1:
m.append(a)
print(max(m))
| Title: Opponents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of th... | ```python
n,d=map(int,input().split())
m=[]
a=0
for i in range(d):
l=input()[:n]
if "0" in l:
a=a+1
else:
m.append(a)
a=0
if i==d-1:
m.append(a)
print(max(m))
``` | 3 | |
632 | C | The Smallest String Concatenation | PROGRAMMING | 1,700 | [
"sortings",
"strings"
] | null | null | You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list of strings, output the lexicographically smallest concatenation. | The first line contains integer *n* — the number of strings (1<=≤<=*n*<=≤<=5·104).
Each of the next *n* lines contains one string *a**i* (1<=≤<=|*a**i*|<=≤<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104. | Print the only string *a* — the lexicographically smallest string concatenation. | [
"4\nabba\nabacaba\nbcd\ner\n",
"5\nx\nxx\nxxa\nxxaa\nxxaaa\n",
"3\nc\ncb\ncba\n"
] | [
"abacabaabbabcder\n",
"xxaaaxxaaxxaxxx\n",
"cbacbc\n"
] | none | 0 | [
{
"input": "4\nabba\nabacaba\nbcd\ner",
"output": "abacabaabbabcder"
},
{
"input": "5\nx\nxx\nxxa\nxxaa\nxxaaa",
"output": "xxaaaxxaaxxaxxx"
},
{
"input": "3\nc\ncb\ncba",
"output": "cbacbc"
},
{
"input": "10\naba\nabaaca\naba\nacaaaabbac\nabaacac\nb\ncabbcccaab\nbaacbb\nbcab... | 1,456,849,254 | 4,854 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | x=int(input())
y=list()
for i in range(x):
y.append(input())
y.sort()
z=""
for j in range(x):
z+=y[j]
print(z) | Title: The Smallest String Concatenation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list ... | ```python
x=int(input())
y=list()
for i in range(x):
y.append(input())
y.sort()
z=""
for j in range(x):
z+=y[j]
print(z)
``` | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,664,696,661 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | from math import ceil
def theatreSquare(input):
n = int(input.split(' ')[0])
m = int(input.split(' ')[1])
a = int(input.split(' ')[2])
global nDimensionCount
global mDimensionCount
if a > n:
nDimensionCount = 1
elif a > m:
mDimensionCount = 1
else:
n... | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
from math import ceil
def theatreSquare(input):
n = int(input.split(' ')[0])
m = int(input.split(' ')[1])
a = int(input.split(' ')[2])
global nDimensionCount
global mDimensionCount
if a > n:
nDimensionCount = 1
elif a > m:
mDimensionCount = 1
else:
... | 0 |
1,009 | B | Minimum Ternary String | PROGRAMMING | 1,400 | [
"greedy",
"implementation"
] | null | null | You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For e... | The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). | Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). | [
"100210\n",
"11222121\n",
"20\n"
] | [
"001120\n",
"11112222\n",
"20\n"
] | none | 0 | [
{
"input": "100210",
"output": "001120"
},
{
"input": "11222121",
"output": "11112222"
},
{
"input": "20",
"output": "20"
},
{
"input": "1002",
"output": "0012"
},
{
"input": "10",
"output": "01"
},
{
"input": "000021",
"output": "000012"
},
{
... | 1,617,576,082 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 0 | x = input()
while '21' in x or '10' in x :
x=x.replace('21','12',1)
x=x.replace('10','01',1)
print(x) | Title: Minimum Ternary String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) ... | ```python
x = input()
while '21' in x or '10' in x :
x=x.replace('21','12',1)
x=x.replace('10','01',1)
print(x)
``` | 0 | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,694,405,719 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | x = int(input())
pasos = (x + 4) // 5
print(pasos)
| Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
x = int(input())
pasos = (x + 4) // 5
print(pasos)
``` | 3 | |
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,632,529,461 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 77 | 6,963,200 | # Time complexity: O(n)
# Space complexity: O(n)
# Rationale: For each location with lily, the minimum step to reach is 1 + step
# to reach the previous lily (within the jump range d). To avoid counting for the
# spots without lily, we use a large number for comparison to skip the computation.
n, d = map(int, input().... | 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
# Time complexity: O(n)
# Space complexity: O(n)
# Rationale: For each location with lily, the minimum step to reach is 1 + step
# to reach the previous lily (within the jump range d). To avoid counting for the
# spots without lily, we use a large number for comparison to skip the computation.
n, d = map(int... | 3 | |
1,004 | C | Sonya and Robots | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya wi... | The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row. | Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet. | [
"5\n1 5 4 1 3\n",
"7\n1 2 1 1 1 3 2\n"
] | [
"9\n",
"7\n"
] | In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$).
In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$). | 1,500 | [
{
"input": "5\n1 5 4 1 3",
"output": "9"
},
{
"input": "7\n1 2 1 1 1 3 2",
"output": "7"
},
{
"input": "10\n2 2 4 4 3 1 1 2 3 2",
"output": "14"
},
{
"input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4",
"output": "20"
},
{
"input": "1\n1",
"output": "0"
}
] | 1,531,025,451 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 233 | 12,595,200 | """
http://codeforces.com/problemset/problem/1004/C
"""
input()
arr = map(int, input().split())
hash_ = {}
cnt = 0
for x in arr:
if x not in hash_:
cnt += len(hash_)
hash_[x] = len(hash_)
else:
cnt += len(hash_) - hash_[x]
hash_[x] += len(hash_) - hash_[x]
print(cnt)
| Title: Sonya and Robots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot ... | ```python
"""
http://codeforces.com/problemset/problem/1004/C
"""
input()
arr = map(int, input().split())
hash_ = {}
cnt = 0
for x in arr:
if x not in hash_:
cnt += len(hash_)
hash_[x] = len(hash_)
else:
cnt += len(hash_) - hash_[x]
hash_[x] += len(hash_) - hash_[x]
print(cnt)
`... | 3 |
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.