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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* ... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182... | 1,669,392,988 | 2,147,483,647 | PyPy 3 | OK | TESTS | 76 | 186 | 1,740,800 | n = int(input())
points = []
for _ in range(n):
x, y = list(map(int, input().split(' ')))
points.append((x, y))
seen = set()
def dfs(x, y, tmp):
seen.add((x, y))
tmp.append((x, y))
for nx, ny in points:
if (nx, ny) not in seen and (nx == x or ny == y):
dfs(nx, ny, tmp)
cc = []... | Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha... | ```python
n = int(input())
points = []
for _ in range(n):
x, y = list(map(int, input().split(' ')))
points.append((x, y))
seen = set()
def dfs(x, y, tmp):
seen.add((x, y))
tmp.append((x, y))
for nx, ny in points:
if (nx, ny) not in seen and (nx == x or ny == y):
dfs(nx, ny, tmp... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,590,789,056 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 80 | 248 | 307,200 | import math
n = int(input())
arraylist = []
for i in range(0,n):
current = list(map(int,input().strip().split(" ")))
arraylist.append(current)
def sum (array):
sum = 0
for i in range(0, len(array)):
sum += array[i]
return sum
n = len(arraylist)
sumarr = []
fo... | 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
import math
n = int(input())
arraylist = []
for i in range(0,n):
current = list(map(int,input().strip().split(" ")))
arraylist.append(current)
def sum (array):
sum = 0
for i in range(0, len(array)):
sum += array[i]
return sum
n = len(arraylist)
sumar... | 0 |
631 | A | Interview | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.
We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109).
The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109). | Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. | [
"5\n1 2 4 3 2\n2 3 3 12 1\n",
"10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n"
] | [
"22",
"46"
] | Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation.
In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *... | 500 | [
{
"input": "5\n1 2 4 3 2\n2 3 3 12 1",
"output": "22"
},
{
"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6",
"output": "46"
},
{
"input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 9... | 1,551,131,984 | 284 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 614,400 | n=int(input())
maxf = -9999;
p=input().rstrip().split(' ')
q=input().rstrip().split(' ')
for i in range(0,len(p)):
for j in range(i,len(p)):
y=p[i:j+1]
Y=q[i:j+1]
S=0;
D=0;
F=0;
for k in range(0,len(y)):
S=S|int(y[k])
D=D|int(Y[k])... | Title: Interview
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of... | ```python
n=int(input())
maxf = -9999;
p=input().rstrip().split(' ')
q=input().rstrip().split(' ')
for i in range(0,len(p)):
for j in range(i,len(p)):
y=p[i:j+1]
Y=q[i:j+1]
S=0;
D=0;
F=0;
for k in range(0,len(y)):
S=S|int(y[k])
D=D... | 0 | |
946 | C | String Transformation | PROGRAMMING | 1,300 | [
"greedy",
"strings"
] | null | null | You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.
Your target is to make some number... | The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≤<=|*s*|<=≤<=105) small english letters. | If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes). | [
"aacceeggiikkmmooqqssuuwwyy\n",
"thereisnoanswer\n"
] | [
"abcdefghijklmnopqrstuvwxyz\n",
"-1\n"
] | none | 0 | [
{
"input": "aacceeggiikkmmooqqssuuwwyy",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "thereisnoanswer",
"output": "-1"
},
{
"input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs",
"output": "-1"
},
{
"input": "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaen... | 1,678,873,602 | 2,147,483,647 | PyPy 3 | OK | TESTS | 102 | 93 | 4,198,400 | s=list(input())
i,j=97,0
for c in s:
if c<=chr(i):
s[j]=chr(i);i+=1
if i>122:
print(''.join(s));break
j+=1
else:print(-1) | Title: String Transformation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be rep... | ```python
s=list(input())
i,j=97,0
for c in s:
if c<=chr(i):
s[j]=chr(i);i+=1
if i>122:
print(''.join(s));break
j+=1
else:print(-1)
``` | 3 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,596,622,938 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 218 | 6,963,200 | import sys
def parse_line(line):
line = line.strip().split()
name = line[0]
score = int(line[1])
return name, score
def update_scores(name, score, scores, winner):
if name not in scores:
scores[name] = score
else:
scores[name] += score
if winner == '':
... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
import sys
def parse_line(line):
line = line.strip().split()
name = line[0]
score = int(line[1])
return name, score
def update_scores(name, score, scores, winner):
if name not in scores:
scores[name] = score
else:
scores[name] += score
if winner =... | 0 |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,695,402,575 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 46 | 0 | L = [int(i) for i in input().split()]
s = 0
for i in range(1,L[2]+1):
s+= i * L[0]
if L[1] - s >= 0:
print(0)
else:
print(s-L[1])
| Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
L = [int(i) for i in input().split()]
s = 0
for i in range(1,L[2]+1):
s+= i * L[0]
if L[1] - s >= 0:
print(0)
else:
print(s-L[1])
``` | 3 | |
821 | C | Okabe and Boxes | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"trees"
] | null | null | Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack.
Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the sta... | The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of boxes.
Each of the next 2*n* lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer *x* (1<=≤<=*x*<=≤<=*n*) follows, indicating that Daru should add the box with number *x* to the top of... | Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. | [
"3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n",
"7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n"
] | [
"1\n",
"2\n"
] | In the first sample, Daru should reorder the boxes after adding box 3 to the stack.
In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack. | 1,500 | [
{
"input": "3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove",
"output": "1"
},
{
"input": "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove",
"output": "2"
},
{
"input": "4\nadd 1\nadd 3\nremove\nadd 4\nadd 2\nremove\nremove\nremov... | 1,498,461,013 | 2,147,483,647 | Python 3 | OK | TESTS | 89 | 1,544 | 12,800,000 | # Time : 2017-6-26 14:30
# Auther : Anjone
# URL : http://codeforces.com/contest/821/problem/C
ans = 0
num = 1
stack = []
n = int(input())
for i in range(2*n):
s = input()
if s.find("add") != -1:
stack.append(int(s.split()[1]) )
else:
if len(stack) != 0 and stack[-1] != num:
stack = []
... | Title: Okabe and Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack.
Okabe, being a control freak, gives Daru 2*n* commands: *n* of which a... | ```python
# Time : 2017-6-26 14:30
# Auther : Anjone
# URL : http://codeforces.com/contest/821/problem/C
ans = 0
num = 1
stack = []
n = int(input())
for i in range(2*n):
s = input()
if s.find("add") != -1:
stack.append(int(s.split()[1]) )
else:
if len(stack) != 0 and stack[-1] != num:
stack... | 3 | |
120 | A | Elevator | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n... | The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the... | Print character "R" if the VIP is right-handed or "L" if he is left-handed. | [
"front\n1\n"
] | [
"L\n"
] | none | 0 | [
{
"input": "front\n1",
"output": "L"
},
{
"input": "back\n1",
"output": "R"
},
{
"input": "front\n2",
"output": "R"
},
{
"input": "back\n2",
"output": "L"
}
] | 1,611,767,799 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 122 | 0 | s = input()
n = input()
if s == 'front' and n == '1':
print('L')
elif s == 'back' and n == '2':
print('L')
else:
print('R')
| Title: Elevator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through... | ```python
s = input()
n = input()
if s == 'front' and n == '1':
print('L')
elif s == 'back' and n == '2':
print('L')
else:
print('R')
``` | -1 | |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest in... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000... | 1,649,795,006 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 30 | 0 | a, b = list(map(int, input().split()))
while b % a != 0:
a, b = b, a % b
print(a)
| Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre... | ```python
a, b = list(map(int, input().split()))
while b % a != 0:
a, b = b, a % b
print(a)
``` | 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,684,761,551 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 31 | 0 | import math
m, n, a = [int(x) for x in input().split()]
g = math.ceil(n/a)
j = math.ceil(m/a)
print(g*j) | 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
import math
m, n, a = [int(x) for x in input().split()]
g = math.ceil(n/a)
j = math.ceil(m/a)
print(g*j)
``` | 3.9845 |
0 | none | none | none | 0 | [
"none"
] | null | null | Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*) meaning there is an edge between nodes *u**i* and *v**i*.
The next line contains *n* integer numbers, the *i*-th of them corresponds t... | In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*. | [
"10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n"
] | [
"2\n4\n7\n"
] | none | 0 | [
{
"input": "10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1",
"output": "2\n4\n7"
},
{
"input": "15\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13\n15 14\n0 1 0 0 1 1 1 1 1 1 0 0 0 1 1\n1 1 1 1 0 0 1 1 0 1 0 0 1 1 0",
"output"... | 1,399,826,317 | 3,517 | Python 3 | WRONG_ANSWER | PRETESTS | 1 | 61 | 0 | from collections import deque
n = int(input())
edges = {}
for i in range(n - 1):
v, u = tuple(map(int, input().split()))
if u not in edges:
edges[u] = [v]
else:
edges[u].append(v)
def children(u):
if u not in edges:
return []
return edges[u]
def grandchildren(u):
gc = [... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a... | ```python
from collections import deque
n = int(input())
edges = {}
for i in range(n - 1):
v, u = tuple(map(int, input().split()))
if u not in edges:
edges[u] = [v]
else:
edges[u].append(v)
def children(u):
if u not in edges:
return []
return edges[u]
def grandchildren(u):
... | 0 | |
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output"... | 1,699,701,121 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 62 | 0 | n = int(input())
string1 = 'I hate'
string2 = 'I love'
output = ''
flag = True
for i in range(n):
if i == n - 1:
flag = False
if i % 2 == 0 and flag:
output += string1 + ' that '
elif i % 2 == 1 and flag:
output += string2 + ' that '
elif i % 2 == 0:
output +... | Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and... | ```python
n = int(input())
string1 = 'I hate'
string2 = 'I love'
output = ''
flag = True
for i in range(n):
if i == n - 1:
flag = False
if i % 2 == 0 and flag:
output += string1 + ' that '
elif i % 2 == 1 and flag:
output += string2 + ' that '
elif i % 2 == 0:
... | 3 | |
712 | B | Memory and Trident | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion:
- An 'L' indicates he should move one unit left. - An 'R' indicates he should move one unit right. - A 'U' indicates he should move one unit up. - A 'D' indicates he should move... | The first and only line contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) — the instructions Memory is given. | If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1. | [
"RRU\n",
"UDUR\n",
"RUUR\n"
] | [
"-1\n",
"1\n",
"2\n"
] | In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.
In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change *s* to "LDUR". This string uses ... | 1,000 | [
{
"input": "RRU",
"output": "-1"
},
{
"input": "UDUR",
"output": "1"
},
{
"input": "RUUR",
"output": "2"
},
{
"input": "DDDD",
"output": "2"
},
{
"input": "RRRR",
"output": "2"
},
{
"input": "RRRUUD",
"output": "2"
},
{
"input": "UDURLRDURL... | 1,609,682,431 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 108 | 0 | s=input()
if len(s)%2==1:
print(-1)
else:
x=0
y=0
for i in s:
if i=="R":
x+=1
elif i=="l":
x-=1
elif i=="U":
y+=1
else:
y-=1
print((abs(x)+abs(y))//2) | Title: Memory and Trident
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion:
- An 'L' indicates he should move one unit left. - An 'R' indicates he shou... | ```python
s=input()
if len(s)%2==1:
print(-1)
else:
x=0
y=0
for i in s:
if i=="R":
x+=1
elif i=="l":
x-=1
elif i=="U":
y+=1
else:
y-=1
print((abs(x)+abs(y))//2)
``` | 0 | |
454 | B | Little Pony and Sort by Shift | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | [
"2\n2 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"1\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 3 2",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "6\n3 4 5 6 3 2",
"output": "-1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n1 1 2 1 1",
"output": "2"
}... | 1,657,142,476 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 156 | 9,830,400 | #n,t=map
from cmath import sqrt
from math import ceil
n=int(input())
a = list(map(int,input().strip().split()))[:n]
b=a
b=sorted(b)
s,c=0,0
last=n-1
for i in range(0,n):
if a==b and c==0:
s=1
break
a[0],a[last]=a[last],a[0]
last-=1
if a==b:
s=1
c+=... | Title: Little Pony and Sort by Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. ... | ```python
#n,t=map
from cmath import sqrt
from math import ceil
n=int(input())
a = list(map(int,input().strip().split()))[:n]
b=a
b=sorted(b)
s,c=0,0
last=n-1
for i in range(0,n):
if a==b and c==0:
s=1
break
a[0],a[last]=a[last],a[0]
last-=1
if a==b:
s=1
... | 0 | |
515 | A | Drazil and Date | PROGRAMMING | 1,000 | [
"math"
] | null | null | Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to ... | You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line. | If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes).
Otherwise, print "Yes". | [
"5 5 11\n",
"10 15 25\n",
"0 5 1\n",
"0 0 2\n"
] | [
"No\n",
"Yes\n",
"No\n",
"Yes\n"
] | In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "5 5 11",
"output": "No"
},
{
"input": "10 15 25",
"output": "Yes"
},
{
"input": "0 5 1",
"output": "No"
},
{
"input": "0 0 2",
"output": "Yes"
},
{
"input": "999999999 999999999 2000000000",
"output": "Yes"
},
{
"input": "-606037695 9983201... | 1,687,312,973 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 46 | 0 | a, b, s = (int(i) for i in input().split())
res = "YES" if s >= a + b and (a + b) & 1 == s & 1 else "NO"
print(res)
| Title: Drazil and Date
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit ... | ```python
a, b, s = (int(i) for i in input().split())
res = "YES" if s >= a + b and (a + b) & 1 == s & 1 else "NO"
print(res)
``` | 0 | |
691 | A | Fashion in Berland | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fast... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | [
"3\n1 0 1\n",
"3\n1 0 0\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 0 1",
"output": "YES"
},
{
"input": "3\n1 0 0",
"output": "NO"
},
{
"input": "3\n1 1 0",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n0 0 1",
"output": "NO"
},
{
"input": "3\n0 0 0",
"output": "NO"
}... | 1,471,303,706 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 77 | 4,608,000 | n=int(input())
bs=input()
def f(n,bs):
if (n == 1):
if (bs == "0"):
print("NO")
else:
print("YES")
else:
s = 0
for a in bs[::2]:
if (a == "0"):
s += 1
if (s > 1):
print("NO")
... | Title: Fashion in Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened,... | ```python
n=int(input())
bs=input()
def f(n,bs):
if (n == 1):
if (bs == "0"):
print("NO")
else:
print("YES")
else:
s = 0
for a in bs[::2]:
if (a == "0"):
s += 1
if (s > 1):
print("NO")... | 3 | |
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,671,822,594 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 92 | 4,403,200 | _ = int(input())
students = input()
rec = {'1':[],'2':[],'3':[]}
for c in range(len(students)):
if students[c] == ' ': continue
rec[students[c]].append(c//2+1)
teams = len(min(rec.values(),key=lambda x : len(x)))
print(teams)
for i in range(teams):
print(rec['1'][i],rec['2'][i],rec['3'][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
_ = int(input())
students = input()
rec = {'1':[],'2':[],'3':[]}
for c in range(len(students)):
if students[c] == ' ': continue
rec[students[c]].append(c//2+1)
teams = len(min(rec.values(),key=lambda x : len(x)))
print(teams)
for i in range(teams):
print(rec['1'][i],rec['2'][i],rec['3'][i])
``` | 3 | |
960 | B | Minimize the error | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1.
Output the min... | The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively.
Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-... | Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. | [
"2 0 0\n1 2\n2 3\n",
"2 1 0\n1 2\n2 2\n",
"2 5 7\n3 4\n14 4\n"
] | [
"2",
"0",
"1"
] | In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2.
In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we... | 1,000 | [
{
"input": "2 0 0\n1 2\n2 3",
"output": "2"
},
{
"input": "2 1 0\n1 2\n2 2",
"output": "0"
},
{
"input": "2 5 7\n3 4\n14 4",
"output": "1"
},
{
"input": "2 0 1\n1 2\n2 2",
"output": "0"
},
{
"input": "2 1 1\n0 0\n1 1",
"output": "0"
},
{
"input": "5 5 ... | 1,696,179,134 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n, k1, k2=map(int, input(). split())
a=[int(x) for x in map(int, input().split())]
b=[int(x) for x in map(int, input().split())]
k=k1+k2
s=0
while k>0:
for i in range(n):
if a[i]<b[i]:
a[i]+=1
k-=1
elif a[i]>b[i]:
a[i]-=1
k-=1
else... | Title: Minimize the error
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one ... | ```python
n, k1, k2=map(int, input(). split())
a=[int(x) for x in map(int, input().split())]
b=[int(x) for x in map(int, input().split())]
k=k1+k2
s=0
while k>0:
for i in range(n):
if a[i]<b[i]:
a[i]+=1
k-=1
elif a[i]>b[i]:
a[i]-=1
k-=1
... | 0 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,693,981,012 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | k,n,w = map(int, input().split())
print( ((w*(w+1)) // 2) * k - n) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
k,n,w = map(int, input().split())
print( ((w*(w+1)) // 2) * k - n)
``` | 0 | |
165 | A | Supercentral Point | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*):
- point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=><=*x* and *y*'... | The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one spac... | Print the only number — the number of supercentral points of the given set. | [
"8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n",
"5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n"
] | [
"2\n",
"1\n"
] | In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0). | 500 | [
{
"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3",
"output": "2"
},
{
"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0",
"output": "1"
},
{
"input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1",
"output": "1"
},
{
"input": "25\n-651 897\n... | 1,609,669,652 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 280 | 307,200 | def right_count(a, arr):
c = 0
for items in arr:
if items[0] > a[0] and items[1] == a[1]:
c += 1
return c
def left_count(a, arr):
c = 0
for items in arr:
if items[0] < a[0] and items[1] == a[1]:
c += 1
return c
def lower_count(a, arr):
... | Title: Supercentral Point
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the give... | ```python
def right_count(a, arr):
c = 0
for items in arr:
if items[0] > a[0] and items[1] == a[1]:
c += 1
return c
def left_count(a, arr):
c = 0
for items in arr:
if items[0] < a[0] and items[1] == a[1]:
c += 1
return c
def lower_count... | 3 | |
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,656,843,041 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 109 | 512,000 | a = []
for i in range(1,10): a.append(int('4' * i))
for i in range(2**9):b=bin(i)[2:];b=b.replace('1','4');b=b.replace('0','7');a.append(int(b))
for i in range(2**9):b=bin(i)[2:];b=b.replace('0','4');b=b.replace('1','7');a.append(int(b))
a=sorted(list(set(a)));print(a.index(int(input()))+1)
| Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
a = []
for i in range(1,10): a.append(int('4' * i))
for i in range(2**9):b=bin(i)[2:];b=b.replace('1','4');b=b.replace('0','7');a.append(int(b))
for i in range(2**9):b=bin(i)[2:];b=b.replace('0','4');b=b.replace('1','7');a.append(int(b))
a=sorted(list(set(a)));print(a.index(int(input()))+1)
``` | 3 | |
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
... | 1,664,826,655 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,867,200 | from sympy import N
def solve(n, nums):
nums.sort()
for _ in range(2):
if nums[-1]-nums[-2] > nums[1] - nums[0]:
nums.pop()
else:
nums.pop(0)
return sum(y-x for x,y in zip(nums,nums[1:]))
n = int(input())
nums = list(map(int,input().split()))
print(so... | Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they hav... | ```python
from sympy import N
def solve(n, nums):
nums.sort()
for _ in range(2):
if nums[-1]-nums[-2] > nums[1] - nums[0]:
nums.pop()
else:
nums.pop(0)
return sum(y-x for x,y in zip(nums,nums[1:]))
n = int(input())
nums = list(map(int,input().split()))... | -1 | |
330 | B | Road Construction | PROGRAMMING | 1,300 | [
"constructive algorithms",
"graphs"
] | null | null | A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two... | The first line consists of two integers *n* and *m* .
Then *m* lines follow, each consisting of two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*), which means that it is not possible to construct a road connecting cities *a**i* and *b**i*. Consider the cities are numbered from 1 to *n*.... | You should print an integer *s*: the minimum number of roads that should be constructed, in the first line. Then *s* lines should follow, each consisting of two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*), which means that a road should be constructed between cities *a**i* and *b**i*.... | [
"4 1\n1 3\n"
] | [
"3\n1 2\n4 2\n2 3\n"
] | This is one possible solution of the example:
These are examples of wrong solutions: | 1,000 | [
{
"input": "4 1\n1 3",
"output": "3\n1 2\n4 2\n2 3"
},
{
"input": "1000 0",
"output": "999\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 ... | 1,592,040,331 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 248 | 204,800 | f=lambda: map(int, input().split(' '))
n, m =f()
print(n-1)
if(m==0):
for j in range(1,n):
print(j,' ', j+1)
else:
s=set()
for j in range(m):
s=set(f()).union(s)
#print(s)
ss = set([i for i in range(1, n+1)]).difference(s)
#print(ss)
kp = list(ss)[0]
for j in range(1, n+1):
if(j!=k... | Title: Road Construction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constru... | ```python
f=lambda: map(int, input().split(' '))
n, m =f()
print(n-1)
if(m==0):
for j in range(1,n):
print(j,' ', j+1)
else:
s=set()
for j in range(m):
s=set(f()).union(s)
#print(s)
ss = set([i for i in range(1, n+1)]).difference(s)
#print(ss)
kp = list(ss)[0]
for j in range(1, n+1):
... | 0 | |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,698,678,719 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n = list(map(int, input().split(' ')))
total = 0
for i in n:
total+=i
print(total//3) | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
n = list(map(int, input().split(' ')))
total = 0
for i in n:
total+=i
print(total//3)
``` | 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,579,527,278 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 310 | 0 | import math
a=input("")
count=0
for i in a:
if(i.isupper()):
count+=1
if(count>(len(a)-count)):
print(a.upper())
else:
print(a.lower())
| 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
import math
a=input("")
count=0
for i in a:
if(i.isupper()):
count+=1
if(count>(len(a)-count)):
print(a.upper())
else:
print(a.lower())
``` | 3.9225 |
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each frie... | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer — the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
... | 1,694,079,145 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 92 | 0 | n, k, l, c, d, p, nl, np = list(map(int, input().split()))
milk=k*l
toast=milk//n
lime=c*d
salt=p//np
min_value=min(toast,lime,salt)
value=min_value//n
print(value)
| Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut... | ```python
n, k, l, c, d, p, nl, np = list(map(int, input().split()))
milk=k*l
toast=milk//n
lime=c*d
salt=p//np
min_value=min(toast,lime,salt)
value=min_value//n
print(value)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | This is an interactive problem. Refer to the Interaction section below for better understanding.
Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight.
Initially, Ithea puts *n* clear sheets of paper in a line. They are numbered from 1 to *n* from left to right.
This game wil... | The first line contains 3 integers *n*,<=*m* and *c* (, means rounded up) — the number of sheets, the number of rounds and the largest possible number Ithea can give to Chtholly respectively. The remaining parts of input are given throughout the interaction process. | none | [
"2 4 4\n2\n1\n3\n"
] | [
"1\n2\n2\n"
] | In the example, Chtholly initially knew there were 2 sheets, 4 rounds and each number was between 1 and 4. She then received a 2 and decided to write it in the 1st sheet. Then she received a 1 and wrote it in the 2nd sheet. At last, she received a 3 and replaced 1 with 3 in the 2nd sheet. At this time all the sheets we... | 0 | [
{
"input": "2 4 4\n2\n1\n3\n4",
"output": "3"
},
{
"input": "2 2 2\n1\n2",
"output": "2"
},
{
"input": "3 6 3\n1\n2\n1\n3\n1\n3",
"output": "3"
},
{
"input": "4 8 4\n4\n4\n4\n4\n4\n4\n4\n4",
"output": "4"
},
{
"input": "10 120 15\n6\n11\n9\n11\n3\n12\n11\n12\n2\n8... | 1,589,371,206 | 5,106 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import sys
n, m, c = map(int, input().split())
l = [0 for _ in range(n)]
for j in range(m):
p = int(input())
if p>int(c/2):
i = n-1
while (i>=0 and p<=l[i]):
i-=1
l[i] = p
else:
i = 0
while (i<n and p>=l[i]):
i+=1
l[i] = p
print(i+1)
# print(l)
sy... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem. Refer to the Interaction section below for better understanding.
Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight.
Initially, Ithea puts *n* clear she... | ```python
import sys
n, m, c = map(int, input().split())
l = [0 for _ in range(n)]
for j in range(m):
p = int(input())
if p>int(c/2):
i = n-1
while (i>=0 and p<=l[i]):
i-=1
l[i] = p
else:
i = 0
while (i<n and p>=l[i]):
i+=1
l[i] = p
print(i+1)
# prin... | -1 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,694,606,722 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | m = ''
for i in range(int(input()):
m = input()
if len(m) > 10:
print(m[0] + str(len(m)) + m[-1]
continue
print(m) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
m = ''
for i in range(int(input()):
m = input()
if len(m) > 10:
print(m[0] + str(len(m)) + m[-1]
continue
print(m)
``` | -1 |
870 | A | Search for Pretty Integers | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2... | Print the smallest pretty integer. | [
"2 3\n4 2\n5 7 6\n",
"8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n"
] | [
"25\n",
"1\n"
] | In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among t... | 500 | [
{
"input": "2 3\n4 2\n5 7 6",
"output": "25"
},
{
"input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n9\n1",
"output": "19"
},
{
"input": "9 1\n5 4 2 3 6 1 7 9 8\n9",
"output": "9"
},
{
"input": "5 3\n7 2 5 8 6\n3 1 9",
"output"... | 1,617,212,475 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | // Problem: A. Search for Pretty Integers
// Contest: Codeforces - Technocup 2018 - Elimination Round 2
// URL: https://codeforces.com/problemset/problem/870/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
#defi... | Title: Search for Pretty Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the sm... | ```python
// Problem: A. Search for Pretty Integers
// Contest: Codeforces - Technocup 2018 - Elimination Round 2
// URL: https://codeforces.com/problemset/problem/870/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace s... | -1 | |
701 | A | Cards | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards ... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card. | Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print... | [
"6\n1 5 7 4 4 3\n",
"4\n10 10 10 10\n"
] | [
"1 3\n6 2\n4 5\n",
"1 2\n3 4\n"
] | In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable. | 500 | [
{
"input": "6\n1 5 7 4 4 3",
"output": "1 3\n6 2\n4 5"
},
{
"input": "4\n10 10 10 10",
"output": "1 4\n2 3"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,564,368,981 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 280 | 1,638,400 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
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 [int(x) for x in sys.stdin.readline().split()]
def LI_(): ... | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one p... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
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 [int(x) for x in sys.stdin.readline().split()]
d... | 3 | |
549 | G | Happy Line | PROGRAMMING | 2,200 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of *n* Berland residents lined up in front of the ice cream stall. We know that each of them has a certain amount of berland dollars with them. The residents of Berland are nice people,... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of residents who stand in the line.
The second line contains *n* space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=109), where *a**i* is the number of Berland dollars of a man standing on the *i*-th position in the line. The positions are number... | If it is impossible to make all the residents happy, print ":(" without the quotes. Otherwise, print in the single line *n* space-separated integers, the *i*-th of them must be equal to the number of money of the person on position *i* in the new line. If there are multiple answers, print any of them. | [
"2\n11 8\n",
"5\n10 9 7 10 6\n",
"3\n12 3 3\n"
] | [
"9 10 ",
":(\n",
"4 4 10 "
] | In the first sample two residents should swap places, after that the first resident has 10 dollars and he is at the head of the line and the second resident will have 9 coins and he will be at the end of the line.
In the second sample it is impossible to achieve the desired result.
In the third sample the first pers... | 1,500 | [
{
"input": "2\n11 8",
"output": "9 10 "
},
{
"input": "5\n10 9 7 10 6",
"output": ":("
},
{
"input": "3\n12 3 3",
"output": "4 4 10 "
},
{
"input": "4\n7 3 9 10",
"output": "4 6 9 10 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "5\n15 5 8 6 3",... | 1,689,429,450 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689429450.4168031")# 1689429450.4168234 | Title: Happy Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of *n* Berland residents lined up in front of the ice cream stall. We know that each of t... | ```python
print("_RANDOM_GUESS_1689429450.4168031")# 1689429450.4168234
``` | 0 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,636,028,937 | 2,147,483,647 | Python 3 | OK | TESTS | 3 | 92 | 4,198,400 | def main() -> None:
n = int(input())
for _ in range(n):
t = int(input())
n = 360 / (180 - t)
print("YES" if n.is_integer() else "NO")
if __name__ == '__main__':
main()
| Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can... | ```python
def main() -> None:
n = int(input())
for _ in range(n):
t = int(input())
n = 360 / (180 - t)
print("YES" if n.is_integer() else "NO")
if __name__ == '__main__':
main()
``` | 3 | |
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen... | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"o... | 1,690,113,974 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n=int(input())
l=[1,5,10,20,100]
b=0
for i in l:
b += n // i
n %= i
print(b) | Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$... | ```python
n=int(input())
l=[1,5,10,20,100]
b=0
for i in l:
b += n // i
n %= i
print(b)
``` | 0 | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,459,344,248 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 1,126,400 | from collections import deque
n,d=[int(i) for i in input().split()]
Deq=[int(j) for j in input().split()]
cnt=0
for i in range(0,n-2):
for j in range(n-1,i+1,-1):
if Deq[j]-Deq[i]<=d :
cnt+=int((j-i)*(j-i-1)/2)
break
print(cnt) | Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
from collections import deque
n,d=[int(i) for i in input().split()]
Deq=[int(j) for j in input().split()]
cnt=0
for i in range(0,n-2):
for j in range(n-1,i+1,-1):
if Deq[j]-Deq[i]<=d :
cnt+=int((j-i)*(j-i-1)/2)
break
print(cnt)
``` | 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,684,385,774 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n,m,k = map(int,input().split())
print(1 if n==m==k else ((n + k-(n%k)) * (m +k-(m%k)))//(k**2)) | 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
n,m,k = map(int,input().split())
print(1 if n==m==k else ((n + k-(n%k)) * (m +k-(m%k)))//(k**2))
``` | 0 |
863 | A | Quasi-palindrome | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to str... | The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes. | Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes). | [
"131\n",
"320\n",
"2010200\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 0 | [
{
"input": "131",
"output": "YES"
},
{
"input": "320",
"output": "NO"
},
{
"input": "2010200",
"output": "YES"
},
{
"input": "1",
"output": "YES"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "999999999",
"output": "YES"
},
{
"i... | 1,697,909,894 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | #O(n)
x = input() #O(1)
if x == x[::-1]: #O(1) #O(n)
print("Yes")
else:
print("No")
| Title: Quasi-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from righ... | ```python
#O(n)
x = input() #O(1)
if x == x[::-1]: #O(1) #O(n)
print("Yes")
else:
print("No")
``` | 0 | |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,610,274,078 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 154 | 307,200 | n = int(input())
x,y,z = 0,0,0
l = list(map(int, input().split()))
x = sum(l[0:len(l):3])
y = sum(l[1:len(l):3])
z = sum(l[2:len(l):3])
if x == max(x,y,z):
print("chest")
elif y == max(x,y,z):
print("biceps")
elif z == max(x,y,z):
print("back")
| Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
n = int(input())
x,y,z = 0,0,0
l = list(map(int, input().split()))
x = sum(l[0:len(l):3])
y = sum(l[1:len(l):3])
z = sum(l[2:len(l):3])
if x == max(x,y,z):
print("chest")
elif y == max(x,y,z):
print("biceps")
elif z == max(x,y,z):
print("back")
``` | 3 | |
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1... | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"outpu... | 1,606,751,236 | 2,147,483,647 | PyPy 3 | OK | TESTS | 95 | 1,715 | 28,979,200 |
t=[]
f={}
n=int(input())
for i in range(n):
a = input()
t.append(a)
for j in range(n-1,-1,-1):
if t[j] not in f:
print(t[j])
f[t[j]]=1
| Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The rela... | ```python
t=[]
f={}
n=int(input())
for i in range(n):
a = input()
t.append(a)
for j in range(n-1,-1,-1):
if t[j] not in f:
print(t[j])
f[t[j]]=1
``` | 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,646,054,890 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 31 | 0 |
n,m = map(int,input().split())
max = 0
for i in range(n):
a = list(map(int,input().split()))
if min(a)>max:
max = min(a)
print(max) | 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())
max = 0
for i in range(n):
a = list(map(int,input().split()))
if min(a)>max:
max = min(a)
print(max)
``` | 3 | |
91 | B | Queue | PROGRAMMING | 1,500 | [
"binary search",
"data structures"
] | B. Queue | 2 | 256 | There are *n* walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the *n*-th walrus stands at the beginning of the queue. The *i*-th walrus has the age equal to *a**i*.
The *i*-th walrus becomes displeased if there's a younger... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105) — the number of walruses in the queue. The second line contains integers *a**i* (1<=≤<=*a**i*<=≤<=109).
Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly youn... | Print *n* numbers: if the *i*-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the *i*-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | [
"6\n10 8 5 3 50 45\n",
"7\n10 4 6 3 2 8 15\n",
"5\n10 3 1 10 11\n"
] | [
"2 1 0 -1 0 -1 ",
"4 2 1 0 -1 -1 -1 ",
"1 0 -1 -1 -1 "
] | none | 1,000 | [
{
"input": "6\n10 8 5 3 50 45",
"output": "2 1 0 -1 0 -1 "
},
{
"input": "7\n10 4 6 3 2 8 15",
"output": "4 2 1 0 -1 -1 -1 "
},
{
"input": "5\n10 3 1 10 11",
"output": "1 0 -1 -1 -1 "
},
{
"input": "13\n18 9 8 9 23 20 18 18 33 25 31 37 36",
"output": "2 0 -1 -1 2 1 -1 -1 ... | 1,598,550,755 | 2,147,483,647 | PyPy 3 | OK | TESTS | 61 | 624 | 13,312,000 | n=int(input())
a=list(map(int,input().split()))
m=[0]*n
for i in range(n-1,-1,-1):
if(i==n-1):
m[i]=a[i]
else:
m[i]=min(a[i],m[i+1])
res=[0 for i in range(n)]
for i in range(n):
left=i+1
right=n-1
ans=-1
while(left<=right):
mid=left+(right-left)//2
... | Title: Queue
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the *n*-th walrus stands at the beginning of the queue. The *i*-th walrus ... | ```python
n=int(input())
a=list(map(int,input().split()))
m=[0]*n
for i in range(n-1,-1,-1):
if(i==n-1):
m[i]=a[i]
else:
m[i]=min(a[i],m[i+1])
res=[0 for i in range(n)]
for i in range(n):
left=i+1
right=n-1
ans=-1
while(left<=right):
mid=left+(right-left)//2... | 3.819204 |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,691,765,236 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = int(input().strip()
prev = ""
output = 0
for x in range(n):
current = input().strip()
if current != prev:
output+=1
prev=current
print(output)
| Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
n = int(input().strip()
prev = ""
output = 0
for x in range(n):
current = input().strip()
if current != prev:
output+=1
prev=current
print(output)
``` | -1 | |
721 | A | One-dimensional Japanese Crossword | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers repr... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). | The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. | [
"3\nBBW\n",
"5\nBWBWB\n",
"4\nWWWW\n",
"4\nBBBB\n",
"13\nWBBBBWWBWBBBW\n"
] | [
"1\n2 ",
"3\n1 1 1 ",
"0\n",
"1\n4 ",
"3\n4 1 3 "
] | The last sample case correspond to the picture in the statement. | 500 | [
{
"input": "3\nBBW",
"output": "1\n2 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "4\nWWWW",
"output": "0"
},
{
"input": "4\nBBBB",
"output": "1\n4 "
},
{
"input": "13\nWBBBBWWBWBBBW",
"output": "3\n4 1 3 "
},
{
"input": "1\nB",
... | 1,618,886,055 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | s = input()
l = input()
c = 0
for i in l:
if i == "B":
c+=1
else:
print(c)
c=0
| Title: One-dimensional Japanese Crossword
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the... | ```python
s = input()
l = input()
c = 0
for i in l:
if i == "B":
c+=1
else:
print(c)
c=0
``` | 0 | |
660 | C | Hard Process | PROGRAMMING | 1,600 | [
"binary search",
"dp",
"two pointers"
] | null | null | You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*). | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*. | On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones.
On the second line print *n* integers *a**j* — the elements of the array *a* after the changes.
If there are multiple answers, you can print any one of them. | [
"7 1\n1 0 0 1 1 0 1\n",
"10 2\n1 0 0 1 0 1 0 1 0 1\n"
] | [
"4\n1 0 0 1 1 1 1\n",
"5\n1 0 0 1 1 1 1 1 0 1\n"
] | none | 0 | [
{
"input": "7 1\n1 0 0 1 1 0 1",
"output": "4\n1 0 0 1 1 1 1"
},
{
"input": "10 2\n1 0 0 1 0 1 0 1 0 1",
"output": "5\n1 0 0 1 1 1 1 1 0 1"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "7 0\n0 1 0 0 0 1 0",
"o... | 1,599,823,139 | 1,439 | PyPy 3 | OK | TESTS | 38 | 249 | 26,419,200 | import sys
n, k = map(int, sys.stdin.buffer.readline().split())
a = [0] + list(map(int, sys.stdin.buffer.readline().split()))
zero = [0]*(n+1)
for i in range(1, n+1):
zero[i] = zero[i-1] + (1 if a[i] == 0 else 0)
def solve(x):
for i in range(x, n+1):
if zero[i] - zero[i-x] <= k:
... | Title: Hard Process
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can ch... | ```python
import sys
n, k = map(int, sys.stdin.buffer.readline().split())
a = [0] + list(map(int, sys.stdin.buffer.readline().split()))
zero = [0]*(n+1)
for i in range(1, n+1):
zero[i] = zero[i-1] + (1 if a[i] == 0 else 0)
def solve(x):
for i in range(x, n+1):
if zero[i] - zero[i-x] <= k:
... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,635,206,722 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 122 | 4,505,600 | n=int(input())
a,b,c=0,0,0
for i in range(n):
l=list(map(int,input().split()))
a+=l[0]
b+=l[1]
c+=l[2]
if a==0 and b==0 and c==0:
print('YES')
else:
print('NO') | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n=int(input())
a,b,c=0,0,0
for i in range(n):
l=list(map(int,input().split()))
a+=l[0]
b+=l[1]
c+=l[2]
if a==0 and b==0 and c==0:
print('YES')
else:
print('NO')
``` | 3.961108 |
934 | A | A Compatible Pair | PROGRAMMING | 1,400 | [
"brute force",
"games"
] | null | null | Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big B... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109. | Print a single integer — the brightness of the chosen pair. | [
"2 2\n20 18\n2 14\n",
"5 3\n-1 0 1 2 3\n-1 0 1\n"
] | [
"252\n",
"2\n"
] | In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself. | 500 | [
{
"input": "2 2\n20 18\n2 14",
"output": "252"
},
{
"input": "5 3\n-1 0 1 2 3\n-1 0 1",
"output": "2"
},
{
"input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7",
"output": "70"
},
{
"input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 ... | 1,521,117,744 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 124 | 5,632,000 | m,n=map(int,input().split())
A=input()
a=A.split()
B=input()
b=B.split()
c=[]
d=0
for i in range(0,m):
for j in range(0,n):
d=int(a[i])*int(b[j])
c.append(d)
c.sort()
print(c[-2]) | Title: A Compatible Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cr... | ```python
m,n=map(int,input().split())
A=input()
a=A.split()
B=input()
b=B.split()
c=[]
d=0
for i in range(0,m):
for j in range(0,n):
d=int(a[i])*int(b[j])
c.append(d)
c.sort()
print(c[-2])
``` | 0 | |
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,697,779,846 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | n=int(input())
lst=list(map(int,input().split()))
m=int(input())
lstm=list(map(int,input().split()))
dictv={}
dictp={}
for i in lstm:
if(i not in dictv):
for j in range(n):
if(lst[j]==i):
dictv[i]=j+1
dictp[i]=n-j
else:
dictv[i]=2*dictv[i]... | 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
n=int(input())
lst=list(map(int,input().split()))
m=int(input())
lstm=list(map(int,input().split()))
dictv={}
dictp={}
for i in lstm:
if(i not in dictv):
for j in range(n):
if(lst[j]==i):
dictv[i]=j+1
dictp[i]=n-j
else:
dictv[i]=... | 0 | |
814 | A | An abandoned sentiment from past | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"implementation",
"sortings"
] | null | null | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t... | The first line of input contains two space-separated positive integers *n* (2<=≤<=*n*<=≤<=100) and *k* (1<=≤<=*k*<=≤<=*n*) — the lengths of sequence *a* and *b* respectively.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=200) — Hitagi's broken sequence with exactly ... | Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise. | [
"4 2\n11 0 0 14\n5 4\n",
"6 1\n2 3 0 8 9 10\n5\n",
"4 1\n8 94 0 4\n89\n",
"7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n"
] | In the first sample:
- Sequence *a* is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulti... | 500 | [
{
"input": "4 2\n11 0 0 14\n5 4",
"output": "Yes"
},
{
"input": "6 1\n2 3 0 8 9 10\n5",
"output": "No"
},
{
"input": "4 1\n8 94 0 4\n89",
"output": "Yes"
},
{
"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7",
"output": "Yes"
},
{
"input": "40 1\n23 26 27 28 31 35 38 4... | 1,499,892,387 | 2,147,483,647 | Python 3 | OK | TESTS | 96 | 77 | 5,529,600 | n, k = list(map(int, input().split()))
a = input()
b = input().split()
if len(set(b))>1:
print("YES")
else:
b = list(map(int, b))
new_a = list(map(int, a.split()))
c = 0
for i in range(len(new_a)):
if new_a[i] == 0:
new_a[i] = b[c]
c += 1
old_a = list... | Title: An abandoned sentiment from past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of t... | ```python
n, k = list(map(int, input().split()))
a = input()
b = input().split()
if len(set(b))>1:
print("YES")
else:
b = list(map(int, b))
new_a = list(map(int, a.split()))
c = 0
for i in range(len(new_a)):
if new_a[i] == 0:
new_a[i] = b[c]
c += 1
ol... | 3 | |
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,624,197,408 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 77 | 0 | n1 = int(input(), 2)
n2 = int(input(), 2)
print(bin(n1^n2).split("b")[1]) | 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
n1 = int(input(), 2)
n2 = int(input(), 2)
print(bin(n1^n2).split("b")[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,652,101,300 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | y, k, n = map(int,input().split())
l = range((k - y) % k or k, n - y + 1, k) or -1
print(*l) | 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())
l = range((k - y) % k or k, n - y + 1, k) or -1
print(*l)
``` | -1 | |
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-s... | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"inpu... | 1,690,782,369 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | x=input()
y=['H','Q','9']
for i in y:
if i in x:
print("Yes")
else:
print("no") | Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in... | ```python
x=input()
y=['H','Q','9']
for i in y:
if i in x:
print("Yes")
else:
print("no")
``` | 0 | |
596 | B | Wilbur and Array | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input.
The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109). | Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*. | [
"5\n1 2 3 4 5\n",
"4\n1 2 2 1\n"
] | [
"5",
"3"
] | In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes.
In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1. | 1,000 | [
{
"input": "5\n1 2 3 4 5",
"output": "5"
},
{
"input": "4\n1 2 2 1",
"output": "3"
},
{
"input": "3\n1 2 4",
"output": "4"
},
{
"input": "6\n1 2 3 6 5 4",
"output": "8"
},
{
"input": "10\n2 1 4 3 6 5 8 7 10 9",
"output": "19"
},
{
"input": "7\n12 6 12 ... | 1,558,699,774 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | n = int(input())
x = list(map(int, input().split()))
total = 0
for i in range(len(x)):
total += abs(x[i] - total)
print(total) | Title: Wilbur and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+... | ```python
n = int(input())
x = list(map(int, input().split()))
total = 0
for i in range(len(x)):
total += abs(x[i] - total)
print(total)
``` | 0 | |
75 | B | Facetook Priority Wall | PROGRAMMING | 1,500 | [
"expression parsing",
"implementation",
"strings"
] | B. Facetook Priority Wall | 2 | 256 | Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described).
This priority factor will be affected by three types of actions:
- 1. "*X* posted on *Y*'s wall... | The first line contains your name. The second line contains an integer *n*, which is the number of actions (1<=≤<=*n*<=≤<=100). Then *n* lines follow, it is guaranteed that each one contains exactly 1 action in the format given above. There is exactly one space between each two words in a line, and there are no extra s... | Print *m* lines, where *m* is the number of distinct names in the input (excluding yourself). Each line should contain just 1 name. The names should be sorted according to the priority factor with you in the descending order (the highest priority factor should come first). If two or more names have the same priority fa... | [
"ahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post\n",
"aba\n1\nlikes likes posted's post\n"
] | [
"fatma\nmona\n",
"likes\nposted\n"
] | none | 1,000 | [
{
"input": "ahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post",
"output": "fatma\nmona"
},
{
"input": "aba\n1\nlikes likes posted's post",
"output": "likes\nposted"
},
{
"input": "nu\n5\ng commented on pwyndmh's post\nqv posted on g's wall\n... | 1,651,139,202 | 42 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | def input_string(name: str) -> (str, int):
s = input().split(" ")
if s[1] == 'posted':
score = 15
elif s[1] == 'commented':
score = 10
else:
score = 5
if s[0] != name:
return s[0], score
else:
if score > 5:
return s[3].replace("'s",... | Title: Facetook Priority Wall
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be describ... | ```python
def input_string(name: str) -> (str, int):
s = input().split(" ")
if s[1] == 'posted':
score = 15
elif s[1] == 'commented':
score = 10
else:
score = 5
if s[0] != name:
return s[0], score
else:
if score > 5:
return s[3].rep... | 0 |
476 | A | Dreamoon and Stairs | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? | The single line contains two space separated integers *n*, *m* (0<=<<=*n*<=≤<=10000,<=1<=<<=*m*<=≤<=10). | Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead. | [
"10 2\n",
"3 5\n"
] | [
"6\n",
"-1\n"
] | For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5. | 500 | [
{
"input": "10 2",
"output": "6"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "29 7",
"output": "21"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "10000 2",
"output": "5000"
},
{
"input": "10000 ... | 1,671,709,667 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 9 | 46 | 1,331,200 | n, m = [int(i) for i in input().split()]
mn = n / 2 + n % 2
mx = n
k = 0
if n < m:
print(-1)
else:
while mn > k:
k += m
if k <= mx and k >= mn:
print(k)
else:
print(-1) | Title: Dreamoon and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb ... | ```python
n, m = [int(i) for i in input().split()]
mn = n / 2 + n % 2
mx = n
k = 0
if n < m:
print(-1)
else:
while mn > k:
k += m
if k <= mx and k >= mn:
print(k)
else:
print(-1)
``` | 0 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,661,357,692 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | c = (input())
g="0000000"
d="1111111"
if c.__contains__(g) or c.__contains__(d):
print ("YES")
else:
print("NO") | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
c = (input())
g="0000000"
d="1111111"
if c.__contains__(g) or c.__contains__(d):
print ("YES")
else:
print("NO")
``` | 3.977 |
793 | A | Oleg and shares | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. ... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices. | Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible. | [
"3 3\n12 9 15\n",
"2 2\n10 9\n",
"4 1\n1 1000000000 1000000000 1000000000\n"
] | [
"3",
"-1",
"2999999997"
] | Consider the first example.
Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.
Ther... | 500 | [
{
"input": "3 3\n12 9 15",
"output": "3"
},
{
"input": "2 2\n10 9",
"output": "-1"
},
{
"input": "4 1\n1 1000000000 1000000000 1000000000",
"output": "2999999997"
},
{
"input": "1 11\n123",
"output": "0"
},
{
"input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50... | 1,492,967,363 | 1,463 | PyPy 3 | WRONG_ANSWER | PRETESTS | 1 | 93 | 23,040,000 | a, b = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)
mi = arr[0]
flag = True
c = 0
for i in arr:
if abs(i - mi) % b != 0:
fl = False
break
else:
c += abs(i - mi) // b
if flag:
print(c)
else:
print(-1) | Title: Oleg and shares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly o... | ```python
a, b = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)
mi = arr[0]
flag = True
c = 0
for i in arr:
if abs(i - mi) % b != 0:
fl = False
break
else:
c += abs(i - mi) // b
if flag:
print(c)
else:
print(-1)
``` | 0 | |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,646,321,707 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | '''
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
seen = {}
for i, value in enumerate(nums):
remaining = target - nums[i]
if remaining in seen:
return [i, seen[remaining]]
seen[value] = i
... | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
'''
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
seen = {}
for i, value in enumerate(nums):
remaining = target - nums[i]
if remaining in seen:
return [i, seen[remaining]]
seen[value] = i
... | -1 | |
681 | B | Economy Game | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.
Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Kolya's initial game-coin score. | Print "YES" (without quotes) if it's possible that Kolya spent all of his initial *n* coins buying only houses, cars and computers. Otherwise print "NO" (without quotes). | [
"1359257\n",
"17851817\n"
] | [
"YES",
"NO"
] | In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total. | 1,000 | [
{
"input": "1359257",
"output": "YES"
},
{
"input": "17851817",
"output": "NO"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "17851818",
"output": "YES"
},
{
"input": "438734347",
"output": "YES"
},
{
"input": "43873430",
"output": "YES... | 1,574,857,387 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 109 | 0 | m = int(input())
house = 1234567
car = 123456
comp = 1234
q = 0
w = m
a = 0
b = 0
c = 0
for c in range(0,m//comp + 1):
if q == 0 and m >= comp:
for b in range(0,m//car + 1):
if q == 0 and m >= car:
for a in range(0,m//house+1):
if q == 0 and m ... | Title: Economy Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.... | ```python
m = int(input())
house = 1234567
car = 123456
comp = 1234
q = 0
w = m
a = 0
b = 0
c = 0
for c in range(0,m//comp + 1):
if q == 0 and m >= comp:
for b in range(0,m//car + 1):
if q == 0 and m >= car:
for a in range(0,m//house+1):
if q =... | 0 | |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th... | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar... | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
... | 1,677,609,349 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 46 | 0 | n, k = input().split()
n = int(n)
k = int(k)
time = 60 * 4 - k
count = 0
math = 0
for i in range(1,n+1):
math += 5*i
if math <= time:
count += 1
print(count) | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem... | ```python
n, k = input().split()
n = int(n)
k = int(k)
time = 60 * 4 - k
count = 0
math = 0
for i in range(1,n+1):
math += 5*i
if math <= time:
count += 1
print(count)
``` | 3 | |
350 | A | TL | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running ... | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1... | If there is a valid TL value, print it. Otherwise, print -1. | [
"3 6\n4 5 2\n8 9 6 10 7 11\n",
"3 1\n3 4 5\n6\n"
] | [
"5",
"-1\n"
] | none | 500 | [
{
"input": "3 6\n4 5 2\n8 9 6 10 7 11",
"output": "5"
},
{
"input": "3 1\n3 4 5\n6",
"output": "-1"
},
{
"input": "2 5\n45 99\n49 41 77 83 45",
"output": "-1"
},
{
"input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43... | 1,623,938,111 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 154 | 0 | n,m=map(int,input().split())
n1=list(map(int,input().split()))
m1=list(map(int,input().split()))
if max(2*(min(n1)),max(n1))<min(m1):
print(max(2*(min(n1)),max(n1)))
else:
print(-1) | Title: TL
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Val... | ```python
n,m=map(int,input().split())
n1=list(map(int,input().split()))
m1=list(map(int,input().split()))
if max(2*(min(n1)),max(n1))<min(m1):
print(max(2*(min(n1)),max(n1)))
else:
print(-1)
``` | 3 | |
580 | A | Kefa and First Steps | PROGRAMMING | 900 | [
"brute force",
"dp",
"implementation"
] | null | null | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. | [
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] | [
"3",
"3"
] | In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | 750 | [
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 1,690,962,575 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 78 | 13,516,800 | n = int(input())
a = [int(x) for x in input().split()]
ml = 0
cl = 1
for i in range(1, len(a)):
if a[i] >= a[i-1]:
cl += 1
else:
ml = max(ml, cl)
cl = 1
ml = max(ml, cl)
print(ml)
| Title: Kefa and First Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the l... | ```python
n = int(input())
a = [int(x) for x in input().split()]
ml = 0
cl = 1
for i in range(1, len(a)):
if a[i] >= a[i-1]:
cl += 1
else:
ml = max(ml, cl)
cl = 1
ml = max(ml, cl)
print(ml)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | It's Piegirl's birthday soon, and Pieguy has decided to buy her a bouquet of flowers and a basket of chocolates.
The flower shop has *F* different types of flowers available. The *i*-th type of flower always has exactly *p**i* petals. Pieguy has decided to buy a bouquet consisting of exactly *N* flowers. He may buy th... | The first line of input will contain integers *F*, *B*, and *N* (1<=≤<=*F*<=≤<=10,<=1<=≤<=*B*<=≤<=100,<=1<=≤<=*N*<=≤<=1018), the number of types of flowers, the number of types of boxes, and the number of flowers that must go into the bouquet, respectively.
The second line of input will contain *F* integers *p*1,<=*p*... | Print the number of bouquet+basket combinations Pieguy can buy, modulo 1000000007<==<=109<=+<=7. | [
"2 3 3\n3 5\n10 3 7\n",
"6 5 10\n9 3 3 4 9 9\n9 9 1 6 4\n"
] | [
"17\n",
"31415926\n"
] | In the first example, there is 1 way to make a bouquet with 9 petals (3 + 3 + 3), and 1 way to make a basket with 9 pieces of chocolate (3 + 3 + 3), for 1 possible combination. There are 3 ways to make a bouquet with 13 petals (3 + 5 + 5, 5 + 3 + 5, 5 + 5 + 3), and 5 ways to make a basket with 13 pieces of chocolate (3... | 0 | [] | 1,692,517,323 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | print("_RANDOM_GUESS_1692517323.3094378")# 1692517323.3094554 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's Piegirl's birthday soon, and Pieguy has decided to buy her a bouquet of flowers and a basket of chocolates.
The flower shop has *F* different types of flowers available. The *i*-th type of flower always has exactly *p**i* pe... | ```python
print("_RANDOM_GUESS_1692517323.3094378")# 1692517323.3094554
``` | 0 | |
747 | B | Mammoth's Genome Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s... | The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome.
The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. | If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). | [
"8\nAG?C??CT\n",
"4\nAGCT\n",
"6\n????G?\n",
"4\nAA??\n"
] | [
"AGACGTCT\n",
"AGCT\n",
"===\n",
"===\n"
] | In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is ... | 1,000 | [
{
"input": "8\nAG?C??CT",
"output": "AGACGTCT"
},
{
"input": "4\nAGCT",
"output": "AGCT"
},
{
"input": "6\n????G?",
"output": "==="
},
{
"input": "4\nAA??",
"output": "==="
},
{
"input": "4\n????",
"output": "ACGT"
},
{
"input": "252\n???????GCG??T??TT... | 1,657,953,170 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | length_of_genome = int(input())
s = input()
number_per_characters = length_of_genome // 4
a_characters = s.count('A')
c_characters = s.count('C')
g_characters = s.count('G')
t_characters = s.count('T')
special_characters = s.count('?')
deficient_characters = []
if a_characters < number_per_characters:
deficient... | Title: Mammoth's Genome Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter... | ```python
length_of_genome = int(input())
s = input()
number_per_characters = length_of_genome // 4
a_characters = s.count('A')
c_characters = s.count('C')
g_characters = s.count('G')
t_characters = s.count('T')
special_characters = s.count('?')
deficient_characters = []
if a_characters < number_per_characters:
... | 0 | |
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input... | 1,646,370,772 | 2,147,483,647 | Python 3 | OK | TESTS | 80 | 778 | 0 | def solve():
arr.append(1001)
arr.insert(0,10001)
mx=-1
for i in range(1,n+1) :
c=1
start=i
end=i
while True :
if start>=0 and arr[start]>=arr[start-1] :
c+=1
start-=1
elif end <= n+1 and arr[end]>=arr[end+1] :
... | Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *... | ```python
def solve():
arr.append(1001)
arr.insert(0,10001)
mx=-1
for i in range(1,n+1) :
c=1
start=i
end=i
while True :
if start>=0 and arr[start]>=arr[start-1] :
c+=1
start-=1
elif end <= n+1 and arr[end]>=arr[end+... | 3.8055 |
454 | B | Little Pony and Sort by Shift | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | [
"2\n2 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"1\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 3 2",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "6\n3 4 5 6 3 2",
"output": "-1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n1 1 2 1 1",
"output": "2"
}... | 1,657,815,174 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 61 | 2,764,800 |
n=int(input())
a=list(map(int,input().rstrip().split()))
for i in range(1,n):
if a[i-1]>a[i]:print[-1,n-i][sorted(a)==a[i:]+a[:i]];exit()
print(0)
| Title: Little Pony and Sort by Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. ... | ```python
n=int(input())
a=list(map(int,input().rstrip().split()))
for i in range(1,n):
if a[i-1]>a[i]:print[-1,n-i][sorted(a)==a[i:]+a[:i]];exit()
print(0)
``` | -1 | |
633 | A | Ebony and Ivory | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of ... | The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. | Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. | [
"4 6 15\n",
"3 2 7\n",
"6 11 6\n"
] | [
"No\n",
"Yes\n",
"Yes\n"
] | In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. | 250 | [
{
"input": "4 6 15",
"output": "No"
},
{
"input": "3 2 7",
"output": "Yes"
},
{
"input": "6 11 6",
"output": "Yes"
},
{
"input": "3 12 15",
"output": "Yes"
},
{
"input": "5 5 10",
"output": "Yes"
},
{
"input": "6 6 7",
"output": "No"
},
{
"... | 1,530,782,532 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 109 | 307,200 | a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
if c%a==0 or c%b==0:
print('Yes')
else:
v=min(a,b)
b=max(a,b)
a=v
inc=2
flag=0
while a<=c:
a=a*inc
if (c-a)%b==0:
flag=1
#print(check)
break
inc+=1
print('Yes' ... | Title: Ebony and Ivory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
F... | ```python
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
if c%a==0 or c%b==0:
print('Yes')
else:
v=min(a,b)
b=max(a,b)
a=v
inc=2
flag=0
while a<=c:
a=a*inc
if (c-a)%b==0:
flag=1
#print(check)
break
inc+=1
pr... | 0 | |
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi... | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel... | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input"... | 1,662,888,477 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 109 | 8,806,400 | import math
import copy
import itertools
import bisect
import sys
input = sys.stdin.readline
def ilst():
return list(map(int,input().split()))
def islst():
return list(map(str,input().split()))
def inum():
return map(int,input().split())
n,m = inum()
d = {}
for i in r... | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first ... | ```python
import math
import copy
import itertools
import bisect
import sys
input = sys.stdin.readline
def ilst():
return list(map(int,input().split()))
def islst():
return list(map(str,input().split()))
def inum():
return map(int,input().split())
n,m = inum()
d = {}
... | 3 | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,696,427,898 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 62 | 62 | 0 | a,b = map(int,input().split())
cnt = 0
while a<=b:
cnt+=1
a = a*3
b = b*2
print(cnt) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
a,b = map(int,input().split())
cnt = 0
while a<=b:
cnt+=1
a = a*3
b = b*2
print(cnt)
``` | 3 | |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,694,878,628 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 124 | 0 | # Read input
s1, s2, s3, s4 = map(int, input().split())
# Create a set to store unique colors
colors_set = set([s1, s2, s3, s4])
# Calculate the number of additional horseshoes needed
additional_horseshoes = 4 - len(colors_set)
# Print the result
print(additional_horseshoes)
| Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
# Read input
s1, s2, s3, s4 = map(int, input().split())
# Create a set to store unique colors
colors_set = set([s1, s2, s3, s4])
# Calculate the number of additional horseshoes needed
additional_horseshoes = 4 - len(colors_set)
# Print the result
print(additional_horseshoes)
``` | 3 | |
928 | A | Login Verification | PROGRAMMING | 1,200 | [
"*special",
"strings"
] | null | null | When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds ... | The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins.
The next *n* lines describe the exi... | Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes). | [
"1_wat\n2\n2_wat\nwat_1\n",
"000\n3\n00\nooA\noOo\n",
"_i_\n3\n__i_\n_1_\nI\n",
"La0\n3\n2a0\nLa1\n1a0\n",
"abc\n1\naBc\n",
"0Lil\n2\nLIL0\n0Ril\n"
] | [
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"Yes\n"
] | In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one. | 500 | [
{
"input": "1_wat\n2\n2_wat\nwat_1",
"output": "Yes"
},
{
"input": "000\n3\n00\nooA\noOo",
"output": "No"
},
{
"input": "_i_\n3\n__i_\n_1_\nI",
"output": "No"
},
{
"input": "La0\n3\n2a0\nLa1\n1a0",
"output": "No"
},
{
"input": "abc\n1\naBc",
"output": "No"
}... | 1,519,505,073 | 18,573 | Python 3 | OK | TESTS | 73 | 93 | 5,632,000 | def liker(data):
data = data.upper()
data = data.replace('O', "0")
data = data.replace("L", "I")
data = data.replace("I", "1")
return data
login = liker(input())
numOfLogins = int(input())
loginsArray = [liker(input()) for x in range(numOfLogins)]
if login in loginsArray:
print("No")
else:
print("Y... | Title: Login Verification
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercas... | ```python
def liker(data):
data = data.upper()
data = data.replace('O', "0")
data = data.replace("L", "I")
data = data.replace("I", "1")
return data
login = liker(input())
numOfLogins = int(input())
loginsArray = [liker(input()) for x in range(numOfLogins)]
if login in loginsArray:
print("No")
else:
... | 3 | |
252 | A | Little Xor | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that.
... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230. | Print a single integer — the required maximal *xor* of a segment of consecutive elements. | [
"5\n1 2 1 1 2\n",
"3\n1 2 7\n",
"4\n4 2 4 8\n"
] | [
"3\n",
"7\n",
"14\n"
] | In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one.
The second sample contains only one optimal segment, which contains exactly one array element (element with index three). | 500 | [
{
"input": "5\n1 2 1 1 2",
"output": "3"
},
{
"input": "3\n1 2 7",
"output": "7"
},
{
"input": "4\n4 2 4 8",
"output": "14"
},
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
"output": "15"
},
{
"inpu... | 1,625,317,190 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 218 | 1,331,200 | n = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(n):
x = 0
for j in range(i, n):
x = (x ^ a[j])
res = max(res, x)
print(res)
| Title: Little Xor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, ... | ```python
n = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(n):
x = 0
for j in range(i, n):
x = (x ^ a[j])
res = max(res, x)
print(res)
``` | 3 | |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,692,593,983 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n=int(input())
sum=0
f=((-1)**n)*n
for i in range(1,f+1):
sum+=((-1)**i)*i
print(sum) | Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
n=int(input())
sum=0
f=((-1)**n)*n
for i in range(1,f+1):
sum+=((-1)**i)*i
print(sum)
``` | 0 | |
721 | C | Journey | PROGRAMMING | 1,800 | [
"dp",
"graphs"
] | null | null | Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially I... | The first line of the input contains three integers *n*,<=*m* and *T* (2<=≤<=*n*<=≤<=5000,<=<=1<=≤<=*m*<=≤<=5000,<=<=1<=≤<=*T*<=≤<=109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next *m* lines describes roads in Berlatov. *i*-th of them cont... | Print the single integer *k* (2<=≤<=*k*<=≤<=*n*) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace *n* within time not exceeding *T*, in the first line.
Print *k* distinct integers in the second line — indices of showplaces that Irina will visit on her route, in t... | [
"4 3 13\n1 2 5\n2 3 7\n2 4 8\n",
"6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n",
"5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n"
] | [
"3\n1 2 4 \n",
"4\n1 2 4 6 \n",
"3\n1 3 5 \n"
] | none | 1,500 | [
{
"input": "4 3 13\n1 2 5\n2 3 7\n2 4 8",
"output": "3\n1 2 4 "
},
{
"input": "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1",
"output": "4\n1 2 4 6 "
},
{
"input": "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2",
"output": "3\n1 3 5 "
},
{
"input": "10 10 100\n1 4 1\n6 4 1\n9 3... | 1,600,616,889 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 265 | 614,400 | import sys
def dfs(i, t):
if i == n-1 and t >= 0:
return (1, [i])
if t < 0:
return (-2e9, [-1])
mas = -2e9
ris = []
for k in graph[i]:
tmp = dfs(k[0], t-k[1])
if tmp[0] > mas:
mas = tmp[0]
ris = tmp[1]
ris.append(i)... | Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlato... | ```python
import sys
def dfs(i, t):
if i == n-1 and t >= 0:
return (1, [i])
if t < 0:
return (-2e9, [-1])
mas = -2e9
ris = []
for k in graph[i]:
tmp = dfs(k[0], t-k[1])
if tmp[0] > mas:
mas = tmp[0]
ris = tmp[1]
ris... | -1 | |
600 | B | Queries about less or equal elements | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | 0 | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -77918754... | 1,680,020,383 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = list(map(int, input().split()))
for i in range(m):
x = b[i]
l = 0
r = n
while r-l>1:
m = (l+r)//2
if a[m]<=x:
l = m
else:
r = m
print(r, end=" ")
... | Title: Queries about less or equal elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
In... | ```python
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = list(map(int, input().split()))
for i in range(m):
x = b[i]
l = 0
r = n
while r-l>1:
m = (l+r)//2
if a[m]<=x:
l = m
else:
r = m
print(r, end=" ")
... | 0 | |
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats num... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on,... | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The ligh... | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 ... | 1,505,792,912 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 204,800 | n,m = input().split()
n,m = map(int,[n,m])
an = input()
list1 = []
for i in an.split():
list1.append(int(i))
A = []
for j in range(0,n-1):
x,y = input().split()
x,y = map(int,[x,y])
A.append([x,y,list1[j+1]])
#print(A)
B = []#记路过了几条狗
for k in range(0,n-1):
B.append(0)
count = 0
for l in range(0,n-1)... | Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vital... | ```python
n,m = input().split()
n,m = map(int,[n,m])
an = input()
list1 = []
for i in an.split():
list1.append(int(i))
A = []
for j in range(0,n-1):
x,y = input().split()
x,y = map(int,[x,y])
A.append([x,y,list1[j+1]])
#print(A)
B = []#记路过了几条狗
for k in range(0,n-1):
B.append(0)
count = 0
for l in ra... | -1 | |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co... | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"ou... | 1,531,901,431 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 155 | 0 | from math import gcd
n = int(input())
a, b = 1, n - 1
for c in range(1, n):
if gcd(c, n - c) == 1 and c < n - c:
a, b = c, n - c
print(a, b)
| Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is cal... | ```python
from math import gcd
n = int(input())
a, b = 1, n - 1
for c in range(1, n):
if gcd(c, n - c) == 1 and c < n - c:
a, b = c, n - c
print(a, b)
``` | 3 | |
702 | C | Cellular Network | PROGRAMMING | 1,500 | [
"binary search",
"implementation",
"two pointers"
] | null | null | You are given *n* points on the straight line — the positions (*x*-coordinates) of the cities and *m* points on the same line — the positions (*x*-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than ... | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of cities and the number of cellular towers.
The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the coordinates of cities. It is allowed that there are any number... | Print minimal *r* so that each city will be covered by cellular network. | [
"3 2\n-2 2 4\n-3 0\n",
"5 3\n1 5 10 14 17\n4 11 15\n"
] | [
"4\n",
"3\n"
] | none | 0 | [
{
"input": "3 2\n-2 2 4\n-3 0",
"output": "4"
},
{
"input": "5 3\n1 5 10 14 17\n4 11 15",
"output": "3"
},
{
"input": "1 1\n-1000000000\n1000000000",
"output": "2000000000"
},
{
"input": "1 1\n1000000000\n-1000000000",
"output": "2000000000"
},
{
"input": "10 10\n... | 1,675,911,092 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 92 | 2,048,000 | """
https://codeforces.com/contest/702/problem/C
"""
def main():
n, m = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
a.sort()
b.sort()
r = 0
cur_tower = b[0]
cur_city = a[0]
i, j = 0, 0
while i < len... | Title: Cellular Network
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on the straight line — the positions (*x*-coordinates) of the cities and *m* points on the same line — the positions (*x*-coordinates) of the cellular towers. All towers work in the same way — ... | ```python
"""
https://codeforces.com/contest/702/problem/C
"""
def main():
n, m = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
a.sort()
b.sort()
r = 0
cur_tower = b[0]
cur_city = a[0]
i, j = 0, 0
whi... | -1 | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,551,933,537 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 109 | 0 | s = input()
t = 0
for i in s:
if i.isdigit() and int(i) % 2 or i in "aeiou":
t += 1
print(t)
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
s = input()
t = 0
for i in s:
if i.isdigit() and int(i) % 2 or i in "aeiou":
t += 1
print(t)
``` | 3 | |
108 | A | Palindromic Times | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | A. Palindromic Times | 2 | 256 | Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on th... | The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits. | Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time. | [
"12:21\n",
"23:59\n"
] | [
"13:31\n",
"00:00\n"
] | none | 500 | [
{
"input": "12:21",
"output": "13:31"
},
{
"input": "23:59",
"output": "00:00"
},
{
"input": "15:51",
"output": "20:02"
},
{
"input": "10:44",
"output": "11:11"
},
{
"input": "04:02",
"output": "04:40"
},
{
"input": "02:11",
"output": "02:20"
},
... | 1,600,293,651 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 248 | 0 | h,m=input().split(":")
h=int(h)
arr=[6,7,8,9,16,17,18,19,23]
def rev(h):
h=str(h)
return h[::-1]
if h not in arr:
h+=1
print(str(h)+":"+rev(h))
else:
if h==23:
print("00:00")
elif h<10:
print("10:01")
else:print("20:02")
| Title: Palindromic Times
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling... | ```python
h,m=input().split(":")
h=int(h)
arr=[6,7,8,9,16,17,18,19,23]
def rev(h):
h=str(h)
return h[::-1]
if h not in arr:
h+=1
print(str(h)+":"+rev(h))
else:
if h==23:
print("00:00")
elif h<10:
print("10:01")
else:print("20:02")
``` | 0 |
771 | D | Bear and Company | PROGRAMMING | 2,500 | [
"dp"
] | null | null | Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible.
Limak has a string *s*... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=75) — the length of the string.
The second line contains a string *s*, consisting of uppercase English letters. The length of the string is equal to *n*. | Print one integer, denoting the minimum possible number of moves Limak can do, in order to obtain a string without a substring "VK". | [
"4\nVKVK\n",
"5\nBVVKV\n",
"7\nVVKEVKK\n",
"20\nVKVKVVVKVOVKVQKKKVVK\n",
"5\nLIMAK\n"
] | [
"3\n",
"2\n",
"3\n",
"8\n",
"0\n"
] | In the first sample, the initial string is "VKVK". The minimum possible number of moves is 3. One optimal sequence of moves is:
1. Swap two last letters. The string becomes "VKKV".1. Swap first two letters. The string becomes "KVKV".1. Swap the second and the third letter. The string becomes "KKVV". Indeed, this str... | 1,500 | [
{
"input": "4\nVKVK",
"output": "3"
},
{
"input": "5\nBVVKV",
"output": "2"
},
{
"input": "7\nVVKEVKK",
"output": "3"
},
{
"input": "20\nVKVKVVVKVOVKVQKKKVVK",
"output": "8"
},
{
"input": "5\nLIMAK",
"output": "0"
},
{
"input": "1\nV",
"output": "0... | 1,489,858,169 | 6,869 | Python 3 | WRONG_ANSWER | PRETESTS | 8 | 46 | 4,608,000 | n = int(input())
s = "".join(['O' if x not in ('V', 'K') else x for x in input()])
ar = s.split("O")
m = len(ar)
k = 0
for i, el in enumerate(ar):
for j, c in enumerate(el):
if c != "K": continue
l = el[:j].count("V")
if i != m-1:
l = min(l, el[j+1:].count("V") + 1)
... | Title: Bear and Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it ... | ```python
n = int(input())
s = "".join(['O' if x not in ('V', 'K') else x for x in input()])
ar = s.split("O")
m = len(ar)
k = 0
for i, el in enumerate(ar):
for j, c in enumerate(el):
if c != "K": continue
l = el[:j].count("V")
if i != m-1:
l = min(l, el[j+1:].count("V"... | 0 | |
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*... | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
}... | 1,596,705,113 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 310 | 20,172,800 | a=int(input())
b=int(input())
c=a+b
a=int(''.join(x for x in str(a) if x!='0'))
b=int(''.join(x for x in str(b) if x!='0'))
c=int(''.join(x for x in str(c) if x!='0'))
if(a+b==c):
print("YES")
else:
print("NO") | Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu... | ```python
a=int(input())
b=int(input())
c=a+b
a=int(''.join(x for x in str(a) if x!='0'))
b=int(''.join(x for x in str(b) if x!='0'))
c=int(''.join(x for x in str(c) if x!='0'))
if(a+b==c):
print("YES")
else:
print("NO")
``` | 3.884925 |
991 | C | Candies | PROGRAMMING | 1,500 | [
"binary search",
"implementation"
] | null | null | After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself.
This means the process of eating candies is the following: in the beginning Vasya cho... | The first line contains a single integer $n$ ($1 \leq n \leq 10^{18}$) — the initial amount of candies in the box. | Output a single integer — the minimal amount of $k$ that would allow Vasya to eat at least half of candies he got. | [
"68\n"
] | [
"3\n"
] | In the sample, the amount of candies, with $k=3$, would change in the following way (Vasya eats first):
$68 \to 65 \to 59 \to 56 \to 51 \to 48 \to 44 \to 41 \\ \to 37 \to 34 \to 31 \to 28 \to 26 \to 23 \to 21 \to 18 \to 17 \to 14 \\ \to 13 \to 10 \to 9 \to 6 \to 6 \to 3 \to 3 \to 0$.
In total, Vasya would eat $39$ ca... | 1,250 | [
{
"input": "68",
"output": "3"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "42",
"output": "1"
},
{
"input": "43",
"output": "2"
},
{
"input": "756",
"output": "29"
},
{
"input": "999999972",
"output"... | 1,608,303,482 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 124 | 0 | n = int(input())
l, r = 1, int(1e9) + 1
m = -1
while l < r - 1:
f = 0
m = (l + r) // 2
if n / 10 <= 2 * m:
r = m
else:
l = m
print(m)
| Title: Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for hi... | ```python
n = int(input())
l, r = 1, int(1e9) + 1
m = -1
while l < r - 1:
f = 0
m = (l + r) // 2
if n / 10 <= 2 * m:
r = m
else:
l = m
print(m)
``` | 0 | |
20 | A | BerOS file system | PROGRAMMING | 1,700 | [
"implementation"
] | A. BerOS file system | 2 | 64 | The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of ... | The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. | The path in normalized form. | [
"//usr///local//nginx/sbin\n"
] | [
"/usr/local/nginx/sbin\n"
] | none | 500 | [
{
"input": "//usr///local//nginx/sbin",
"output": "/usr/local/nginx/sbin"
},
{
"input": "////a//b/////g",
"output": "/a/b/g"
},
{
"input": "/a/b/c",
"output": "/a/b/c"
},
{
"input": "/",
"output": "/"
},
{
"input": "////",
"output": "/"
},
{
"input": "... | 1,623,118,886 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 216 | 0 | s=str(input())
a="/"
for i in range(1,len(s)):
if((s[i]==s[i-1] and s[i]=='/')):
b=1
else:
a=a+s[i]
print(a) | Title: BerOS file system
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/n... | ```python
s=str(input())
a="/"
for i in range(1,len(s)):
if((s[i]==s[i-1] and s[i]=='/')):
b=1
else:
a=a+s[i]
print(a)
``` | 0 |
215 | A | Bicycle Chain | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the *i*-th star on the pedal axle has *a**i* (0<=<<=*a*1<=<<=*a*2<=<<=...<=<<... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing.
The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars o... | Print the number of "integer" gears with the maximum ratio among all "integer" gears. | [
"2\n4 5\n3\n12 13 15\n",
"4\n1 2 3 4\n5\n10 11 12 13 14\n"
] | [
"2\n",
"1\n"
] | In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15. | 500 | [
{
"input": "2\n4 5\n3\n12 13 15",
"output": "2"
},
{
"input": "4\n1 2 3 4\n5\n10 11 12 13 14",
"output": "1"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 2\n1\n1",
"output": "1"
},
{
"input": "1\n1\n2\n1 2",
"output": "1"
},
{
"input":... | 1,646,215,871 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 16 | 92 | 0 | n=int(input())
q=[int(l) for l in input().split()]
m=int(input())
w=[int(q) for q in input().split()]
max=0;adet=1
for a in range(m):
for b in range(n):
if(int(w[m-1-a]/q[b])==w[m-1-a]/q[b] and w[m-1-a]/q[b]>max):
max=w[m-1-a]/q[b]
elif(int(w[m-1-a]/q[b])==w[m-1-a]/q[b] and w[m-... | Title: Bicycle Chain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We ... | ```python
n=int(input())
q=[int(l) for l in input().split()]
m=int(input())
w=[int(q) for q in input().split()]
max=0;adet=1
for a in range(m):
for b in range(n):
if(int(w[m-1-a]/q[b])==w[m-1-a]/q[b] and w[m-1-a]/q[b]>max):
max=w[m-1-a]/q[b]
elif(int(w[m-1-a]/q[b])==w[m-1-a]/q[b... | 0 | |
863 | C | 1-2-3 | PROGRAMMING | 1,800 | [
"graphs",
"implementation"
] | null | null | Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice".
... | The first line contains three numbers *k*, *a*, *b* (1<=≤<=*k*<=≤<=1018, 1<=≤<=*a*,<=*b*<=≤<=3).
Then 3 lines follow, *i*-th of them containing 3 numbers *A**i*,<=1, *A**i*,<=2, *A**i*,<=3, where *A**i*,<=*j* represents Alice's choice in the game if Alice chose *i* in previous game and Bob chose *j* (1<=≤<=*A**i*,<=*... | Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after *k* games. | [
"10 2 1\n1 1 1\n1 1 1\n1 1 1\n2 2 2\n2 2 2\n2 2 2\n",
"8 1 1\n2 2 1\n3 3 1\n3 1 3\n1 1 1\n2 1 1\n1 2 3\n",
"5 1 1\n1 2 2\n2 2 2\n2 2 2\n1 2 2\n2 2 2\n2 2 2\n"
] | [
"1 9\n",
"5 2\n",
"0 0\n"
] | In the second example game goes like this:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1e21b6e200707470571d69c9946ace6b56f5279b.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice. | 0 | [
{
"input": "10 2 1\n1 1 1\n1 1 1\n1 1 1\n2 2 2\n2 2 2\n2 2 2",
"output": "1 9"
},
{
"input": "8 1 1\n2 2 1\n3 3 1\n3 1 3\n1 1 1\n2 1 1\n1 2 3",
"output": "5 2"
},
{
"input": "5 1 1\n1 2 2\n2 2 2\n2 2 2\n1 2 2\n2 2 2\n2 2 2",
"output": "0 0"
},
{
"input": "1 1 1\n3 3 1\n1 1 1\... | 1,595,653,394 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 6,963,200 | alice, bob = 0,0
def put():
return map(int, input().split())
def play(a,b):
global alice, bob
if a==b:
pass
elif (a,b) in [(2,1), (1,0), (0,2)]:
alice+=1
else:
bob+=1
t,a,b = put()
A,B = [list(put()) for i in range(3)], [list(put()) for i in range(3)]
a,b = ... | Title: 1-2-3
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is... | ```python
alice, bob = 0,0
def put():
return map(int, input().split())
def play(a,b):
global alice, bob
if a==b:
pass
elif (a,b) in [(2,1), (1,0), (0,2)]:
alice+=1
else:
bob+=1
t,a,b = put()
A,B = [list(put()) for i in range(3)], [list(put()) for i in range(3... | 0 | |
651 | B | Beautiful Paintings | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy ... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of painting.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where *a**i* means the beauty of the *i*-th painting. | Print one integer — the maximum possible number of neighbouring pairs, such that *a**i*<=+<=1<=><=*a**i*, after the optimal rearrangement. | [
"5\n20 30 10 50 40\n",
"4\n200 100 100 200\n"
] | [
"4\n",
"2\n"
] | In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | 1,000 | [
{
"input": "5\n20 30 10 50 40",
"output": "4"
},
{
"input": "4\n200 100 100 200",
"output": "2"
},
{
"input": "10\n2 2 2 2 2 2 2 2 2 2",
"output": "0"
},
{
"input": "1\n1000",
"output": "0"
},
{
"input": "2\n444 333",
"output": "1"
},
{
"input": "100\n... | 1,633,376,523 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 5 | 62 | 7,168,000 | from collections import defaultdict
n = int(input())
values = sorted(list(map(int, input().split())))
counts = defaultdict(int)
res = 0
for value in values:
counts[value] += 1
i = 0
keys = list(counts.keys())
temp = []
while counts:
key = keys[i%len(keys)]
if key in counts:
counts... | Title: Beautiful Paintings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to a... | ```python
from collections import defaultdict
n = int(input())
values = sorted(list(map(int, input().split())))
counts = defaultdict(int)
res = 0
for value in values:
counts[value] += 1
i = 0
keys = list(counts.keys())
temp = []
while counts:
key = keys[i%len(keys)]
if key in counts:
... | -1 | |
976 | C | Nested Segments | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"sortings"
] | null | null | You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*.
Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2.
Print indices ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of segments.
Each of the next *n* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the *i*-th segment. | Print two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1. | [
"5\n1 10\n2 9\n3 9\n2 3\n2 9\n",
"3\n1 5\n2 6\n6 20\n"
] | [
"2 1\n",
"-1 -1\n"
] | In the first example the following pairs are considered correct:
- (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; - (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; - (5, 2), (2, 5) — match exactly. | 0 | [
{
"input": "5\n1 10\n2 9\n3 9\n2 3\n2 9",
"output": "2 1"
},
{
"input": "3\n1 5\n2 6\n6 20",
"output": "-1 -1"
},
{
"input": "1\n1 1000000000",
"output": "-1 -1"
},
{
"input": "2\n1 1000000000\n1 1000000000",
"output": "2 1"
},
{
"input": "2\n1 1000000000\n5000000... | 1,623,081,396 | 2,147,483,647 | Python 3 | OK | TESTS | 122 | 1,294 | 30,617,600 | R = lambda :map(int, input().split())
n = int(input())
l = []
for _ in range(n):
a,b = R()
l.append((a,-b,_+1))
l = sorted(l)
for i in range(1,n):
if l[i][1]>=l[i-1][1]:
print(l[i][2],l[i-1][2])
break
else:
print(-1,-1) | Title: Nested Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*.
Segment... | ```python
R = lambda :map(int, input().split())
n = int(input())
l = []
for _ in range(n):
a,b = R()
l.append((a,-b,_+1))
l = sorted(l)
for i in range(1,n):
if l[i][1]>=l[i-1][1]:
print(l[i][2],l[i-1][2])
break
else:
print(-1,-1)
``` | 3 | |
690 | C1 | Brain Network (easy) | PROGRAMMING | 1,300 | [] | null | null | One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the reason is not (as previously suspected) any kind of brain defect – it's the opposite!... | The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) denoting the number of brains (which are conveniently numbered from 1 to *n*) and the number of brain connectors in the nervous system, respectively. In the next *m* lines, descriptions of brain connectors follow. E... | The output consists of one line, containing either yes or no depending on whether the nervous system is valid. | [
"4 4\n1 2\n2 3\n3 1\n4 1\n",
"6 5\n1 2\n2 3\n3 4\n4 5\n3 6\n"
] | [
"no\n",
"yes\n"
] | none | 0 | [
{
"input": "4 4\n1 2\n2 3\n3 1\n4 1",
"output": "no"
},
{
"input": "6 5\n1 2\n2 3\n3 4\n4 5\n3 6",
"output": "yes"
},
{
"input": "2 1\n1 2",
"output": "yes"
},
{
"input": "3 3\n2 1\n1 3\n3 2",
"output": "no"
},
{
"input": "3 2\n1 2\n2 3",
"output": "yes"
},
... | 1,490,734,950 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 93 | 6,246,400 | def is_valid():
import sys
#with open(filename, 'r') as f:
with sys.stdin as f:
for i, line in enumerate(f):
if i == 0:
N, M = line.split(' ')
N, M = int(N), int(M)
if N-1 != M:
return False
graph = [[] f... | Title: Brain Network (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. I... | ```python
def is_valid():
import sys
#with open(filename, 'r') as f:
with sys.stdin as f:
for i, line in enumerate(f):
if i == 0:
N, M = line.split(' ')
N, M = int(N), int(M)
if N-1 != M:
return False
gra... | 3 | |
547 | B | Mike and Feet | PROGRAMMING | 1,900 | [
"binary search",
"data structures",
"dp",
"dsu"
] | null | null | Mike is the president of country What-The-Fatherland. There are *n* bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to *n* from left to right. *i*-th bear is exactly *a**i* feet high.
A group of bears is a non-empty contiguous segment of the line. The size of... | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=2<=×<=105), the number of bears.
The second line contains *n* integers separated by space, *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), heights of bears. | Print *n* integers in one line. For each *x* from 1 to *n*, print the maximum strength among all groups of size *x*. | [
"10\n1 2 3 4 5 4 3 2 1 6\n"
] | [
"6 4 4 3 3 2 2 1 1 1 \n"
] | none | 1,000 | [
{
"input": "10\n1 2 3 4 5 4 3 2 1 6",
"output": "6 4 4 3 3 2 2 1 1 1 "
},
{
"input": "3\n524125987 923264237 374288891",
"output": "923264237 524125987 374288891 "
},
{
"input": "5\n585325539 365329221 412106895 291882089 564718673",
"output": "585325539 365329221 365329221 291882089... | 1,432,740,100 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 8,499,200 | n = int(input())
data = [int(x) for x in input().split()]
left = []
stack = []
for i in range(n):
while len(stack) and data[i] <= data[stack[len(stack) - 1]]:
a = stack.pop()
if not stack:
left.append(-1)
else:
left.append(stack[len(stack) - 1])
stack.append(i)
stack = []
righ... | Title: Mike and Feet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is the president of country What-The-Fatherland. There are *n* bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to *n* from left to right. *i*-th bear is exac... | ```python
n = int(input())
data = [int(x) for x in input().split()]
left = []
stack = []
for i in range(n):
while len(stack) and data[i] <= data[stack[len(stack) - 1]]:
a = stack.pop()
if not stack:
left.append(-1)
else:
left.append(stack[len(stack) - 1])
stack.append(i)
stack... | 0 | |
701 | C | They Are Everywhere | PROGRAMMING | 1,500 | [
"binary search",
"strings",
"two pointers"
] | null | null | Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is ... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of flats in the house.
The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*. | Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. | [
"3\nAaA\n",
"7\nbcAAcbc\n",
"6\naaBCCe\n"
] | [
"2\n",
"3\n",
"5\n"
] | In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | 1,000 | [
{
"input": "3\nAaA",
"output": "2"
},
{
"input": "7\nbcAAcbc",
"output": "3"
},
{
"input": "6\naaBCCe",
"output": "5"
},
{
"input": "1\nA",
"output": "1"
},
{
"input": "1\ng",
"output": "1"
},
{
"input": "52\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ... | 1,697,935,867 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | def check_pokedex(pokedex):
ans = True
for x in pokedex.keys():
if pokedex[x] == 0:
ans = False
return ans
ans = []
n = int(input())
string = input()
pokedex = {}
types = 0
#How many types are there
for x in string:
if x not in pokedex:
pokedex[x] = 0
else:
type... | Title: They Are Everywhere
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each ... | ```python
def check_pokedex(pokedex):
ans = True
for x in pokedex.keys():
if pokedex[x] == 0:
ans = False
return ans
ans = []
n = int(input())
string = input()
pokedex = {}
types = 0
#How many types are there
for x in string:
if x not in pokedex:
pokedex[x] = 0
else:
... | 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,676,063,576 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 |
a=int(input())
c=0
for i in range(a):
s=(input())
e=s.split(' ')
v1=int(e[0])
v2=int(e[1])
v3=int(e[2])
c+=v1+v2+v3
if c :
print("no")
else:
print('yes') | 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
a=int(input())
c=0
for i in range(a):
s=(input())
e=s.split(' ')
v1=int(e[0])
v2=int(e[1])
v3=int(e[2])
c+=v1+v2+v3
if c :
print("no")
else:
print('yes')
``` | 0 |
380 | C | Sereja and Brackets | PROGRAMMING | 2,000 | [
"data structures",
"schedules"
] | null | null | Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length o... | The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains ... | Print the answer to each question on a single line. Print the answers in the order they go in the input. | [
"())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n"
] | [
"0\n0\n2\n10\n4\n6\n6\n"
] | A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<s... | 1,500 | [
{
"input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10",
"output": "0\n0\n2\n10\n4\n6\n6"
},
{
"input": "(((((()((((((((((()((()(((((\n1\n8 15",
"output": "0"
},
{
"input": "((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((((()(((((((((((((((((((()(((\n39\n28 56\n39 ... | 1,624,727,034 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | import sys
import math
input=sys.stdin.readline
s=input().rstrip()
n=len(s)
q=int(input())
class segTree:
def __init__(self):
self.a=[0]*(2*n)
self.b=[0]*(2*n)
self.c=[0]*(2*n)
def build(self,arr):
for i in range(n):
self.a[i+n]=0
self.b[i+n]... | Title: Sereja and Brackets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two i... | ```python
import sys
import math
input=sys.stdin.readline
s=input().rstrip()
n=len(s)
q=int(input())
class segTree:
def __init__(self):
self.a=[0]*(2*n)
self.b=[0]*(2*n)
self.c=[0]*(2*n)
def build(self,arr):
for i in range(n):
self.a[i+n]=0
s... | 0 | |
775 | A | University Schedule | PROGRAMMING | 2,900 | [
"*special"
] | null | null | In this problem your task is to come up with a week schedule of classes in university for professors and student groups. Consider that there are 6 educational days in week and maximum number of classes per educational day is 7 (classes numerated from 1 to 7 for each educational day).
It is known that in university *n*... | The first line contains three integers *n*, *m* and *a* (1<=≤<=*n*,<=*m*,<=*a*<=≤<=60) — the number of groups, the number of professors and the number of classrooms.
Each of the following *n* lines contains *m* integers from 0 to 24 — *j*-th number in *i*-th line equals to the number of classes with the professor *j* ... | In the first line print the minimized value of function *f*.
After that print blank line.
After that print the schedule for each student group in increasing order of group number. For each student group print 7 lines. Each line must contains 6 numbers. Let the number at *i*-th line and *j*-th column equals to *x*. If... | [
"3 3 1\n1 0 0\n0 1 0\n0 0 1\n",
"3 1 1\n1\n1\n1\n",
"5 7 10\n1 3 6 0 1 2 4\n0 3 0 6 5 1 4\n3 5 1 2 3 2 4\n2 3 1 1 4 1 2\n2 4 3 2 4 3 2\n"
] | [
"54\n\n1 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n\n0 0 0 0 0 0 \n2 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n\n0 0 0 0 0 0 \n0 0 0 0 0 0 \n3 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n",
"52\n\... | During the main part of the competition (one week) you solution will be judged on 100 preliminary tests. The first 10 preliminary tests are available for download by a link [http://assets.codeforces.com/files/vk/vkcup-2017-wr2-materials-v1.tar.gz](//assets.codeforces.com/files/vk/vkcup-2017-wr2-materials-v1.tar.gz).
A... | 0 | [] | 1,645,437,705 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("Hello, World!") | Title: University Schedule
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem your task is to come up with a week schedule of classes in university for professors and student groups. Consider that there are 6 educational days in week and maximum number of classes per education... | ```python
print("Hello, World!")
``` | 0 | |
630 | L | Cracking the Code | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activation code arrives.
A young hacker Vasya disassembled the program and foun... | The only line of the input contains a positive integer five digit number for which the activation code should be found. | Output exactly 5 digits without spaces between them — the found activation code of the program. | [
"12345\n"
] | [
"71232"
] | none | 0 | [
{
"input": "12345",
"output": "71232"
},
{
"input": "13542",
"output": "84443"
},
{
"input": "71232",
"output": "10151"
},
{
"input": "11111",
"output": "36551"
},
{
"input": "10000",
"output": "00000"
},
{
"input": "99999",
"output": "99999"
},
... | 1,695,490,683 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n = input()
n1 = int(n[0] + n[2] + n[4] + n[3] + n[1])
print(n1 ** 5 % 100000) | Title: Cracking the Code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone numb... | ```python
n = input()
n1 = int(n[0] + n[2] + n[4] + n[3] + n[1])
print(n1 ** 5 % 100000)
``` | 0 | |
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,628,497,521 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 77 | 7,372,800 | n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = i = 0
for j in range(m):
if i >= n:
break
if b[j] >= a[i]:
count += 1
i += 1
print(n-count)
| 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
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = i = 0
for j in range(m):
if i >= n:
break
if b[j] >= a[i]:
count += 1
i += 1
print(n-count)
``` | 3 | |
986 | D | Perfect Encoding | PROGRAMMING | 3,100 | [
"fft",
"math"
] | null | null | You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID.
To create the system, you choose the parameters of the system — integers $m \ge 1$ and $b_{1}, b_{2}, \ldots, b_{m}$. With these parameters an ID o... | In the only line of input there is one positive integer $n$. The length of the decimal representation of $n$ is no greater than $1.5 \cdot 10^{6}$. The integer does not contain leading zeros. | Print one number — minimal value of $\sum_{i=1}^{m} b_{i}$. | [
"36\n",
"37\n",
"12345678901234567890123456789\n"
] | [
"10\n",
"11\n",
"177\n"
] | none | 2,500 | [
{
"input": "36",
"output": "10"
},
{
"input": "37",
"output": "11"
},
{
"input": "12345678901234567890123456789",
"output": "177"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "3"
},
{
"input... | 1,545,707,284 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 14 | 2,000 | 4,198,400 | import math
# fileT = open("test.in","r")
# n = int(fileT.readline().strip())
n = int(input())
if n == 1 :
print(1)
exit(0)
ans = int(math.log(n,3)) - 1
tmp = pow(3,ans)
while 1 :
for i in range(2,5) :
if tmp*i >= n :
print(ans*3+i)
exit(0)
tmp ... | Title: Perfect Encoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID.
To create the system, you choose the paramete... | ```python
import math
# fileT = open("test.in","r")
# n = int(fileT.readline().strip())
n = int(input())
if n == 1 :
print(1)
exit(0)
ans = int(math.log(n,3)) - 1
tmp = pow(3,ans)
while 1 :
for i in range(2,5) :
if tmp*i >= n :
print(ans*3+i)
exit(0)... | 0 | |
454 | B | Little Pony and Sort by Shift | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | [
"2\n2 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"1\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 3 2",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "6\n3 4 5 6 3 2",
"output": "-1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n1 1 2 1 1",
"output": "2"
}... | 1,609,828,820 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 186 | 10,854,400 | from sys import stdin, stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int, stdin.readline().split()))
for _ in range(1):#nmbr()):
n=nmbr()
a=lst()
p=-1
for i in range(1,n):
if a[i]<a[i-1]:
p=i
break
if p!=-1:new=a[p:][::-1]+a[:p]
if p==-1:print... | Title: Little Pony and Sort by Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. ... | ```python
from sys import stdin, stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int, stdin.readline().split()))
for _ in range(1):#nmbr()):
n=nmbr()
a=lst()
p=-1
for i in range(1,n):
if a[i]<a[i-1]:
p=i
break
if p!=-1:new=a[p:][::-1]+a[:p]
if p... | 0 | |
804 | A | Find Amir | PROGRAMMING | 1,000 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* an... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of schools. | Print single integer: the minimum cost of tickets needed to visit all schools. | [
"2\n",
"10\n"
] | [
"0\n",
"4\n"
] | In the first example we can buy a ticket between the schools that costs <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c67d72010e0498bfd065a6a38fdeaec90358507b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "2",
"output": "0"
},
{
"input": "10",
"output": "4"
},
{
"input": "43670",
"output": "21834"
},
{
"input": "4217",
"output": "2108"
},
{
"input": "17879",
"output": "8939"
},
{
"input": "31809",
"output": "15904"
},
{
"input": "... | 1,509,981,881 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 62 | 0 | a=int(input())
if a%2==0:
x= int((a/2-1))
print (x)
if a%2 !=0:
y= int(((a+1)/2-1))
print(y)
| Title: Find Amir
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel b... | ```python
a=int(input())
if a%2==0:
x= int((a/2-1))
print (x)
if a%2 !=0:
y= int(((a+1)/2-1))
print(y)
``` | 3 | |
315 | A | Sereja and Bottles | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. | In a single line print a single integer — the answer to the problem. | [
"4\n1 1\n2 2\n3 3\n4 4\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] | [
"4\n",
"0\n"
] | none | 500 | [
{
"input": "4\n1 1\n2 2\n3 3\n4 4",
"output": "4"
},
{
"input": "4\n1 2\n2 3\n3 4\n4 1",
"output": "0"
},
{
"input": "3\n2 828\n4 392\n4 903",
"output": "3"
},
{
"input": "4\n2 3\n1 772\n3 870\n3 668",
"output": "2"
},
{
"input": "5\n1 4\n6 6\n4 3\n3 4\n4 758",
... | 1,609,197,374 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 342 | 1,433,600 | n = int(input())
arr = [False] * n
des = []
for i in range(n):
a,b = map(int, input().split())
des.append([a,b,False])
for i in range(n):
open = des[i][1]
for j in range(n):
if(j != i):
if(des[j][0] == open):
des[j][2] = True
count = 0
for i in des:
... | Title: Sereja and Bottles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th... | ```python
n = int(input())
arr = [False] * n
des = []
for i in range(n):
a,b = map(int, input().split())
des.append([a,b,False])
for i in range(n):
open = des[i][1]
for j in range(n):
if(j != i):
if(des[j][0] == open):
des[j][2] = True
count = 0
for i in ... | 3 | |
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"... | 1,647,356,989 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | import sys
input_ = input()
planes, numbers = input_.split('\n')
planes = int(planes)
numbers = [int(i) for i in numbers.split()]
graph = {i+1:j for i,j in enumerate(numbers)}
for i in range(1, planes+1):
if graph[graph[graph[i]]]==i:
print('YES')
break
print('NO')
| Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with ... | ```python
import sys
input_ = input()
planes, numbers = input_.split('\n')
planes = int(planes)
numbers = [int(i) for i in numbers.split()]
graph = {i+1:j for i,j in enumerate(numbers)}
for i in range(1, planes+1):
if graph[graph[graph[i]]]==i:
print('YES')
break
print('NO')
``` | -1 | |
591 | A | Wizards' Duel | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and... | The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ... | Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer ... | [
"100\n50\n50\n",
"199\n60\n40\n"
] | [
"50\n",
"119.4\n"
] | In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | 500 | [
{
"input": "100\n50\n50",
"output": "50"
},
{
"input": "199\n60\n40",
"output": "119.4"
},
{
"input": "1\n1\n1",
"output": "0.5"
},
{
"input": "1\n1\n500",
"output": "0.001996007984"
},
{
"input": "1\n500\n1",
"output": "0.998003992"
},
{
"input": "1\n... | 1,445,764,017 | 417 | Python 3 | OK | TESTS | 45 | 77 | 512,000 | import sys
from collections import deque
read = lambda: list(map(int, sys.stdin.readline().split()))
l,= read()
p, = read()
q, = read()
print (l*p/(p+q))
| Title: Wizards' Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en... | ```python
import sys
from collections import deque
read = lambda: list(map(int, sys.stdin.readline().split()))
l,= read()
p, = read()
q, = read()
print (l*p/(p+q))
``` | 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.