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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
38 | A | Army | PROGRAMMING | 800 | [
"implementation"
] | A. Army | 2 | 256 | The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is... | The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=*n*). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. | [
"3\n5 6\n1 2\n",
"3\n5 6\n1 3\n"
] | [
"5\n",
"11\n"
] | none | 0 | [
{
"input": "3\n5 6\n1 2",
"output": "5"
},
{
"input": "3\n5 6\n1 3",
"output": "11"
},
{
"input": "2\n55\n1 2",
"output": "55"
},
{
"input": "3\n85 78\n1 3",
"output": "163"
},
{
"input": "4\n63 4 49\n2 3",
"output": "4"
},
{
"input": "5\n93 83 42 56\n... | 1,597,574,856 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 218 | 0 | # import sys
# sys.stdin=open('input.in','r')
# sys.stdout=open('output.out','w')
n=int(input())
years=list(map(int,input().strip().split()[:n-1]))
a,b=map(int,input().strip().split()[:2])
print(sum(years[a-1:b-1])) | Title: Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<... | ```python
# import sys
# sys.stdin=open('input.in','r')
# sys.stdout=open('output.out','w')
n=int(input())
years=list(map(int,input().strip().split()[:n-1]))
a,b=map(int,input().strip().split()[:2])
print(sum(years[a-1:b-1]))
``` | 3.9455 |
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate... | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence... | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15... | 1,699,510,754 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 92 | 0 | n,k=list(map(int,input().split()))
nums=list(map(int,input().split()))
ans=k
if nums[k-1]>0:
for i in range(k,n):
if nums[i]!=nums[k-1]:
break
ans+=1
else:
for i in range(k-1,-1,-1):
if nums[i]==0:
ans-=1
else: break
print(ans)
| Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* p... | ```python
n,k=list(map(int,input().split()))
nums=list(map(int,input().split()))
ans=k
if nums[k-1]>0:
for i in range(k,n):
if nums[i]!=nums[k-1]:
break
ans+=1
else:
for i in range(k-1,-1,-1):
if nums[i]==0:
ans-=1
else: break
print(ans)
``` | 3 | |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,600,085,413 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 3,000 | 7,372,800 | import math
length = int(input())
data = input().split(' ')
data = [int(item) for item in data]
for i in data:
max, min = 0, 99999999999999
for j in data:
if i == j:
continue
temp = abs(i - j)
if max < temp:
max = temp
if min > temp:
... | Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
import math
length = int(input())
data = input().split(' ')
data = [int(item) for item in data]
for i in data:
max, min = 0, 99999999999999
for j in data:
if i == j:
continue
temp = abs(i - j)
if max < temp:
max = temp
if min ... | 0 | |
439 | E | Devu and Birthday Celebration | PROGRAMMING | 2,100 | [
"combinatorics",
"dp",
"math"
] | null | null | Today is Devu's birthday. For celebrating the occasion, he bought *n* sweets from the nearby market. He has invited his *f* friends. He would like to distribute the sweets among them. As he is a nice guy and the occasion is great, he doesn't want any friend to be sad, so he would ensure to give at least one sweet to ea... | The first line contains an integer *q* representing the number of queries (1<=≤<=*q*<=≤<=105). Each of the next *q* lines contains two space space-separated integers *n*, *f* (1<=≤<=*f*<=≤<=*n*<=≤<=105). | For each query, output a single integer in a line corresponding to the answer of each query. | [
"5\n6 2\n7 2\n6 3\n6 4\n7 4\n"
] | [
"2\n6\n9\n10\n20\n"
] | For first query: *n* = 6, *f* = 2. Possible partitions are [1, 5] and [5, 1].
For second query: *n* = 7, *f* = 2. Possible partitions are [1, 6] and [2, 5] and [3, 4] and [4, 3] and [5, 3] and [6, 1]. So in total there are 6 possible ways of partitioning. | 2,500 | [
{
"input": "5\n6 2\n7 2\n6 3\n6 4\n7 4",
"output": "2\n6\n9\n10\n20"
},
{
"input": "10\n1 1\n1 1\n1 1\n7 2\n6 3\n9 5\n4 1\n2 1\n3 1\n2 2",
"output": "1\n1\n1\n6\n9\n70\n0\n0\n0\n1"
},
{
"input": "40\n37 15\n48 10\n16 5\n25 23\n32 20\n24 4\n46 19\n16 13\n1 1\n37 22\n44 29\n24 6\n27 10\n39... | 1,630,740,142 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 498 | 49,254,400 | import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush... | Title: Devu and Birthday Celebration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today is Devu's birthday. For celebrating the occasion, he bought *n* sweets from the nearby market. He has invited his *f* friends. He would like to distribute the sweets among them. As he is a nice guy a... | ```python
import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def... | 0 | |
32 | A | Reconnaissance | PROGRAMMING | 800 | [
"brute force"
] | A. Reconnaissance | 2 | 256 | According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Som... | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 1... | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*. | [
"5 10\n10 20 50 60 65\n",
"5 1\n55 30 29 31 55\n"
] | [
"6\n",
"6\n"
] | none | 500 | [
{
"input": "5 10\n10 20 50 60 65",
"output": "6"
},
{
"input": "5 1\n55 30 29 31 55",
"output": "6"
},
{
"input": "6 10\n4 6 4 1 9 3",
"output": "30"
},
{
"input": "7 100\n19 1694 261 162 1 234 513",
"output": "8"
},
{
"input": "8 42\n37 53 74 187 568 22 5 65",
... | 1,660,887,731 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n, d = list((map(int, input().split())))
a = list((map(int, input().split())))
count = 0
for i in range(len(a)):
for j in range(i, len(a)):
if(abs(a[i] - a[j]) <= d and i = j):
count += 1
elif(abs(a[i] - a[j]) <= d):
count += 2
print(cou... | Title: Reconnaissance
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob h... | ```python
n, d = list((map(int, input().split())))
a = list((map(int, input().split())))
count = 0
for i in range(len(a)):
for j in range(i, len(a)):
if(abs(a[i] - a[j]) <= d and i = j):
count += 1
elif(abs(a[i] - a[j]) <= d):
count += 2
... | -1 |
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th... | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ... | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
... | 1,635,941,911 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,300,800 | s,v1,v2,t1,t2=map(int, input().split())
x=s*v1+2*t1
y=s*v2+2*t2
if x<y:
print("Frist")
if y<x:
print("Second")
if x==y:
print("Friendship") | Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t... | ```python
s,v1,v2,t1,t2=map(int, input().split())
x=s*v1+2*t1
y=s*v2+2*t2
if x<y:
print("Frist")
if y<x:
print("Second")
if x==y:
print("Friendship")
``` | 0 | |
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul... | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{... | 1,688,022,620 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | # Read input
a = int(input())
b = int(input())
c = int(input())
# Calculate different combinations of expressions
expression1 = a + b + c
expression2 = a * b * c
expression3 = a * (b + c)
expression4 = (a + b) * c
# Find the maximum value among the expressions
max_value = max(expression1, expression2, exp... | Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ... | ```python
# Read input
a = int(input())
b = int(input())
c = int(input())
# Calculate different combinations of expressions
expression1 = a + b + c
expression2 = a * b * c
expression3 = a * (b + c)
expression4 = (a + b) * c
# Find the maximum value among the expressions
max_value = max(expression1, expres... | 3 | |
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the numb... | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
... | 1,674,443,135 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 46 | 904 | 31,436,800 | n = int(input())
data = dict()
for i in range(1, n+1):
price , quality = [int(number) for number in input().split()]
data[i] = [price, quality]
sort_by_price = sorted(data.items(), key=lambda laptop: laptop[1][0])
sort_by_quality = sorted(data.items(), key=lambda laptop: laptop[1][1])
if sort_by_... | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the... | ```python
n = int(input())
data = dict()
for i in range(1, n+1):
price , quality = [int(number) for number in input().split()]
data[i] = [price, quality]
sort_by_price = sorted(data.items(), key=lambda laptop: laptop[1][0])
sort_by_quality = sorted(data.items(), key=lambda laptop: laptop[1][1])
i... | 3 | |
16 | A | Flag | PROGRAMMING | 800 | [
"implementation"
] | A. Flag | 2 | 64 | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be... | The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands ... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | [
"3 3\n000\n111\n222\n",
"3 3\n000\n000\n111\n",
"3 3\n000\n111\n002\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 0 | [
{
"input": "3 3\n000\n111\n222",
"output": "YES"
},
{
"input": "3 3\n000\n000\n111",
"output": "NO"
},
{
"input": "3 3\n000\n111\n002",
"output": "NO"
},
{
"input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000... | 1,585,408,774 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 372 | 1,638,400 | r, c = [int(x) for x in input().split()]
list_2 = []
index = 0
previous = -1
for i in range(r):
list_2.append(list(input()))
for i in range(r):
index = list_2[i][0]
for j in range(c):
if index != list_2[i][j] or list_2[i][j]==previous:
print("NO")
exit()
previ... | Title: Flag
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of... | ```python
r, c = [int(x) for x in input().split()]
list_2 = []
index = 0
previous = -1
for i in range(r):
list_2.append(list(input()))
for i in range(r):
index = list_2[i][0]
for j in range(c):
if index != list_2[i][j] or list_2[i][j]==previous:
print("NO")
exit()
... | 3.894793 |
656 | A | Da Vinci Powers | PROGRAMMING | 1,900 | [
"*special"
] | null | null | The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer. | The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). | Output a single integer. | [
"3\n",
"10\n"
] | [
"8\n",
"1024\n"
] | none | 0 | [
{
"input": "3",
"output": "8"
},
{
"input": "10",
"output": "1024"
},
{
"input": "35",
"output": "33940307968"
},
{
"input": "0",
"output": "1"
},
{
"input": "1",
"output": "2"
},
{
"input": "2",
"output": "4"
},
{
"input": "4",
"output... | 1,617,263,877 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 0 | 1,060 | 67,072,000 | n = int(input())
print( int( 2**n - (n>12)*2**(n-13)**100 ))
| Title: Da Vinci Powers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer.
Input Specification:
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output Specification:
Output a single integer.
De... | ```python
n = int(input())
print( int( 2**n - (n>12)*2**(n-13)**100 ))
``` | 0 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,614,876,844 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 124 | 307,200 | x = input()
k = input()
lst = []
lstO = []
cnt = 0
for i in range(len(x)):
lst.append(x[i])
if(lst[i] == 't'):
lst[i] = 's'
else:
pass
lst.reverse()
for i in range(len(x)):
lstO.append((k[i]))
for i in range(0, len(x)):
if(lstO[i] != lst[i]):
print("NO")
... | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
x = input()
k = input()
lst = []
lstO = []
cnt = 0
for i in range(len(x)):
lst.append(x[i])
if(lst[i] == 't'):
lst[i] = 's'
else:
pass
lst.reverse()
for i in range(len(x)):
lstO.append((k[i]))
for i in range(0, len(x)):
if(lstO[i] != lst[i]):
print... | 0 |
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,691,655,495 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 0 | n = int(input())
count_100 = n // 100
n %= 100
count_20 = n // 20
n %= 20
count_10 = n // 10
n %= 10
count_5 = n // 5
n %= 5
count_1 = n
total_bills = count_100 + count_20 + count_10 + count_5 + count_1
print(total_bills)
| 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())
count_100 = n // 100
n %= 100
count_20 = n // 20
n %= 20
count_10 = n // 10
n %= 10
count_5 = n // 5
n %= 5
count_1 = n
total_bills = count_100 + count_20 + count_10 + count_5 + count_1
print(total_bills)
``` | 3 | |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,698,887,366 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 124 | 0 | a = str(input())
b = a.split("+")
c = [int(x) for x in b]
c.sort()
d = '+'.join(map(str, c))
print(d) | Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
a = str(input())
b = a.split("+")
c = [int(x) for x in b]
c.sort()
d = '+'.join(map(str, c))
print(d)
``` | 3 | |
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, al... | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": ... | 1,692,473,337 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 46 | 0 | n=int(input())
if (3*n-1)%4==0:
print(2)
elif (3*n-1)%4==1:
print(4)
elif (3*n-1)%4==2:
print(8)
else:
print(6)
| Title: Arpa’s hard exam and Mehrdad’s naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques... | ```python
n=int(input())
if (3*n-1)%4==0:
print(2)
elif (3*n-1)%4==1:
print(4)
elif (3*n-1)%4==2:
print(8)
else:
print(6)
``` | 0 | |
798 | A | Mike and palindrome | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"strings"
] | null | null | Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codefo... | The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15). | Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. | [
"abccaa\n",
"abbcca\n",
"abcda\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "abccaa",
"output": "YES"
},
{
"input": "abbcca",
"output": "NO"
},
{
"input": "abcda",
"output": "YES"
},
{
"input": "kyw",
"output": "YES"
},
{
"input": "fccf",
"output": "NO"
},
{
"input": "mnlm",
"output": "YES"
},
{
"input":... | 1,642,005,502 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | # -*- coding: utf-8 -*-
"""PSAT_assignemnt-5_C_Mike_and_Palindrome.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1ufF9rMcXbcqVpnsBiybAgDmPMAV7m340
"""
text=input()
n=len(text)
text_diff_cnt=0
for i in range(n//2):
if(text[i] != text[(n-1)-i])... | Title: Mike and palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same ... | ```python
# -*- coding: utf-8 -*-
"""PSAT_assignemnt-5_C_Mike_and_Palindrome.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1ufF9rMcXbcqVpnsBiybAgDmPMAV7m340
"""
text=input()
n=len(text)
text_diff_cnt=0
for i in range(n//2):
if(text[i] != text... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an *h*<=×<=*w* field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only some of them are black. Currently Gerald is finishing a game ... | The first line of the input contains three integers: *h*,<=*w*,<=*n* — the sides of the board and the number of black cells (1<=≤<=*h*,<=*w*<=≤<=105,<=1<=≤<=*n*<=≤<=2000).
Next *n* lines contain the description of black cells. The *i*-th of these lines contains numbers *r**i*,<=*c**i* (1<=≤<=*r**i*<=≤<=*h*,<=1<=≤<=*c... | Print a single line — the remainder of the number of ways to move Gerald's pawn from the upper left to the lower right corner modulo 109<=+<=7. | [
"3 4 2\n2 2\n2 3\n",
"100 100 3\n15 16\n16 15\n99 88\n"
] | [
"2\n",
"545732279\n"
] | none | 0 | [
{
"input": "3 4 2\n2 2\n2 3",
"output": "2"
},
{
"input": "100 100 3\n15 16\n16 15\n99 88",
"output": "545732279"
},
{
"input": "1000 1000 4\n50 50\n51 50\n50 51\n51 51",
"output": "899660737"
},
{
"input": "100000 100000 4\n50001 50001\n50000 50000\n50000 50001\n50001 50000"... | 1,532,881,690 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 226,816,000 | import operator
def choose(n, k):
x = [[0 for _ in range(k + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, k + 1):
if i == 1 or i <= j:
x[i][j] = 1
elif j == 0:
x[i][j] = 1
elif j == 1:
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an *h*<=×<=*w* field, and it is painted in two colors, but not like in chess. Almost all cells of ... | ```python
import operator
def choose(n, k):
x = [[0 for _ in range(k + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, k + 1):
if i == 1 or i <= j:
x[i][j] = 1
elif j == 0:
x[i][j] = 1
elif j == 1:
... | 0 | |
837 | A | Text Volume | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. | Print one integer number — volume of text. | [
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] | [
"5\n",
"0\n",
"1\n"
] | In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | 0 | [
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd... | 1,503,208,679 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | import sys
def main ():
nbm = 0
nbc = sys.stdin.readline()
chaine = list(sys.stdin.readline())
for loop in range(int(nbc)):
if chaine[loop].isupper():
nbm += 1
print(nbm)
main() | Title: Text Volume
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex... | ```python
import sys
def main ():
nbm = 0
nbc = sys.stdin.readline()
chaine = list(sys.stdin.readline())
for loop in range(int(nbc)):
if chaine[loop].isupper():
nbm += 1
print(nbm)
main()
``` | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,571,991,289 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 124 | 0 | string = input()
li = list(string)
without = []
for letter in li:
if letter != 'h' and letter != 'e' and letter != 'l' and letter != 'o':
without.append(letter)
for l_etter in without:
li.remove(l_etter)
#print(li)
h = li.index('h')
e = li.index('e')
l = li.index('l')
o = li.index('o')
#pri... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
string = input()
li = list(string)
without = []
for letter in li:
if letter != 'h' and letter != 'e' and letter != 'l' and letter != 'o':
without.append(letter)
for l_etter in without:
li.remove(l_etter)
#print(li)
h = li.index('h')
e = li.index('e')
l = li.index('l')
o = li.index(... | 0 |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,694,162,435 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | a_ris = list(map(int, input().split()))
a_ris.sort(reverse = True)
if a_ris[2] + a_ris[1] > a_ris[0] or a_ris[3] + a_ris[2] > a_ris[1]:
print("Triangle")
elif a_ris[2] + a_ris[1] == a_ris[0] or a_ris[3] + a_ris[2] == a_ris[1]:
print("SEGMENT")
else:
print("Impossible")
"""
from math import*
x = [True] * 1... | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
a_ris = list(map(int, input().split()))
a_ris.sort(reverse = True)
if a_ris[2] + a_ris[1] > a_ris[0] or a_ris[3] + a_ris[2] > a_ris[1]:
print("Triangle")
elif a_ris[2] + a_ris[1] == a_ris[0] or a_ris[3] + a_ris[2] == a_ris[1]:
print("SEGMENT")
else:
print("Impossible")
"""
from math import*
x = ... | 0 |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,680,126,968 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | a = 6
b = 3
c = a
def rec(a, b, c):
if a//b == 1:
return c+a+1
elif a//b ==0:
return c+a
else:
a=a//b+a%b
return rec(a, b, c)
print(rec(a,b,c))
| Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
a = 6
b = 3
c = a
def rec(a, b, c):
if a//b == 1:
return c+a+1
elif a//b ==0:
return c+a
else:
a=a//b+a%b
return rec(a, b, c)
print(rec(a,b,c))
``` | 0 | |
284 | B | Cows and Poker Game | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | There are *n* cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any be... | The first line contains a single integer, *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* characters, each either "A", "I", or "F". The *i*-th character is "A" if the *i*-th player's status is "ALLIN", "I" if the *i*-th player's status is "IN", or "F" if the *i*-th player's status is "FOLDED". | The first line should contain a single integer denoting the number of players that can currently show their hands. | [
"6\nAFFAAA\n",
"3\nAFI\n"
] | [
"4\n",
"1\n"
] | In the first sample, cows 1, 4, 5, and 6 can show their hands. In the second sample, only cow 3 can show her hand. | 1,000 | [
{
"input": "6\nAFFAAA",
"output": "4"
},
{
"input": "3\nAFI",
"output": "1"
},
{
"input": "3\nFFF",
"output": "0"
},
{
"input": "3\nFIF",
"output": "1"
},
{
"input": "3\nAAA",
"output": "3"
},
{
"input": "3\nIII",
"output": "0"
},
{
"input"... | 1,612,265,995 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | n = int(input())
s=input()
c=0
if s>count("I")==1:
print(1)
elif s>count("I")>=2:
print(0)
else:
print(s.count("A"))
| Title: Cows and Poker Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player who... | ```python
n = int(input())
s=input()
c=0
if s>count("I")==1:
print(1)
elif s>count("I")>=2:
print(0)
else:
print(s.count("A"))
``` | -1 | |
3 | C | Tic-tac-toe | PROGRAMMING | 1,800 | [
"brute force",
"games",
"implementation"
] | C. Tic-tac-toe | 1 | 64 | Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the... | The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero). | Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw. | [
"X0X\n.0.\n.X.\n"
] | [
"second\n"
] | none | 0 | [
{
"input": "X0X\n.0.\n.X.",
"output": "second"
},
{
"input": "0.X\nXX.\n000",
"output": "illegal"
},
{
"input": "XXX\n.0.\n000",
"output": "illegal"
},
{
"input": "XXX\n...\n000",
"output": "illegal"
},
{
"input": "X.X\nX..\n00.",
"output": "second"
},
{
... | 1,575,226,876 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 216 | 307,200 | x = input()
y = input()
z = input()
x_count = x.count('X') + y.count('X') + z.count('X')
o_count = x.count('0') + y.count('0') + z.count('0')
dot_count = x.count('.') + y.count('.') + z.count('.')
if x_count + o_count + dot_count != 9:
print('illegal')
exit()
if dot_count == 9:
print('first')
... | Title: Tic-tac-toe
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds ... | ```python
x = input()
y = input()
z = input()
x_count = x.count('X') + y.count('X') + z.count('X')
o_count = x.count('0') + y.count('0') + z.count('0')
dot_count = x.count('.') + y.count('.') + z.count('.')
if x_count + o_count + dot_count != 9:
print('illegal')
exit()
if dot_count == 9:
print('fi... | 0 |
312 | B | Archer | PROGRAMMING | 1,300 | [
"math",
"probabilities"
] | null | null | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will... | A single line contains four integers . | Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"1 2 1 2\n"
] | [
"0.666666666667"
] | none | 1,000 | [
{
"input": "1 2 1 2",
"output": "0.666666666667"
},
{
"input": "1 3 1 3",
"output": "0.600000000000"
},
{
"input": "1 3 2 3",
"output": "0.428571428571"
},
{
"input": "3 4 3 4",
"output": "0.800000000000"
},
{
"input": "1 2 10 11",
"output": "0.523809523810"
... | 1,678,728,129 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | a, b, c, d = map(int, input().split())
p1 = a / float(b)
p2 = c / float(d)
q1 = 1 - p1
q2 = 1 - p2
prob1 = p1 * (1 / (1 - q1))
prob2 = p2 * (q2 / (1 - q2))
print(prob1 / (prob2 + prob1)) | Title: Archer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one w... | ```python
a, b, c, d = map(int, input().split())
p1 = a / float(b)
p2 = c / float(d)
q1 = 1 - p1
q2 = 1 - p2
prob1 = p1 * (1 / (1 - q1))
prob2 = p2 * (q2 / (1 - q2))
print(prob1 / (prob2 + prob1))
``` | 0 | |
300 | A | Array | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The produ... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. | In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second... | [
"3\n-1 2 0\n",
"4\n-1 -2 -3 0\n"
] | [
"1 -1\n1 2\n1 0\n",
"1 -1\n2 -3 -2\n1 0\n"
] | none | 500 | [
{
"input": "3\n-1 2 0",
"output": "1 -1\n1 2\n1 0"
},
{
"input": "4\n-1 -2 -3 0",
"output": "1 -1\n2 -3 -2\n1 0"
},
{
"input": "5\n-1 -2 1 2 0",
"output": "1 -1\n2 1 2\n2 0 -2"
},
{
"input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -1... | 1,670,836,667 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 156 | 0 | n=int(input())
nums=list(map(int,input().split()))
third=-1
first=-1
count=0
minus=[0]*2
for i,item in enumerate(nums):
if item ==0:
if third==-1:
third=i
if item <0:
count+=1
if minus[-1]==0:
minus[-1]=i
else:
minus[0],minus[1]=... | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. T... | ```python
n=int(input())
nums=list(map(int,input().split()))
third=-1
first=-1
count=0
minus=[0]*2
for i,item in enumerate(nums):
if item ==0:
if third==-1:
third=i
if item <0:
count+=1
if minus[-1]==0:
minus[-1]=i
else:
minus[0]... | 0 | |
887 | A | Div. 64 | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisi... | In the only line given a non-empty binary string *s* with length up to 100. | Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise. | [
"100010001\n",
"100\n"
] | [
"yes",
"no"
] | In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system) | 500 | [
{
"input": "100010001",
"output": "yes"
},
{
"input": "100",
"output": "no"
},
{
"input": "0000001000000",
"output": "yes"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "no"
},
{
"in... | 1,536,781,846 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | s=input()
if(len(s)<=6):
print('no')
else:
for i in range(6,len(s)):
if(s[i]=='1'):
print('yes')
exit()
print('no') | Title: Div. 64
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some dig... | ```python
s=input()
if(len(s)<=6):
print('no')
else:
for i in range(6,len(s)):
if(s[i]=='1'):
print('yes')
exit()
print('no')
``` | 0 | |
907 | A | Masha and Bears | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg... | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 500 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"... | 1,593,179,798 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 6,656,000 | v1,v2,v3,vm = map(int, input().split())
if(2*v3 >= vm):
v1= max(v1,vm)
v2= max(v2,vm)
v3= max(v3,vm)
if(v1>v2 and v2>v3):
print(v1)
print(v2)
print(v3)
else:
print(-1)
else:
print(-1)
| Title: Masha and Bears
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son b... | ```python
v1,v2,v3,vm = map(int, input().split())
if(2*v3 >= vm):
v1= max(v1,vm)
v2= max(v2,vm)
v3= max(v3,vm)
if(v1>v2 and v2>v3):
print(v1)
print(v2)
print(v3)
else:
print(-1)
else:
print(-1)
``` | 0 | |
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,635,189,436 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 4,300,800 | import math
a,b =input().split(" ")
a=int(a)
b=int(b)
print(math.gcd(a,b))
| 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
import math
a,b =input().split(" ")
a=int(a)
b=int(b)
print(math.gcd(a,b))
``` | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,661,179,722 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 0 | n=int(input())
arr=list(map(int,input().split()))
ev=[]
od=[]
for i in range(n):
if(arr[i]%2==0):
ev.append(i+1)
else:
od.append(i+1)
if(len(ev)==1):
print(ev[0])
else:
print(od[0]) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n=int(input())
arr=list(map(int,input().split()))
ev=[]
od=[]
for i in range(n):
if(arr[i]%2==0):
ev.append(i+1)
else:
od.append(i+1)
if(len(ev)==1):
print(ev[0])
else:
print(od[0])
``` | 3.977 |
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"ou... | 1,636,389,767 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 4,505,600 |
import math
from math import gcd
def fact(n):
f = 1
while n!=1:
f = f*n
n = n-1
return f
A = int(input())
B = int(input())
fact_A = fact(A)
fact_B = fact(B)
result = gcd(fact_A,fact_B)
print(result)
| Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi... | ```python
import math
from math import gcd
def fact(n):
f = 1
while n!=1:
f = f*n
n = n-1
return f
A = int(input())
B = int(input())
fact_A = fact(A)
fact_B = fact(B)
result = gcd(fact_A,fact_B)
print(result)
``` | -1 | |
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,662,532,809 | 2,147,483,647 | PyPy 3 | OK | TESTS | 80 | 186 | 0 | import math
N = int(input())
H = list(map(int, input().split()))
ascender = []
descender = []
prev = math.inf
for index, value in enumerate(H):
ascender.append(ascender[index - 1] + 1 if value >= prev else 0)
prev = value
prev = math.inf
for index, value in enumerate(H[::-1]):
descender.a... | 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
import math
N = int(input())
H = list(map(int, input().split()))
ascender = []
descender = []
prev = math.inf
for index, value in enumerate(H):
ascender.append(ascender[index - 1] + 1 if value >= prev else 0)
prev = value
prev = math.inf
for index, value in enumerate(H[::-1]):
d... | 3.9535 |
441 | A | Valera and Antique Items | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfec... | The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has.
Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space... | In the first line, print integer *p* — the number of sellers with who Valera can make a deal.
In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order. | [
"3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n",
"3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n"
] | [
"3\n1 2 3\n",
"0\n\n"
] | In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.
In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the... | 500 | [
{
"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000",
"output": "3\n1 2 3"
},
{
"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000",
"output": "0"
},
{
"input": "2 100001\n1 895737\n1 541571",
"output": "0"
},
{
"input": "1 1000000\n1 100... | 1,546,879,829 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | n, v = map(int, input().split())
find = False
for i in range(n):
l = list(map(int, input().split()))
if min(l[1:]) < v:
print(i+1, end=' ')
find = True
if not find:
print(0)
| Title: Valera and Antique Items
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the... | ```python
n, v = map(int, input().split())
find = False
for i in range(n):
l = list(map(int, input().split()))
if min(l[1:]) < v:
print(i+1, end=' ')
find = True
if not find:
print(0)
``` | 0 | |
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea... | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n... | 1,672,431,280 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 184 | 0 | from itertools import permutations
teams = []; count = 0
for _ in range(int(input())):
teams.append(input().split())
for match in permutations(teams, 2):
count += 1 if match[0][0] == match[-1][-1] else 0
print(count) | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W... | ```python
from itertools import permutations
teams = []; count = 0
for _ in range(int(input())):
teams.append(input().split())
for match in permutations(teams, 2):
count += 1 if match[0][0] == match[-1][-1] else 0
print(count)
``` | 3 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,681,495,627 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 122 | 0 | #F
user=input()
cnt=0
for i in range(6,len(user)):
if user[i-6:i+1]=="0000000" or user[i-6:i+1]=="1111111":
cnt+=1
if cnt==0:
print("NO")
else:
print("YES")
| 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
#F
user=input()
cnt=0
for i in range(6,len(user)):
if user[i-6:i+1]=="0000000" or user[i-6:i+1]=="1111111":
cnt+=1
if cnt==0:
print("NO")
else:
print("YES")
``` | 3.9695 |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,695,569,672 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 184 | 0 | # Read input
n = int(input())
heights = list(map(int, input().split()))
# Initialize the variables to keep track of the minimum number of seconds
# needed to form a line-up that the general will like.
min_seconds = 0
# Iterate through the list of heights from both ends simultaneously.
# Compare the heights o... | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
# Read input
n = int(input())
heights = list(map(int, input().split()))
# Initialize the variables to keep track of the minimum number of seconds
# needed to form a line-up that the general will like.
min_seconds = 0
# Iterate through the list of heights from both ends simultaneously.
# Compare the... | 0 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,574,684,488 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | def main():
n1=int(input(),2)
n2=int(input(),2)
ans=n1^n2
ans="{0:b}".format(ans)
print(ans)
if __name__ == '__main__':
main() | 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
def main():
n1=int(input(),2)
n2=int(input(),2)
ans=n1^n2
ans="{0:b}".format(ans)
print(ans)
if __name__ == '__main__':
main()
``` | 0 |
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 ... | 1,508,813,487 | 387 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
void Print()
{
cout << endl;
}
template<typename T1, typename ... T>
void Print(const T1 &t1, const T& ... t)
{
cout << t1 << " ";
Print(t...);
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &... | Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the... | ```python
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
void Print()
{
cout << endl;
}
template<typename T1, typename ... T>
void Print(const T1 &t1, const T& ... t)
{
cout << t1 << " ";
Print(t...);
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair... | -1 | |
449 | A | Jzzhu and Chocolate | PROGRAMMING | 1,700 | [
"greedy",
"math"
] | null | null | Jzzhu has a big rectangular chocolate bar that consists of *n*<=×<=*m* unit squares. He wants to cut this bar exactly *k* times. Each cut must meet the following requirements:
- each cut should be straight (horizontal or vertical); - each cut should go along edges of unit squares (it is prohibited to divide any unit... | A single line contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=109; 1<=≤<=*k*<=≤<=2·109). | Output a single integer representing the answer. If it is impossible to cut the big chocolate *k* times, print -1. | [
"3 4 1\n",
"6 4 2\n",
"2 3 4\n"
] | [
"6\n",
"8\n",
"-1\n"
] | In the first sample, Jzzhu can cut the chocolate following the picture below:
In the second sample the optimal division looks like this:
In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times. | 500 | [
{
"input": "3 4 1",
"output": "6"
},
{
"input": "6 4 2",
"output": "8"
},
{
"input": "2 3 4",
"output": "-1"
},
{
"input": "10 10 2",
"output": "30"
},
{
"input": "1000000000 1000000000 2000000000",
"output": "-1"
},
{
"input": "1000000000 1000000000 9... | 1,405,947,930 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | def split(m,n,k):
if m%(k+1) == 0:
return n*(m//(k+1))
elif n%(k+1) == 0:
return m*(n//(k+1))
if k <= min(m,n):
return (m*n)//(max(m,n)//(k+1))
else:
k2 = k - (min(m,n) - 1)
return max(m,n) // (k2+1)
args = input().split()
print(split(*map(int, args)))
| Title: Jzzhu and Chocolate
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jzzhu has a big rectangular chocolate bar that consists of *n*<=×<=*m* unit squares. He wants to cut this bar exactly *k* times. Each cut must meet the following requirements:
- each cut should be straight (horizo... | ```python
def split(m,n,k):
if m%(k+1) == 0:
return n*(m//(k+1))
elif n%(k+1) == 0:
return m*(n//(k+1))
if k <= min(m,n):
return (m*n)//(max(m,n)//(k+1))
else:
k2 = k - (min(m,n) - 1)
return max(m,n) // (k2+1)
args = input().split()
print(split(*map(int, args)))
``` | 0 | |
296 | A | Yaroslav and Permutations | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | 500 | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 53... | 1,697,726,269 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 156 | 0 | from sys import stdin,stdout
#input = stdin.readline
def main():
#t = int(input())
t = 1
for z in range(t):
n = int(input())
#a,b,c = map(int,input().split())
ai = list(map(int,input().split()))
n2 = (n+1) // 2
ar = [0]*1001
for i in ai:
... | Title: Yaroslav and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would... | ```python
from sys import stdin,stdout
#input = stdin.readline
def main():
#t = int(input())
t = 1
for z in range(t):
n = int(input())
#a,b,c = map(int,input().split())
ai = list(map(int,input().split()))
n2 = (n+1) // 2
ar = [0]*1001
for i in ai:... | 3 | |
353 | A | Domino | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half... | Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. | [
"2\n4 2\n6 4\n",
"1\n2 3\n",
"3\n1 4\n2 3\n4 4\n"
] | [
"0\n",
"-1\n",
"1\n"
] | In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the... | 500 | [
{
"input": "2\n4 2\n6 4",
"output": "0"
},
{
"input": "1\n2 3",
"output": "-1"
},
{
"input": "3\n1 4\n2 3\n4 4",
"output": "1"
},
{
"input": "5\n5 4\n5 4\n1 5\n5 5\n3 3",
"output": "1"
},
{
"input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n... | 1,567,102,613 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 22 | 280 | 1,228,800 | n=int(input())
x=[]
y=[]
for i in range(n):
a,b=map(int,input().split())
x.append(a)
y.append(b)
f=0
count=0
def ch(x,y):
return (sum(x)%2==0 and sum(y)%2==0)
if ch(x,y):
print(0)
else:
f=0
for i in range(n):
f=0
x[i],y[i]=y[i],x[i]
count+=1
... | Title: Domino
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the n... | ```python
n=int(input())
x=[]
y=[]
for i in range(n):
a,b=map(int,input().split())
x.append(a)
y.append(b)
f=0
count=0
def ch(x,y):
return (sum(x)%2==0 and sum(y)%2==0)
if ch(x,y):
print(0)
else:
f=0
for i in range(n):
f=0
x[i],y[i]=y[i],x[i]
count... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*.
Your task is to find such permutation *p* of length *n*, that the group of number... | The single line of the input contains two space-separated positive integers *n*, *k* (1<=≤<=*k*<=<<=*n*<=≤<=105). | Print *n* integers forming the permutation. If there are multiple answers, print any of them. | [
"3 2\n",
"3 1\n",
"5 2\n"
] | [
"1 3 2\n",
"1 2 3\n",
"1 3 2 4 5\n"
] | By |*x*| we denote the absolute value of number *x*. | 0 | [
{
"input": "3 2",
"output": "1 3 2"
},
{
"input": "3 1",
"output": "1 2 3"
},
{
"input": "5 2",
"output": "1 3 2 4 5"
},
{
"input": "5 4",
"output": "1 5 2 4 3"
},
{
"input": "10 4",
"output": "1 10 2 9 8 7 6 5 4 3"
},
{
"input": "10 3",
"output": ... | 1,414,174,295 | 4,295 | Python 3 | WRONG_ANSWER | PRETESTS | 6 | 62 | 0 | from sys import stdin
lines = list(filter(None, stdin.read().split('\n')))
def parseline(line):
return list(map(int, line.split()))
lines = list(map(parseline, lines))
n, k = lines[0]
x = n + 1
for i in range(n, n - k, -1):
if 1 <= x + i <= n:
x = x + i
else:
x = x - i
print(x, end=' ')
step = -1 if k %2 =... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=... | ```python
from sys import stdin
lines = list(filter(None, stdin.read().split('\n')))
def parseline(line):
return list(map(int, line.split()))
lines = list(map(parseline, lines))
n, k = lines[0]
x = n + 1
for i in range(n, n - k, -1):
if 1 <= x + i <= n:
x = x + i
else:
x = x - i
print(x, end=' ')
step = -1... | 0 | |
94 | B | Friends | PROGRAMMING | 1,300 | [
"graphs",
"implementation",
"math"
] | B. Friends | 1 | 256 | One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something.
The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people"
Igor just c... | The first line contains an integer *m* (0<=≤<=*m*<=≤<=10), which is the number of relations of acquaintances among the five friends of Igor's.
Each of the following *m* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=5;*a**i*<=≠<=*b**i*), where (*a**i*,<=*b**i*) is a pair of acquainted people.... | Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". | [
"4\n1 3\n2 3\n1 4\n5 3\n",
"5\n1 2\n2 3\n3 4\n4 5\n5 1\n"
] | [
"WIN\n",
"FAIL\n"
] | none | 1,000 | [
{
"input": "4\n1 3\n2 3\n1 4\n5 3",
"output": "WIN"
},
{
"input": "5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "FAIL"
},
{
"input": "1\n4 3",
"output": "WIN"
},
{
"input": "6\n1 3\n2 3\n1 2\n5 3\n4 2\n4 5",
"output": "WIN"
},
{
"input": "2\n1 3\n2 5",
"output": "WI... | 1,658,002,856 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 85 | 62 | 0 |
import sys
input = sys.stdin.readline
n = int(input())
d = [0]*5
for i in range(n):
a, b = map(int, input().split())
d[a-1] += 1
d[b-1] += 1
if d.count(2) == 5:
print('FAIL')
else:
print('WIN')
| Title: Friends
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something.
The following statement caught his attention: "Among any six people there are ei... | ```python
import sys
input = sys.stdin.readline
n = int(input())
d = [0]*5
for i in range(n):
a, b = map(int, input().split())
d[a-1] += 1
d[b-1] += 1
if d.count(2) == 5:
print('FAIL')
else:
print('WIN')
``` | 3.969 |
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,634,755,567 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 4,505,600 | n=int(input())
l=[]
t=[]
for i in range(n):
t=list(map(int,input().split()))
if(i==0):
l=t
else:
for j in range(3):
l[i]=l[i]+t[i]
if(l[0] or l[1] or l[2]):
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
n=int(input())
l=[]
t=[]
for i in range(n):
t=list(map(int,input().split()))
if(i==0):
l=t
else:
for j in range(3):
l[i]=l[i]+t[i]
if(l[0] or l[1] or l[2]):
print("NO")
else:
print("YES")
``` | 0 |
137 | B | Permutation | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is cal... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). | Print the only number — the minimum number of changes needed to get the permutation. | [
"3\n3 1 2\n",
"2\n2 2\n",
"5\n5 3 3 3 1\n"
] | [
"0\n",
"1\n",
"2\n"
] | The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with... | 1,000 | [
{
"input": "3\n3 1 2",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "2"
},
{
"input": "5\n6 6 6 6 6",
"output": "5"
},
{
"input": "10\n1 1 2 2 8 8 7 7 9 9",
"output": "5"
},
{
"input": "8\n9 8 7 6 5 4 3 2"... | 1,449,443,764 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 124 | 307,200 | n = int(input())
count = (n + 1) * [ 0 ]
for a in map(int, input().split()):
if a <= n:
count[a] += 1
result = 0
for a in count[1:(n + 1)]:
if a == 0:
result += 1
print(result)
| Title: Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task ... | ```python
n = int(input())
count = (n + 1) * [ 0 ]
for a in map(int, input().split()):
if a <= n:
count[a] += 1
result = 0
for a in count[1:(n + 1)]:
if a == 0:
result += 1
print(result)
``` | 3 | |
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894"... | 1,605,354,006 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | # https://codeforces.com/problemset/problem/678/A
n, k = map(int, input().split())
x = n % k
if x != 0:
print(k - x)
else:
print(n + k)
| Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *... | ```python
# https://codeforces.com/problemset/problem/678/A
n, k = map(int, input().split())
x = n % k
if x != 0:
print(k - x)
else:
print(n + k)
``` | 0 | |
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy start... | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second lin... | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fanta... | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
... | 1,413,138,403 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 186 | 307,200 | n = input()
a = input()
b = input()
m = n[::-1]
i = n.find(a)
x = False
if i != -1 :
n = n[i+len(a)::1]
j = n.find(b)
if j != -1 :
x = True
i = m.find(a)
y = False
if i != -1 :
m = m[i+len(a)::1]
j = m.find(b)
if j != -1 :
y = True
if x and y :
print('both')
elif x :
pr... | Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the... | ```python
n = input()
a = input()
b = input()
m = n[::-1]
i = n.find(a)
x = False
if i != -1 :
n = n[i+len(a)::1]
j = n.find(b)
if j != -1 :
x = True
i = m.find(a)
y = False
if i != -1 :
m = m[i+len(a)::1]
j = m.find(b)
if j != -1 :
y = True
if x and y :
print('both')
elif ... | 3.904711 |
590 | A | Median Smoothing | PROGRAMMING | 1,700 | [
"implementation"
] | null | null | A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and engineering. Vasya liked the idea of the method very much, and he decided to try it in practi... | The first input line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=500<=000) — the length of the initial sequence.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=0 or *a**i*<==<=1), giving the initial sequence itself. | If the sequence will never become stable, print a single number <=-<=1.
Otherwise, first print a single integer — the minimum number of times one needs to apply the median smoothing algorithm to the initial sequence before it becomes is stable. In the second line print *n* numbers separated by a space — the resulting... | [
"4\n0 0 1 1\n",
"5\n0 1 0 1 0\n"
] | [
"0\n0 0 1 1\n",
"2\n0 0 0 0 0\n"
] | In the second sample the stabilization occurs in two steps: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5a983e7baab048cbe43812cb997c15e9d7100231.png" style="max-width: 100.0%;max-height: 100.0%;"/>, and the sequence 00000 is obviously stable. | 750 | [
{
"input": "4\n0 0 1 1",
"output": "0\n0 0 1 1"
},
{
"input": "5\n0 1 0 1 0",
"output": "2\n0 0 0 0 0"
},
{
"input": "3\n1 0 0",
"output": "0\n1 0 0"
},
{
"input": "4\n1 0 0 1",
"output": "0\n1 0 0 1"
},
{
"input": "7\n1 0 1 1 1 0 1",
"output": "1\n1 1 1 1 1 1... | 1,473,737,983 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | I=input
n=int(I())
a=I()
print(['0\n'+a,str(a.count('01'[a[0]<'1']))+'\n'+(a[0]+' ')*n][a[0]==a[-1]]) | Title: Median Smoothing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in sci... | ```python
I=input
n=int(I())
a=I()
print(['0\n'+a,str(a.count('01'[a[0]<'1']))+'\n'+(a[0]+' ')*n][a[0]==a[-1]])
``` | 0 | |
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul... | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter t... | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input":... | 1,663,459,069 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | check = []
counter = 0
for i in range(0 , 3):
x = input().split('>')
if len(x) == 1:
x = x[0].split('<')
arr[index[x[1]]]['count'] += 1
else :
arr[index[x[0]]]['count'] += 1
def value(key) :
return key['count']
arr.sort(key=value)
for i in arr :
if not i['count... | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ... | ```python
check = []
counter = 0
for i in range(0 , 3):
x = input().split('>')
if len(x) == 1:
x = x[0].split('<')
arr[index[x[1]]]['count'] += 1
else :
arr[index[x[0]]]['count'] += 1
def value(key) :
return key['count']
arr.sort(key=value)
for i in arr :
if no... | -1 |
845 | C | Two TVs | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at a... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of shows.
Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=109) — starting and ending time of *i*-th show. | If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes). | [
"3\n1 2\n2 3\n4 5\n",
"4\n1 2\n2 3\n2 3\n1 2\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 2\n2 3\n4 5",
"output": "YES"
},
{
"input": "4\n1 2\n2 3\n2 3\n1 2",
"output": "NO"
},
{
"input": "4\n0 1\n1 2\n2 3\n3 4",
"output": "YES"
},
{
"input": "3\n1 2\n2 3\n2 4",
"output": "NO"
},
{
"input": "3\n0 100\n0 100\n0 100",
"output": "NO"
... | 1,588,065,642 | 2,147,483,647 | PyPy 3 | OK | TESTS | 58 | 748 | 16,076,800 | import io, os
import sys
from atexit import register
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.stdout = io.BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
tokens = []
tokens_next = 0
def nextStr():
global tokens, tokens_next
while tokens_next >= len(tokens... | Title: Two TVs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He ... | ```python
import io, os
import sys
from atexit import register
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.stdout = io.BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
tokens = []
tokens_next = 0
def nextStr():
global tokens, tokens_next
while tokens_next >= ... | 3 | |
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,591,055,747 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 0 | x = int(input())
for i in range(x):
y=int(input())
z=int(input())
print(1) | 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
x = int(input())
for i in range(x):
y=int(input())
z=int(input())
print(1)
``` | -1 | |
912 | B | New Year's Eve | PROGRAMMING | 1,300 | [
"bitmasks",
"constructive algorithms",
"number theory"
] | null | null | Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a d... | The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018). | Output one number — the largest possible xor-sum. | [
"4 3\n",
"6 6\n"
] | [
"7\n",
"7\n"
] | In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.
In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7. | 1,000 | [
{
"input": "4 3",
"output": "7"
},
{
"input": "6 6",
"output": "7"
},
{
"input": "2 2",
"output": "3"
},
{
"input": "1022 10",
"output": "1023"
},
{
"input": "415853337373441 52",
"output": "562949953421311"
},
{
"input": "75 12",
"output": "127"
... | 1,522,249,725 | 1,005 | Python 3 | OK | TESTS | 58 | 93 | 7,372,800 | n, k = map(int, input().split(' '))
if k == 1:
print(n)
else:
powered = 2
while powered <= n:
powered *= 2
print(powered-1)
| Title: New Year's Eve
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* co... | ```python
n, k = map(int, input().split(' '))
if k == 1:
print(n)
else:
powered = 2
while powered <= n:
powered *= 2
print(powered-1)
``` | 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,608,973 | 2,147,483,647 | Python 3 | OK | TESTS | 73 | 77 | 5,632,000 | my_dict = {'o' : '0', 'l' : '1', 'i' : '1'}
pas = input().lower()
new_pas = ''
for x in pas:
if x in my_dict:
new_pas += my_dict[x]
else:
new_pas += x
n = int(input())
cnt = 0
for i in range(n):
pas_now = input().lower()
new_pas_now = ''
for x in pas_now:
if x i... | 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
my_dict = {'o' : '0', 'l' : '1', 'i' : '1'}
pas = input().lower()
new_pas = ''
for x in pas:
if x in my_dict:
new_pas += my_dict[x]
else:
new_pas += x
n = int(input())
cnt = 0
for i in range(n):
pas_now = input().lower()
new_pas_now = ''
for x in pas_now:
... | 3 | |
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,698,156,355 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 10 | 46 | 0 | num = input()
answ = int("".join((num[i] for i in [0,2,4,3,1])))
answ = str(answ**5)
print(answ[-5:])# 1698156355.2098389 | 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
num = input()
answ = int("".join((num[i] for i in [0,2,4,3,1])))
answ = str(answ**5)
print(answ[-5:])# 1698156355.2098389
``` | 3 | |
845 | B | Luba And The Ticket | PROGRAMMING | 1,600 | [
"brute force",
"greedy",
"implementation"
] | null | null | Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of las... | You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0. | Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky. | [
"000000\n",
"123456\n",
"111000\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one re... | 0 | [
{
"input": "000000",
"output": "0"
},
{
"input": "123456",
"output": "2"
},
{
"input": "111000",
"output": "1"
},
{
"input": "120111",
"output": "0"
},
{
"input": "999999",
"output": "0"
},
{
"input": "199880",
"output": "1"
},
{
"input": "... | 1,662,670,732 | 2,147,483,647 | Python 3 | OK | TESTS | 145 | 1,341 | 0 | x=int(input())
def s(a):
r=0
while a>0:
r+=a%10
a//=10
return r
def d(a,b):
r=0
for i in range(6):
if a%10!=b%10:
r += 1
a//=10
b//=10
return r
c=6
for i in range(1000000):
if s(i%1000)==s(i//1000):
c=min(c,d(x,i))
print(c)
| Title: Luba And The Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make th... | ```python
x=int(input())
def s(a):
r=0
while a>0:
r+=a%10
a//=10
return r
def d(a,b):
r=0
for i in range(6):
if a%10!=b%10:
r += 1
a//=10
b//=10
return r
c=6
for i in range(1000000):
if s(i%1000)==s(i//1000):
c=min(c,d(x,i))
print(c)
``` | 3 | |
884 | D | Boxes And Balls | PROGRAMMING | 2,300 | [
"data structures",
"greedy"
] | null | null | Ivan has *n* different boxes. The first of them contains some balls of *n* different colors.
Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≤<=*i*<=≤<=*n*) *i*-th box will contain all balls with color *i*.
In order to do this, Ivan will make some tu... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200000) — the number of boxes and colors.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of balls with color *i*. | Print one number — the minimum possible penalty of the game. | [
"3\n1 2 3\n",
"4\n2 3 4 5\n"
] | [
"6\n",
"19\n"
] | In the first example you take all the balls from the first box, choose *k* = 3 and sort all colors to corresponding boxes. Penalty is 6.
In the second example you make two turns:
1. Take all the balls from the first box, choose *k* = 3, put balls of color 3 to the third box, of color 4 — to the fourth box and the r... | 0 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "4\n2 3 4 5",
"output": "19"
},
{
"input": "6\n1 4 4 4 4 4",
"output": "38"
},
{
"input": "8\n821407370 380061316 428719552 90851747 825473738 704702117 845629927 245820158",
"output": "8176373828"
},
{
"input": "... | 1,634,046,940 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 857 | 40,038,400 | import sys
from heapq import *
def get_ints():
return list(map(int, sys.stdin.readline().strip().split()))
def solve(N, nums):
ans = 0
q = []
for n in nums:
heappush(q, n)
if not (N & 1):
heappush(q, 0)
while len(q) > 1:
s = heappop(q) + heappop(q)... | Title: Boxes And Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has *n* different boxes. The first of them contains some balls of *n* different colors.
Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≤<=*i*<=≤... | ```python
import sys
from heapq import *
def get_ints():
return list(map(int, sys.stdin.readline().strip().split()))
def solve(N, nums):
ans = 0
q = []
for n in nums:
heappush(q, n)
if not (N & 1):
heappush(q, 0)
while len(q) > 1:
s = heappop(q) + ... | 3 | |
515 | C | Drazil and Factorial | PROGRAMMING | 1,400 | [
"greedy",
"math",
"sortings"
] | null | null | Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they shoul... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*.
The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes. | Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. | [
"4\n1234\n",
"3\n555\n"
] | [
"33222\n",
"555\n"
] | In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "4\n1234",
"output": "33222"
},
{
"input": "3\n555",
"output": "555"
},
{
"input": "15\n012345781234578",
"output": "7777553333222222222222"
},
{
"input": "1\n8",
"output": "7222"
},
{
"input": "10\n1413472614",
"output": "75333332222222"
},
{
... | 1,587,451,649 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 140 | 0 | a=int(input())
s=input()
ans=''
two=0
thr=0
fiv=0
sev=0
for i in range(len(s)):
if(s[i]=='2'):
two+=1
if(s[i]=='3'):
thr+=1
if(s[i]=='4'):
thr+=1
two+=2
if(s[i]=='5'):
fiv+=1
if(s[i]=='6'):
fiv+=1
thr+=1
if(... | Title: Drazil and Factorial
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that cont... | ```python
a=int(input())
s=input()
ans=''
two=0
thr=0
fiv=0
sev=0
for i in range(len(s)):
if(s[i]=='2'):
two+=1
if(s[i]=='3'):
thr+=1
if(s[i]=='4'):
thr+=1
two+=2
if(s[i]=='5'):
fiv+=1
if(s[i]=='6'):
fiv+=1
thr+=... | 0 | |
385 | B | Bear and Strings | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation",
"math",
"strings"
] | null | null | The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string... | The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters. | Print a single number — the answer to the problem. | [
"bearbtear\n",
"bearaabearc\n"
] | [
"6\n",
"20\n"
] | In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).
In the second sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (1, 11), (2, 10), (2, 11), (3, 10), (3, 11), (4, 10), (4, 11), (5, 10), (5, 11)... | 1,000 | [
{
"input": "bearbtear",
"output": "6"
},
{
"input": "bearaabearc",
"output": "20"
},
{
"input": "pbearbearhbearzqbearjkterasjhy",
"output": "291"
},
{
"input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb",
"output"... | 1,619,620,094 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | x=list(input())
n=len(x)
c=0
t=-1
for i in range(n-4):
if "".join(x[i:i+4])=="bear":
c+=(i-t)*(n-i-3)
t=i
print(c) | Title: Bear and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j... | ```python
x=list(input())
n=len(x)
c=0
t=-1
for i in range(n-4):
if "".join(x[i:i+4])=="bear":
c+=(i-t)*(n-i-3)
t=i
print(c)
``` | 0 | |
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s... | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indi... | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGB... | 1,605,742,075 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 218 | 0 | n=int(input())
c='ROYGBIV'
ans=''
for i in range(n):
ans+=c[i%7]
if ans[-2]=='O':
ans=ans[:-3]+"GBI"
elif ans[-1]=='R':
ans=ans[:-1]+'G'
elif ans[-2:]=='RO':
ans=ans[:-2]+'GB'
print(ans) | Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
-... | ```python
n=int(input())
c='ROYGBIV'
ans=''
for i in range(n):
ans+=c[i%7]
if ans[-2]=='O':
ans=ans[:-3]+"GBI"
elif ans[-1]=='R':
ans=ans[:-1]+'G'
elif ans[-2:]=='RO':
ans=ans[:-2]+'GB'
print(ans)
``` | 3.9455 |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,681,064,288 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 122 | 0 | def func():
s,u = input(),input()
t = s[::-1]
print('YES'if u == t else 'NO')
def init(flag=True):
for _ in range(int(input()) if flag else 1):
func()
if __name__ == '__main__':
init(False) | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
def func():
s,u = input(),input()
t = s[::-1]
print('YES'if u == t else 'NO')
def init(flag=True):
for _ in range(int(input()) if flag else 1):
func()
if __name__ == '__main__':
init(False)
``` | 3.9695 |
1,005 | D | Polycarp and Div 3 | PROGRAMMING | 1,500 | [
"dp",
"greedy",
"number theory"
] | null | null | Polycarp likes numbers that are divisible by 3.
He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot... | The first line of the input contains a positive integer $s$. The number of digits of the number $s$ is between $1$ and $2\cdot10^5$, inclusive. The first (leftmost) digit is not equal to 0. | Print the maximum number of numbers divisible by $3$ that Polycarp can get by making vertical cuts in the given number $s$. | [
"3121\n",
"6\n",
"1000000000000000000000000000000000\n",
"201920181\n"
] | [
"2\n",
"1\n",
"33\n",
"4\n"
] | In the first example, an example set of optimal cuts on the number is 3|1|21.
In the second example, you do not need to make any cuts. The specified number 6 forms one number that is divisible by $3$.
In the third example, cuts must be made between each pair of digits. As a result, Polycarp gets one digit 1 and $33$ ... | 0 | [
{
"input": "3121",
"output": "2"
},
{
"input": "6",
"output": "1"
},
{
"input": "1000000000000000000000000000000000",
"output": "33"
},
{
"input": "201920181",
"output": "4"
},
{
"input": "4",
"output": "0"
},
{
"input": "10",
"output": "1"
},
... | 1,669,901,249 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 156 | 2,764,800 | # LUOGU_RID: 96253599
n = input()
a = [int(i) for i in n]
tmp = 0
cnt = 0
ans = 0
for i in a:
t = i % 3
tmp = (tmp + t) % 3
cnt += 1
if t == 0 or tmp == 0 or cnt == 3:
ans += 1
cnt = 0
tmp = 0
print(ans) | Title: Polycarp and Div 3
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp likes numbers that are divisible by 3.
He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical c... | ```python
# LUOGU_RID: 96253599
n = input()
a = [int(i) for i in n]
tmp = 0
cnt = 0
ans = 0
for i in a:
t = i % 3
tmp = (tmp + t) % 3
cnt += 1
if t == 0 or tmp == 0 or cnt == 3:
ans += 1
cnt = 0
tmp = 0
print(ans)
``` | 3 | |
735 | D | Taxes | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not equal to *n*, of course). For example, if *n*<==<=6 then Funt has to pay 3 burles, while fo... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·109) — the total year income of mr. Funt. | Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax. | [
"4\n",
"27\n"
] | [
"2\n",
"3\n"
] | none | 1,750 | [
{
"input": "4",
"output": "2"
},
{
"input": "27",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "2000000000",
"output": "2"
},
{
"input": "26",
"output": ... | 1,622,927,918 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 13 | 140 | 1,228,800 | import math
n = int(input())
if n % 2:
r = 3
else:
r = 2
f = [1]
for i in range(1, int(math.sqrt(n)) + 1):
if not n % i:
f.append(i)
print(min(max(f), r))
| Title: Taxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not ... | ```python
import math
n = int(input())
if n % 2:
r = 3
else:
r = 2
f = [1]
for i in range(1, int(math.sqrt(n)) + 1):
if not n % i:
f.append(i)
print(min(max(f), r))
``` | 0 | |
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"... | 1,688,025,255 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 77 | 0 | n = int(input())
count = 0
for _ in range(n):
pi, qi = map(int,input().split())
if qi -pi >=2:
count +=1
print(count) | Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want ... | ```python
n = int(input())
count = 0
for _ in range(n):
pi, qi = map(int,input().split())
if qi -pi >=2:
count +=1
print(count)
``` | 3 | |
667 | A | Pouring Rain | PROGRAMMING | 1,100 | [
"geometry",
"math"
] | null | null | A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything ... | The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where:
- *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth ... | If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is... | [
"1 2 3 100\n",
"1 1 1 1\n"
] | [
"NO\n",
"YES\n3.659792366325\n"
] | In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we ca... | 500 | [
{
"input": "1 2 3 100",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "YES\n3.659792366325"
},
{
"input": "48 7946 7992 72",
"output": "NO"
},
{
"input": "72 6791 8546 46",
"output": "NO"
},
{
"input": "100 5635 9099 23",
"output": "NO"
},
{
"input... | 1,518,377,354 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 62 | 5,632,000 | d,h,v,e = map(int, input().split())
denominator = (4.00 * v) - ((d**2)*e*3.1415926)
if(denominator < 0):
print("NO")
else:
print("YES")
numerator = 3.1415926 * (d**2) * h
answer = numerator/denominator
print(answer) | Title: Pouring Rain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, cont... | ```python
d,h,v,e = map(int, input().split())
denominator = (4.00 * v) - ((d**2)*e*3.1415926)
if(denominator < 0):
print("NO")
else:
print("YES")
numerator = 3.1415926 * (d**2) * h
answer = numerator/denominator
print(answer)
``` | 3 | |
265 | B | Roadside Trees (Simplified Edition) | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts.
Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the fol... | The first line contains an integer *n* (1<=<=≤<=<=*n*<=≤<=105) — the number of trees.
Next *n* lines contains the height of trees: *i*-th line contains an integer *h**i* (1<=≤<=*h**i*<=≤<=104) — the height of the tree with the number *i*. | Print a single integer — the minimal time required to eat all nuts in seconds. | [
"2\n1\n2\n",
"5\n2\n1\n2\n1\n1\n"
] | [
"5\n",
"14\n"
] | none | 1,000 | [
{
"input": "2\n1\n2",
"output": "5"
},
{
"input": "5\n2\n1\n2\n1\n1",
"output": "14"
},
{
"input": "1\n1",
"output": "2"
}
] | 1,615,205,769 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 466 | 2,969,600 | n = int(input())
arr = []
for i in range(n):
arr.append(int(input()))
time = arr[0] + 1
for i in range(n-1):
diff = abs(arr[i] - arr[i+1])
time+=diff+2
print(time)
| Title: Roadside Trees (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wan... | ```python
n = int(input())
arr = []
for i in range(n):
arr.append(int(input()))
time = arr[0] + 1
for i in range(n-1):
diff = abs(arr[i] - arr[i+1])
time+=diff+2
print(time)
``` | 3 | |
632 | C | The Smallest String Concatenation | PROGRAMMING | 1,700 | [
"sortings",
"strings"
] | null | null | You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list of strings, output the lexicographically smallest concatenation. | The first line contains integer *n* — the number of strings (1<=≤<=*n*<=≤<=5·104).
Each of the next *n* lines contains one string *a**i* (1<=≤<=|*a**i*|<=≤<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104. | Print the only string *a* — the lexicographically smallest string concatenation. | [
"4\nabba\nabacaba\nbcd\ner\n",
"5\nx\nxx\nxxa\nxxaa\nxxaaa\n",
"3\nc\ncb\ncba\n"
] | [
"abacabaabbabcder\n",
"xxaaaxxaaxxaxxx\n",
"cbacbc\n"
] | none | 0 | [
{
"input": "4\nabba\nabacaba\nbcd\ner",
"output": "abacabaabbabcder"
},
{
"input": "5\nx\nxx\nxxa\nxxaa\nxxaaa",
"output": "xxaaaxxaaxxaxxx"
},
{
"input": "3\nc\ncb\ncba",
"output": "cbacbc"
},
{
"input": "10\naba\nabaaca\naba\nacaaaabbac\nabaacac\nb\ncabbcccaab\nbaacbb\nbcab... | 1,485,509,149 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 4,608,000 | n=int(input())
a=[]
for i in range(n):
a.append(input())
for i in range (n-1):
for j in range (i+1, n):
if (len(a[i])<len(a[j])):
a[i], a[j]=a[j], a[i]
else:
if (a[i]>a[j]):
a[i], a[j]=a[j], a[i]
print (''.join(a)) | Title: The Smallest String Concatenation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list ... | ```python
n=int(input())
a=[]
for i in range(n):
a.append(input())
for i in range (n-1):
for j in range (i+1, n):
if (len(a[i])<len(a[j])):
a[i], a[j]=a[j], a[i]
else:
if (a[i]>a[j]):
a[i], a[j]=a[j], a[i]
print (''.join(a))
``` | 0 | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,690,667,685 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | n,m=map(int,input().split())
v=list(map(int,input().split()))
b=[]
for j in v:
if v.count(j)==n:
print(0)
break
else:
while len(b)!=n:
b+=[min(v)]
v.remove(min(v))
print(max(b)-min(b)) | Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
n,m=map(int,input().split())
v=list(map(int,input().split()))
b=[]
for j in v:
if v.count(j)==n:
print(0)
break
else:
while len(b)!=n:
b+=[min(v)]
v.remove(min(v))
print(max(b)-min(b))
``` | 0 | |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,651,908,879 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 37 | 93 | 0 | #import sys
#input = sys.stdin.readline().strip()
#####################################################################
a,b = list(map(int,input().split()))
c = input()
if '0' * b in c:
print(-1)
elif c.count('1') == a:
if a % b == 0:
print(a // b)
else:
print((a//b)+1)
els... | Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
#import sys
#input = sys.stdin.readline().strip()
#####################################################################
a,b = list(map(int,input().split()))
c = input()
if '0' * b in c:
print(-1)
elif c.count('1') == a:
if a % b == 0:
print(a // b)
else:
print((a//... | 0 | |
353 | A | Domino | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half... | Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. | [
"2\n4 2\n6 4\n",
"1\n2 3\n",
"3\n1 4\n2 3\n4 4\n"
] | [
"0\n",
"-1\n",
"1\n"
] | In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the... | 500 | [
{
"input": "2\n4 2\n6 4",
"output": "0"
},
{
"input": "1\n2 3",
"output": "-1"
},
{
"input": "3\n1 4\n2 3\n4 4",
"output": "1"
},
{
"input": "5\n5 4\n5 4\n1 5\n5 5\n3 3",
"output": "1"
},
{
"input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n... | 1,626,233,489 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 6,963,200 | n=int(input())
sumx,sumy,res=0,0,0
for i in range(n):
x,y=map(int,input().split())
if i==0:
sumx+=x
sumy+=y
if i>=1:
if sumx%2!=0 and sumy%2==0:
if x%2!=0 and y%2==0:
sumx+=x
sumy+=y
elif x%2==0 and y%2!=0:
... | Title: Domino
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the n... | ```python
n=int(input())
sumx,sumy,res=0,0,0
for i in range(n):
x,y=map(int,input().split())
if i==0:
sumx+=x
sumy+=y
if i>=1:
if sumx%2!=0 and sumy%2==0:
if x%2!=0 and y%2==0:
sumx+=x
sumy+=y
elif x%2==0 and y%2!=0:... | 0 | |
353 | A | Domino | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half... | Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. | [
"2\n4 2\n6 4\n",
"1\n2 3\n",
"3\n1 4\n2 3\n4 4\n"
] | [
"0\n",
"-1\n",
"1\n"
] | In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the... | 500 | [
{
"input": "2\n4 2\n6 4",
"output": "0"
},
{
"input": "1\n2 3",
"output": "-1"
},
{
"input": "3\n1 4\n2 3\n4 4",
"output": "1"
},
{
"input": "5\n5 4\n5 4\n1 5\n5 5\n3 3",
"output": "1"
},
{
"input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n... | 1,471,254,633 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 92 | 4,608,000 | n = int(input())
top = []
bot = []
for i in range(n):
x, y= map(int, input().split())
top.append(x)
bot.append(y)
if sum(top) % 2 == 0 and sum(bot) % 2 == 0:
print(0)
elif sum(top) % 2 != 0 and sum(bot) % 2 != 0:
for i in range(len(top)):
if (top[i] % 2 == 0 and bot[i] % 2 != 0) o... | Title: Domino
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the n... | ```python
n = int(input())
top = []
bot = []
for i in range(n):
x, y= map(int, input().split())
top.append(x)
bot.append(y)
if sum(top) % 2 == 0 and sum(bot) % 2 == 0:
print(0)
elif sum(top) % 2 != 0 and sum(bot) % 2 != 0:
for i in range(len(top)):
if (top[i] % 2 == 0 and bot[i] %... | 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,593,648,430 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 248 | 0 | s=input()
n=len(s)
small=0
upper=0
while n > 0:
if s[n-1].isupper():
upper+=1
else:
small+=1
n-=1
if upper<small:
print(s.lower())
elif upper>small:
print(s.upper())
elif upper==small:
print(s)
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=input()
n=len(s)
small=0
upper=0
while n > 0:
if s[n-1].isupper():
upper+=1
else:
small+=1
n-=1
if upper<small:
print(s.lower())
elif upper>small:
print(s.upper())
elif upper==small:
print(s)
``` | 0 |
888 | B | Buggy Robot | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — mo... | The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100).
The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R. | Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. | [
"4\nLDUR\n",
"5\nRRRUU\n",
"6\nLLRRRR\n"
] | [
"4\n",
"0\n",
"4\n"
] | none | 0 | [
{
"input": "4\nLDUR",
"output": "4"
},
{
"input": "5\nRRRUU",
"output": "0"
},
{
"input": "6\nLLRRRR",
"output": "4"
},
{
"input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR",
"output": "76"
},
{
"input": "89\nLDL... | 1,555,584,218 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | n=int(input())
s=input()
count=0
done=0
for i in range(n):
if s[i]=='L':
count-=1
elif s[i]=='R':
count+=1
elif s[i]=='U':
count+=1
else:
count-=1
if count==0:
done=1
a=i
if done==1:
print(a+1)
else:
print(0)... | Title: Buggy Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the ce... | ```python
n=int(input())
s=input()
count=0
done=0
for i in range(n):
if s[i]=='L':
count-=1
elif s[i]=='R':
count+=1
elif s[i]=='U':
count+=1
else:
count-=1
if count==0:
done=1
a=i
if done==1:
print(a+1)
else:
... | 0 | |
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,675,437,686 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 92 | 17,715,200 | word = input ()
count = 0
for letter in word :
count = count + 1
if word.isdigit() == True:
pass
elif count <= 10:
print(word)
elif count >10 :
new_word = word[0] + str(count - 2) + word[-1]
print(new_word)
| 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
word = input ()
count = 0
for letter in word :
count = count + 1
if word.isdigit() == True:
pass
elif count <= 10:
print(word)
elif count >10 :
new_word = word[0] + str(count - 2) + word[-1]
print(new_word)
``` | 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,591,098,070 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 233 | 11,264,000 | # 1 3 2 1 3 2
# 2 1 2 1
# Python program for KMP Algorithm
def KMPSearch(pat, txt):
M = len(pat)
N = len(txt)
val = -1
lps = [0] * M
j = 0
computeLPSArray(pat, M, lps)
i = 0
while i < N:
if pat[j] == txt[i]:
i += 1
j += 1
if j == M:
... | 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
# 1 3 2 1 3 2
# 2 1 2 1
# Python program for KMP Algorithm
def KMPSearch(pat, txt):
M = len(pat)
N = len(txt)
val = -1
lps = [0] * M
j = 0
computeLPSArray(pat, M, lps)
i = 0
while i < N:
if pat[j] == txt[i]:
i += 1
j += 1
i... | 0 | |
870 | C | Maximum splitting | PROGRAMMING | 1,300 | [
"dp",
"greedy",
"math",
"number theory"
] | null | null | You are given several queries. In the *i*-th query you are given a single positive integer *n**i*. You are to represent *n**i* as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.
An integer greater than 1 is composite, if it is not prim... | The first line contains single integer *q* (1<=≤<=*q*<=≤<=105) — the number of queries.
*q* lines follow. The (*i*<=+<=1)-th line contains single integer *n**i* (1<=≤<=*n**i*<=≤<=109) — the *i*-th query. | For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. | [
"1\n12\n",
"2\n6\n8\n",
"3\n1\n2\n3\n"
] | [
"3\n",
"1\n2\n",
"-1\n-1\n-1\n"
] | 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.
8 = 4 + 4, 6 can't be split into several composite summands.
1, 2, 3 are less than any composite number, so they do not have valid splittings. | 1,500 | [
{
"input": "1\n12",
"output": "3"
},
{
"input": "2\n6\n8",
"output": "1\n2"
},
{
"input": "3\n1\n2\n3",
"output": "-1\n-1\n-1"
},
{
"input": "6\n1\n2\n3\n5\n7\n11",
"output": "-1\n-1\n-1\n-1\n-1\n-1"
},
{
"input": "3\n4\n6\n9",
"output": "1\n1\n1"
},
{
... | 1,558,015,626 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 1,060 | 0 | n = int(input())
for i in range(n):
calc = int(input())
if calc <= 3 or calc == 5 or calc == 7 or calc == 11:
print(-1)
else:
ans = int(calc / 4)
if (calc % 4) % 2 == 1:
ans = ans - 1
print(ans) | Title: Maximum splitting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given several queries. In the *i*-th query you are given a single positive integer *n**i*. You are to represent *n**i* as a sum of maximum possible number of composite summands and print this maximum number, o... | ```python
n = int(input())
for i in range(n):
calc = int(input())
if calc <= 3 or calc == 5 or calc == 7 or calc == 11:
print(-1)
else:
ans = int(calc / 4)
if (calc % 4) % 2 == 1:
ans = ans - 1
print(ans)
``` | 3 | |
290 | B | QR code | PROGRAMMING | 1,500 | [
"*special",
"implementation"
] | null | null | The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=32), separated by a single space. | Output a single integer. | [
"1 1\n",
"3 7\n",
"13 10\n"
] | [
"0\n",
"0\n",
"1\n"
] | none | 0 | [
{
"input": "1 1",
"output": "0"
},
{
"input": "3 7",
"output": "0"
},
{
"input": "13 10",
"output": "1"
},
{
"input": "6 12",
"output": "1"
},
{
"input": "14 14",
"output": "0"
},
{
"input": "19 14",
"output": "0"
},
{
"input": "21 18",
... | 1,570,474,859 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 216 | 0 | s=str(input()).split()
a=list(map(int,s))
x=list('1111111010101011111001010011111111000001000000000010101100010000011011101001101100000110100010111011011101010110010011111010010111011011101011000110001111001010111011000001010101010110100001010000011111111010101010101010101011111110000000011111011111001111000000001000... | Title: QR code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=32), separated by a single space.
Output Specification:
Output a single integer.
Demo Input:
['1 1\n', '3 7\n', '13 10\n']
Demo Output:
['0... | ```python
s=str(input()).split()
a=list(map(int,s))
x=list('111111101010101111100101001111111100000100000000001010110001000001101110100110110000011010001011101101110101011001001111101001011101101110101100011000111100101011101100000101010101011010000101000001111111101010101010101010101111111000000001111101111100111100... | 0 | ||
999 | D | Equalize the Remainders | PROGRAMMING | 1,900 | [
"data structures",
"greedy",
"implementation"
] | null | null | You are given an array consisting of $n$ integers $a_1, a_2, \dots, a_n$, and a positive integer $m$. It is guaranteed that $m$ is a divisor of $n$.
In a single move, you can choose any position $i$ between $1$ and $n$ and increase $a_i$ by $1$.
Let's calculate $c_r$ ($0 \le r \le m-1)$ — the number of elements havin... | The first line of input contains two integers $n$ and $m$ ($1 \le n \le 2 \cdot 10^5, 1 \le m \le n$). It is guaranteed that $m$ is a divisor of $n$.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$), the elements of the array. | In the first line, print a single integer — the minimum number of moves required to satisfy the following condition: for each remainder from $0$ to $m - 1$, the number of elements of the array having this remainder equals $\frac{n}{m}$.
In the second line, print any array satisfying the condition and can be obtained f... | [
"6 3\n3 2 0 6 10 12\n",
"4 2\n0 1 2 3\n"
] | [
"3\n3 2 0 7 10 14 \n",
"0\n0 1 2 3 \n"
] | none | 0 | [
{
"input": "6 3\n3 2 0 6 10 12",
"output": "3\n3 2 0 7 10 14 "
},
{
"input": "4 2\n0 1 2 3",
"output": "0\n0 1 2 3 "
},
{
"input": "1 1\n1000000000",
"output": "0\n1000000000 "
},
{
"input": "6 3\n3 2 0 6 10 11",
"output": "1\n3 2 0 7 10 11 "
},
{
"input": "100 25... | 1,643,179,787 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 561 | 27,443,200 | """
-*- coding: utf-8 -*-
Created on Sat Jan 22 18:33:32 2022
@author: Tausif Khan Arnob
"""
n, m = map(int, input().split())
a = [*map(int, input().split())]
li = [[] for i in range(m)]
k, s, j = n // m, sum(a), 0
for i, val in enumerate(a):
li[val % m].append(i)
for i in range(m):
whil... | Title: Equalize the Remainders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array consisting of $n$ integers $a_1, a_2, \dots, a_n$, and a positive integer $m$. It is guaranteed that $m$ is a divisor of $n$.
In a single move, you can choose any position $i$ between $1$... | ```python
"""
-*- coding: utf-8 -*-
Created on Sat Jan 22 18:33:32 2022
@author: Tausif Khan Arnob
"""
n, m = map(int, input().split())
a = [*map(int, input().split())]
li = [[] for i in range(m)]
k, s, j = n // m, sum(a), 0
for i, val in enumerate(a):
li[val % m].append(i)
for i in range(m):... | 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,684,363,685 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import sys
input = sys.stdin.readline
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
n = inp()
s = inlt()
ax = []
bx = []
cx = []
for idx, st in... | 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
import sys
input = sys.stdin.readline
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
n = inp()
s = inlt()
ax = []
bx = []
cx = []
for ... | -1 | |
665 | C | Simple Strings | PROGRAMMING | 1,300 | [
"dp",
"greedy",
"strings"
] | null | null | zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with th... | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters. | Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them.
Note that the string *s*' should also consist of only lowercase English letters. | [
"aab\n",
"caaab\n",
"zscoder\n"
] | [
"bab\n",
"cabab\n",
"zscoder\n"
] | none | 0 | [
{
"input": "aab",
"output": "bab"
},
{
"input": "caaab",
"output": "cabab"
},
{
"input": "zscoder",
"output": "zscoder"
},
{
"input": "u",
"output": "u"
},
{
"input": "h",
"output": "h"
},
{
"input": "dtottttotd",
"output": "dtotataotd"
},
{
... | 1,691,332,008 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 109 | 1,228,800 | t = input() + ' '
s = ' '
for a, b in zip(t, t[1:]):
if a == s[-1]:
for q in 'abc':
if a != q != b:
s += q
break
else: s += a
print(s[1:]) | Title: Simple Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wa... | ```python
t = input() + ' '
s = ' '
for a, b in zip(t, t[1:]):
if a == s[-1]:
for q in 'abc':
if a != q != b:
s += q
break
else: s += a
print(s[1:])
``` | 3 | |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
... | 1,694,269,187 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | def is_prime(x):
if x <= 1:
return False
if x <= 3:
return True
if x % 2 == 0 or x % 3 == 0:
return False
i = 5
while i * i <= x:
if x % i == 0 or x % (i + 2) == 0:
return False
i += 6
return True
def composite_pair(n):
for ... | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statemen... | ```python
def is_prime(x):
if x <= 1:
return False
if x <= 3:
return True
if x % 2 == 0 or x % 3 == 0:
return False
i = 5
while i * i <= x:
if x % i == 0 or x % (i + 2) == 0:
return False
i += 6
return True
def composite_pair(n):... | 3 | |
538 | D | Weird Chess | PROGRAMMING | 1,800 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.
Igor's chessboard is a square of size *n*<=×<=*n* cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=50).
The next *n* lines contain *n* characters each describing the position offered by Igor. The *j*-th character of the *i*-th string can have the following values:
- o — in this case the field (*i*,<=*j*) is occupied by a piece and the field may or may not... | If there is a valid set of moves, in the first line print a single word 'YES' (without the quotes). Next, print the description of the set of moves of a piece in the form of a (2*n*<=-<=1)<=×<=(2*n*<=-<=1) board, the center of the board has a piece and symbols 'x' mark cells that are attacked by it, in a format similar... | [
"5\noxxxx\nx...x\nx...x\nx...x\nxxxxo\n",
"6\n.x.x..\nx.x.x.\n.xo..x\nx..ox.\n.x.x.x\n..x.x.\n",
"3\no.x\noxx\no.x\n"
] | [
"YES\n....x....\n....x....\n....x....\n....x....\nxxxxoxxxx\n....x....\n....x....\n....x....\n....x....\n",
"YES\n...........\n...........\n...........\n....x.x....\n...x...x...\n.....o.....\n...x...x...\n....x.x....\n...........\n...........\n...........\n",
"NO\n"
] | In the first sample test the piece is a usual chess rook, and in the second sample test the piece is a usual chess knight. | 1,500 | [
{
"input": "5\noxxxx\nx...x\nx...x\nx...x\nxxxxo",
"output": "YES\nxxxxxxxxx\nx...xxxxx\nx...xxxxx\nx...xxxxx\nxxxxoxxxx\nxxxxx...x\nxxxxx...x\nxxxxx...x\nxxxxxxxxx"
},
{
"input": "6\n.x.x..\nx.x.x.\n.xo..x\nx..ox.\n.x.x.x\n..x.x.",
"output": "YES\nxxxxxxxxxxx\nxxxxxxxxxxx\nxx.x.x..xxx\nxxx.x.x.... | 1,481,119,942 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 22 | 2,000 | 4,812,800 | n=int(input())
len=2*n-1
def er(len,z):
L=[]
i=0
while i<len:
L.append([])
j=0
while j<len:
L[i].append(z)
j=j+1
i=i+1
return L
ans=er(len,'x')
ans[n-1][n-1]='o'
L=[]
for i in range(n):
L.append([])
L[i]=input()
vec=[ (i,j) for i in range(n) for j in range(n) if L[i][j]=='.' ]
i=0
while i<n:
... | Title: Weird Chess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.
Igor's chessboard is a square of size *n*<=×<=*n* cells.... | ```python
n=int(input())
len=2*n-1
def er(len,z):
L=[]
i=0
while i<len:
L.append([])
j=0
while j<len:
L[i].append(z)
j=j+1
i=i+1
return L
ans=er(len,'x')
ans[n-1][n-1]='o'
L=[]
for i in range(n):
L.append([])
L[i]=input()
vec=[ (i,j) for i in range(n) for j in range(n) if L[i][j]=='.' ]
i=0
w... | 0 | |
864 | A | Fair Game | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number.
The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards. | If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more.
In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number t... | [
"4\n11\n27\n27\n11\n",
"2\n6\n6\n",
"6\n10\n20\n30\n20\n10\n20\n",
"6\n1\n1\n2\n2\n3\n3\n"
] | [
"YES\n11 27\n",
"NO\n",
"NO\n",
"NO\n"
] | In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.
In the second example fair game is impossible because the nu... | 500 | [
{
"input": "4\n11\n27\n27\n11",
"output": "YES\n11 27"
},
{
"input": "2\n6\n6",
"output": "NO"
},
{
"input": "6\n10\n20\n30\n20\n10\n20",
"output": "NO"
},
{
"input": "6\n1\n1\n2\n2\n3\n3",
"output": "NO"
},
{
"input": "2\n1\n100",
"output": "YES\n1 100"
},
... | 1,550,392,274 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | def petya(arr1):
n=len(arr1)
if len(set(arr1))==1:
return False
if sorted(list(set(arr1[:n//2])))==sorted(list(set(arr1[n//2:]))):
return True
return False
n=int(input())
arr1=[]
for _ in range(n):
arr1.append(int(input()))
if petya(arr1):
print('YES')
else:
... | Title: Fair Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (di... | ```python
def petya(arr1):
n=len(arr1)
if len(set(arr1))==1:
return False
if sorted(list(set(arr1[:n//2])))==sorted(list(set(arr1[n//2:]))):
return True
return False
n=int(input())
arr1=[]
for _ in range(n):
arr1.append(int(input()))
if petya(arr1):
print('YES')
... | 0 | |
525 | C | Ilya and Sticks | PROGRAMMING | 1,600 | [
"greedy",
"math",
"sortings"
] | null | null | In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of *n* sticks and an instrument. Each stick is characterized by its length *l**i*.
Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way tha... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of the available sticks.
The second line of the input contains *n* positive integers *l**i* (2<=≤<=*l**i*<=≤<=106) — the lengths of the sticks. | The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks. | [
"4\n2 4 4 2\n",
"4\n2 2 3 5\n",
"4\n100003 100004 100005 100006\n"
] | [
"8\n",
"0\n",
"10000800015\n"
] | none | 1,000 | [
{
"input": "4\n2 4 4 2",
"output": "8"
},
{
"input": "4\n2 2 3 5",
"output": "0"
},
{
"input": "4\n100003 100004 100005 100006",
"output": "10000800015"
},
{
"input": "8\n5 3 3 3 3 4 4 4",
"output": "25"
},
{
"input": "10\n123 124 123 124 2 2 2 2 9 9",
"output... | 1,610,141,302 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 36 | 140 | 7,782,400 | n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse = True)
total = 0
for i in range(0, len(arr), 4):
if i < len(arr) and i + 1 < len(arr) and i + 2 < len(arr) and i + 3 < len(arr):
if arr[i] - arr[i + 1] <= 1 and arr[i + 2] - arr[i + 3] <= 1:
total += arr[i + 1] * arr[i + 3]... | Title: Ilya and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of *n* sticks and an instrument. Each stick is characterized by its length *l**i*.
Ilya decided to m... | ```python
n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse = True)
total = 0
for i in range(0, len(arr), 4):
if i < len(arr) and i + 1 < len(arr) and i + 2 < len(arr) and i + 3 < len(arr):
if arr[i] - arr[i + 1] <= 1 and arr[i + 2] - arr[i + 3] <= 1:
total += arr[i + 1] * ... | 0 | |
137 | B | Permutation | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is cal... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). | Print the only number — the minimum number of changes needed to get the permutation. | [
"3\n3 1 2\n",
"2\n2 2\n",
"5\n5 3 3 3 1\n"
] | [
"0\n",
"1\n",
"2\n"
] | The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with... | 1,000 | [
{
"input": "3\n3 1 2",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "2"
},
{
"input": "5\n6 6 6 6 6",
"output": "5"
},
{
"input": "10\n1 1 2 2 8 8 7 7 9 9",
"output": "5"
},
{
"input": "8\n9 8 7 6 5 4 3 2"... | 1,592,488,137 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 248 | 921,600 | n = int(input())
a = set(list(map(int,input().split())))
print(len(set(range(1,n+1))-a)) | Title: Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task ... | ```python
n = int(input())
a = set(list(map(int,input().split())))
print(len(set(range(1,n+1))-a))
``` | 3 | |
764 | B | Timofey and cubes | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation"
] | null | null | Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.
In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Sup... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order. | Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order.
It can be shown that the answer is unique. | [
"7\n4 3 7 6 9 1 2\n",
"8\n6 1 4 2 5 6 9 2\n"
] | [
"2 3 9 6 7 1 4",
"2 1 6 2 5 4 9 6"
] | Consider the first sample.
1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing ha... | 1,000 | [
{
"input": "7\n4 3 7 6 9 1 2",
"output": "2 3 9 6 7 1 4"
},
{
"input": "8\n6 1 4 2 5 6 9 2",
"output": "2 1 6 2 5 4 9 6"
},
{
"input": "1\n1424",
"output": "1424"
},
{
"input": "9\n-7 9 -4 9 -6 11 15 2 -10",
"output": "-10 9 15 9 -6 11 -4 2 -7"
},
{
"input": "2\n2... | 1,630,426,462 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 77 | 20,172,800 | n=int(input())
a=[int(i) for i in input().split()]
if n==1:
print(a)
elif n==2:
print(*a[::-1])
else:
if n%2==1:
for i in range(1,n//2+1,2):
# print(i,n-i+1)
a[i-1],a[n-i]=a[n-i],a[i-1]
else:
for i in range(1,n//2,2):
# print(i,n-i+1)
... | Title: Timofey and cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other p... | ```python
n=int(input())
a=[int(i) for i in input().split()]
if n==1:
print(a)
elif n==2:
print(*a[::-1])
else:
if n%2==1:
for i in range(1,n//2+1,2):
# print(i,n-i+1)
a[i-1],a[n-i]=a[n-i],a[i-1]
else:
for i in range(1,n//2,2):
# print(i,n... | 0 | |
903 | C | Boxes Packing | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box. | Print the minimum possible number of visible boxes. | [
"3\n1 2 3\n",
"4\n4 2 4 3\n"
] | [
"1\n",
"2\n"
] | In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1. | 0 | [
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "4\n4 2 4 3",
"output": "2"
},
{
"input": "10\n58 58 58 58 58 58 58 58 58 58",
"output": "10"
},
{
"input": "10\n86 89 89 86 86 89 86 86 89 89",
"output": "5"
},
{
"input": "100\n981 288 186 186 292 876 341 288 98... | 1,588,253,968 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 124 | 819,200 | from collections import defaultdict
n=int(input())
a=sorted(list(map(int,input().split())))
d=defaultdict(int)
for i in a:
d[i]+=1
print(max(d.values()))
| Title: Boxes Packing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not pu... | ```python
from collections import defaultdict
n=int(input())
a=sorted(list(map(int,input().split())))
d=defaultdict(int)
for i in a:
d[i]+=1
print(max(d.values()))
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg... | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 0 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"... | 1,514,040,226 | 2,326 | Python 3 | WRONG_ANSWER | PRETESTS | 5 | 46 | 5,529,600 | v1, v2, v3, vm = map(int, input().split())
if 2 * v3 < vm or 2 * v2 < vm:
print(-1)
else:
print(2 * v1)
print(2 * v2)
print(max(v3, vm)) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can cli... | ```python
v1, v2, v3, vm = map(int, input().split())
if 2 * v3 < vm or 2 * v2 < vm:
print(-1)
else:
print(2 * v1)
print(2 * v2)
print(max(v3, vm))
``` | 0 | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,687,182,043 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 124 | 0 | z=int(input())
sow=input()
k=list(map(int, sow.split()))
cool=[]
cool.append(k[0])
ex=0
for i in range(1,len(k)):
b=k[i]
c=max(cool)
c2=min(cool)
if b>c or b<c2:
ex=ex+1
cool.append(k[i])
print(ex)
| Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
z=int(input())
sow=input()
k=list(map(int, sow.split()))
cool=[]
cool.append(k[0])
ex=0
for i in range(1,len(k)):
b=k[i]
c=max(cool)
c2=min(cool)
if b>c or b<c2:
ex=ex+1
cool.append(k[i])
print(ex)
``` | 3 | |
916 | A | Jamie and Alarm Snooze | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He ... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60).
The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59). | Print the minimum number of times he needs to press the button. | [
"3\n11 23\n",
"5\n01 07\n"
] | [
"2\n",
"0\n"
] | In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20.
In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky. | 500 | [
{
"input": "3\n11 23",
"output": "2"
},
{
"input": "5\n01 07",
"output": "0"
},
{
"input": "34\n09 24",
"output": "3"
},
{
"input": "2\n14 37",
"output": "0"
},
{
"input": "14\n19 54",
"output": "9"
},
{
"input": "42\n15 44",
"output": "12"
},
... | 1,606,824,536 | 2,147,483,647 | Python 3 | OK | TESTS | 254 | 124 | 0 | x = int(input())
hh, mm = map(int, input().split())
result = 0
while '7' not in str(hh) and '7' not in str(mm):
mm-=x
if mm<0:
mm=60+mm
hh-=1
if hh<0:
hh=24+hh
result+=1
print(result) | Title: Jamie and Alarm Snooze
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will the... | ```python
x = int(input())
hh, mm = map(int, input().split())
result = 0
while '7' not in str(hh) and '7' not in str(mm):
mm-=x
if mm<0:
mm=60+mm
hh-=1
if hh<0:
hh=24+hh
result+=1
print(result)
``` | 3 | |
349 | A | Cinema Line | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. | Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". | [
"4\n25 25 50 50\n",
"2\n25 100\n",
"4\n50 50 25 25\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "4\n25 25 50 50",
"output": "YES"
},
{
"input": "2\n25 100",
"output": "NO"
},
{
"input": "4\n50 50 25 25",
"output": "NO"
},
{
"input": "3\n25 50 100",
"output": "NO"
},
{
"input": "10\n25 25 25 25 25 25 25 25 25 25",
"output": "YES"
},
{
"... | 1,623,720,890 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 122 | 0 | n = int(input())
d = dict()
a = list(map(int, input().split()))
d = dict()
result = "YES"
for i in a:
d[i] = d.get(i, 0) + 1
c = i - 25
if c > 0 and d.get(c, 0) > 0:
d[c] -= 1
else:
result = "NO"
break
print(result)
| Title: Cinema Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the bookin... | ```python
n = int(input())
d = dict()
a = list(map(int, input().split()))
d = dict()
result = "YES"
for i in a:
d[i] = d.get(i, 0) + 1
c = i - 25
if c > 0 and d.get(c, 0) > 0:
d[c] -= 1
else:
result = "NO"
break
print(result)
``` | 0 | |
234 | C | Weather | PROGRAMMING | 1,300 | [
"dp",
"implementation"
] | null | null | Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet.
Our hero Vasya is quite concerned about the problems. He decided to try a little experiment and observe how outside daily temperature changes. He hung out a ther... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of days for which Vasya has been measuring the temperature.
The second line contains a sequence of *n* integers *t*1,<=*t*2,<=...,<=*t**n* (|*t**i*|<=≤<=109) — the sequence of temperature values. Numbers *t**i* are separated by single space... | Print a single integer — the answer to the given task. | [
"4\n-1 1 -2 1\n",
"5\n0 -1 1 2 -5\n"
] | [
"1\n",
"2\n"
] | Note to the first sample: there are two ways to change exactly one number so that the sequence met Vasya's condition. You can either replace the first number 1 by any negative number or replace the number -2 by any positive number. | 0 | [
{
"input": "4\n-1 1 -2 1",
"output": "1"
},
{
"input": "5\n0 -1 1 2 -5",
"output": "2"
},
{
"input": "6\n0 0 0 0 0 0",
"output": "6"
},
{
"input": "6\n-1 -2 -3 -4 5 6",
"output": "0"
},
{
"input": "8\n1 2 -1 0 10 2 12 13",
"output": "3"
},
{
"input": "... | 1,620,522,689 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 374 | 15,974,400 | with open("input.txt", "r") as f:
n = int(f.readline())
t = list(map(int, f.readline().split()))
m = 0
for i in range(1, n):
if t[i] <= 0:
m += 1
if t[0] >= 0:
m += 1
p = m
for i in range(1, n - 1):
if t[i] < 0:
cost = -1
elif t[i] == 0:
cost = 0
else:
... | Title: Weather
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet.
Our hero Vasya is quite concerned about the problems. He decided to ... | ```python
with open("input.txt", "r") as f:
n = int(f.readline())
t = list(map(int, f.readline().split()))
m = 0
for i in range(1, n):
if t[i] <= 0:
m += 1
if t[0] >= 0:
m += 1
p = m
for i in range(1, n - 1):
if t[i] < 0:
cost = -1
elif t[i] == 0:
cost = 0
els... | 3 | |
253 | B | Physics Practical | PROGRAMMING | 1,400 | [
"binary search",
"dp",
"sortings",
"two pointers"
] | null | null | One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher h... | The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=5000) — the results of the measurements. The numbers on the second line are separated by single spaces. | Print a single integer — the minimum number of results Vasya will have to remove. | [
"6\n4 5 3 8 3 7\n",
"4\n4 3 2 4\n"
] | [
"2\n",
"0\n"
] | In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one... | 1,000 | [
{
"input": "6\n4 5 3 8 3 7",
"output": "2"
},
{
"input": "4\n4 3 2 4",
"output": "0"
},
{
"input": "6\n5 6 4 9 4 8",
"output": "1"
},
{
"input": "4\n5 4 1 5",
"output": "1"
},
{
"input": "2\n3 2",
"output": "0"
},
{
"input": "10\n39 9 18 13 6 16 47 15 ... | 1,661,776,670 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 186 | 2,764,800 | n = int(input())
A = list(map(int, input().split()))
count = [0 for i in range(5001)]
minimal = min(A)
for elem in A:
count[elem] += 1
ans = 0
for elem in A:
if elem < minimal or elem > 2 * minimal:
ans += count[elem]
print(ans) | Title: Physics Practical
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he... | ```python
n = int(input())
A = list(map(int, input().split()))
count = [0 for i in range(5001)]
minimal = min(A)
for elem in A:
count[elem] += 1
ans = 0
for elem in A:
if elem < minimal or elem > 2 * minimal:
ans += count[elem]
print(ans)
``` | -1 | |
30 | B | Codeforces World Finals | PROGRAMMING | 1,700 | [
"implementation"
] | B. Codeforces World Finals | 2 | 256 | The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa understood that to conquer the world he needs to organize the world Codeforces tournament. He hopes that a... | The first line contains the date *DD*.*MM*.*YY*, the second line contains the date *BD*.*BM*.*BY*. It is guaranteed that both dates are correct, and *YY* and *BY* are always in [01;99].
It could be that by passport Bob was born after the finals. In this case, he can still change the order of numbers in date. | If it is possible to rearrange the numbers in the date of birth so that Bob will be at least 18 years old on the *DD*.*MM*.*YY*, output YES. In the other case, output NO.
Each number contains exactly two digits and stands for day, month or year in a date. Note that it is permitted to rearrange only numbers, not digit... | [
"01.01.98\n01.01.80\n",
"20.10.20\n10.02.30\n",
"28.02.74\n28.02.64\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 1,000 | [
{
"input": "01.01.98\n01.01.80",
"output": "YES"
},
{
"input": "20.10.20\n10.02.30",
"output": "NO"
},
{
"input": "28.02.74\n28.02.64",
"output": "NO"
},
{
"input": "05.05.25\n06.02.71",
"output": "NO"
},
{
"input": "19.11.54\n29.11.53",
"output": "NO"
},
... | 1,453,478,910 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 124 | 0 | d = list(map(int, input().split('.')))
b = list(map(int, input().split('.')))
if d[2] - b[2] > 18:
print('YES')
elif d[2] - b[2] < 18:
print('NO')
elif (d[1], d[0]) >= (b[1], b[0]):
print('YES')
elif b[0] <= 12 and (d[1], d[0]) >= (b[0], b[1]):
print('YES')
else:
print('NO') | Title: Codeforces World Finals
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa u... | ```python
d = list(map(int, input().split('.')))
b = list(map(int, input().split('.')))
if d[2] - b[2] > 18:
print('YES')
elif d[2] - b[2] < 18:
print('NO')
elif (d[1], d[0]) >= (b[1], b[0]):
print('YES')
elif b[0] <= 12 and (d[1], d[0]) >= (b[0], b[1]):
print('YES')
else:
print('NO')
``` | 0 |
90 | B | African Crossword | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | B. African Crossword | 2 | 256 | An African crossword is a rectangular table *n*<=×<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.
To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Next *n* lines contain *m* lowercase Latin letters each. That is the crossword grid. | Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter. | [
"3 3\ncba\nbcd\ncbc\n",
"5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n"
] | [
"abcd",
"codeforces"
] | none | 1,000 | [
{
"input": "3 3\ncba\nbcd\ncbc",
"output": "abcd"
},
{
"input": "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf",
"output": "codeforces"
},
{
"input": "4 4\nusah\nusha\nhasu\nsuha",
"output": "ahhasusu"
},
{
"input": "7 5\naabcd\neffgh\niijkk\nlmnoo\npqqrs\nttuvw\nxxyyz",
"output... | 1,601,867,900 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 218 | 307,200 | n , m = map(int,input().split())
arr = []
for i in range(n):
arr.append(input())
res = list(zip(*arr))
for i in range(n):
for j in range(m):
if arr[i].count(arr[i][j])==1:
if res[j].count(arr[i][j])==1:
print(arr[i][j],end="")
| Title: African Crossword
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
An African crossword is a rectangular table *n*<=×<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.
To s... | ```python
n , m = map(int,input().split())
arr = []
for i in range(n):
arr.append(input())
res = list(zip(*arr))
for i in range(n):
for j in range(m):
if arr[i].count(arr[i][j])==1:
if res[j].count(arr[i][j])==1:
print(arr[i][j],end="")
... | 3.944928 |
959 | A | Mahmoud and Ehab and the even-odd game | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that:
- 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab'... | The only line contains an integer *n* (1<=≤<=*n*<=≤<=109), the number at the beginning of the game. | Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise. | [
"1\n",
"2\n"
] | [
"Ehab",
"Mahmoud"
] | In the first sample, Mahmoud can't choose any integer *a* initially because there is no positive even integer less than or equal to 1 so Ehab wins.
In the second sample, Mahmoud has to choose *a* = 2 and subtract it from *n*. It's Ehab's turn and *n* = 0. There is no positive odd integer less than or equal to 0 so Mah... | 500 | [
{
"input": "1",
"output": "Ehab"
},
{
"input": "2",
"output": "Mahmoud"
},
{
"input": "10000",
"output": "Mahmoud"
},
{
"input": "33333",
"output": "Ehab"
},
{
"input": "5",
"output": "Ehab"
},
{
"input": "1000000000",
"output": "Mahmoud"
},
{
... | 1,625,145,910 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 124 | 2,252,800 | import os
import sys
import math
import numpy
import collections
import itertools
from io import BytesIO, IOBase
#---<Fast I/O>---#
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.... | Title: Mahmoud and Ehab and the even-odd game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a*... | ```python
import os
import sys
import math
import numpy
import collections
import itertools
from io import BytesIO, IOBase
#---<Fast I/O>---#
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x... | -1 | |
735 | B | Urbanization | PROGRAMMING | 1,100 | [
"greedy",
"number theory",
"sortings"
] | null | null | Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* of them is equal to *a**i*. Authorities plan to build two cities, first for *n*1 people and second ... | The first line of the input contains three integers *n*, *n*1 and *n*2 (1<=≤<=*n*,<=*n*1,<=*n*2<=≤<=100<=000, *n*1<=+<=*n*2<=≤<=*n*) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line conta... | Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your ... | [
"2 1 1\n1 5\n",
"4 2 1\n1 4 2 3\n"
] | [
"6.00000000\n",
"6.50000000\n"
] | In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (*a*<sub class="lower-index">3</sub> + *a*<sub class=... | 1,000 | [
{
"input": "2 1 1\n1 5",
"output": "6.00000000"
},
{
"input": "4 2 1\n1 4 2 3",
"output": "6.50000000"
},
{
"input": "3 1 2\n1 2 3",
"output": "4.50000000"
},
{
"input": "10 4 6\n3 5 7 9 12 25 67 69 83 96",
"output": "88.91666667"
},
{
"input": "19 7 12\n1 2 4 8 1... | 1,680,398,690 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 233 | 9,728,000 | from heapq import nlargest,heapify
def solve():
n,n1,n2=map(int,input().split());a=sorted(list(map(int,input().split())));heapify(a)
t=sum(nlargest(min(n1,n2),a))/min(n1,n2)
t1=sum(nlargest(max(n1,n2),a[:n-(min(n1,n2))]))/max(n1,n2)
print(t1+t)
solve()
# 3 2
# 2 3 4 5 6 | Title: Urbanization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* o... | ```python
from heapq import nlargest,heapify
def solve():
n,n1,n2=map(int,input().split());a=sorted(list(map(int,input().split())));heapify(a)
t=sum(nlargest(min(n1,n2),a))/min(n1,n2)
t1=sum(nlargest(max(n1,n2),a[:n-(min(n1,n2))]))/max(n1,n2)
print(t1+t)
solve()
# 3 2
# 2 3 4 5 6
``` | 3 | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,697,226,938 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | from sys import stdin
s = []
for i in stdin:
s.append(i.rstrip('\n'))
m = [i for i in s[1:]]
n = [i for i in m if i.count('1') > 1]
print(len(n)) | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
from sys import stdin
s = []
for i in stdin:
s.append(i.rstrip('\n'))
m = [i for i in s[1:]]
n = [i for i in m if i.count('1') > 1]
print(len(n))
``` | 3 | |
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec... | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"... | 1,617,042,344 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 0 | n = int(input())
s = input()
ans = [0]*n
addi=1
if(n%2 == 0):
idx = n//2-1
sign = 1
else:
idx = n//2
sign = -1
for i in range(n):
ans[idx] = s[i]
idx += (addi*sign)
addi += 1
sign *= -1
print(''.join(ans)) | Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the... | ```python
n = int(input())
s = input()
ans = [0]*n
addi=1
if(n%2 == 0):
idx = n//2-1
sign = 1
else:
idx = n//2
sign = -1
for i in range(n):
ans[idx] = s[i]
idx += (addi*sign)
addi += 1
sign *= -1
print(''.join(ans))
``` | 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,549,816,827 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 124 | 0 | s1=list(input())
s2=list(input())
for i in range(len(s1)):
if s1[i]==s2[i]:
s1[i]='0'
else:
s1[i]='1'
s1="".join(s1)
print(s1) | 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
s1=list(input())
s2=list(input())
for i in range(len(s1)):
if s1[i]==s2[i]:
s1[i]='0'
else:
s1[i]='1'
s1="".join(s1)
print(s1)
``` | 3.969 |
909 | A | Generate Login | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"sortings"
] | null | null | The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and ... | The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. | Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. | [
"harry potter\n",
"tom riddle\n"
] | [
"hap\n",
"tomr\n"
] | none | 500 | [
{
"input": "harry potter",
"output": "hap"
},
{
"input": "tom riddle",
"output": "tomr"
},
{
"input": "a qdpinbmcrf",
"output": "aq"
},
{
"input": "wixjzniiub ssdfodfgap",
"output": "wis"
},
{
"input": "z z",
"output": "zz"
},
{
"input": "ertuyivhfg v"... | 1,515,119,086 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 62 | 5,529,600 | f,s = input().split()
l = f[0]
for c in f[1:]:
if c >= s[0]: break
l += c
print(l + s[0]);
| Title: Generate Login
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the fu... | ```python
f,s = input().split()
l = f[0]
for c in f[1:]:
if c >= s[0]: break
l += c
print(l + s[0]);
``` | 3 | |
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,667,394,061 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 | word=input()
a=0
b=0
for i in word:
if i.isupper():
a+=1
else:
b+=1
if a>b:
print(word.upper())
else:
print(word.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
word=input()
a=0
b=0
for i in word:
if i.isupper():
a+=1
else:
b+=1
if a>b:
print(word.upper())
else:
print(word.lower())
``` | 3.969 |
47 | A | Triangular numbers | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Triangular numbers | 2 | 256 | A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers fr... | The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. | If the given integer is a triangular number output YES, otherwise output NO. | [
"1\n",
"2\n",
"3\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "2",
"output": "NO"
},
{
"input": "3",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "NO... | 1,675,403,458 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | #4266668 Aug 11, 2013 7:39:45 PM fuwutu 47A - Triangular numbers Python 3 Accepted 124 ms 0 KB
n = int(input())
triangular = 1
i = 1
while triangular < n:
i += 1
triangular += i
if triangular == n:
print("YES")
else:
print("NO")
| Title: Triangular numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t... | ```python
#4266668 Aug 11, 2013 7:39:45 PM fuwutu 47A - Triangular numbers Python 3 Accepted 124 ms 0 KB
n = int(input())
triangular = 1
i = 1
while triangular < n:
i += 1
triangular += i
if triangular == n:
print("YES")
else:
print("NO")
``` | 3.977 |
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.