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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
670 | A | Holidays | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"greedy",
"math"
] | null | null | On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars. | Print two integers — the minimum possible and the maximum possible number of days off per year on Mars. | [
"14\n",
"2\n"
] | [
"4 4\n",
"0 2\n"
] | In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off. | 500 | [
{
"input": "14",
"output": "4 4"
},
{
"input": "2",
"output": "0 2"
},
{
"input": "1",
"output": "0 1"
},
{
"input": "3",
"output": "0 2"
},
{
"input": "4",
"output": "0 2"
},
{
"input": "5",
"output": "0 2"
},
{
"input": "6",
"output":... | 1,693,657,313 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | n = int(input())
min_days_off = (n // 7) * 2
max_days_off = min_days_off + min(2, n % 7)
print(min_days_off, max_days_off)
| Title: Holidays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maxim... | ```python
n = int(input())
min_days_off = (n // 7) * 2
max_days_off = min_days_off + min(2, n % 7)
print(min_days_off, max_days_off)
``` | 0 | |
462 | B | Appleman and Card Game | PROGRAMMING | 1,300 | [
"greedy"
] | null | null | Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to lette... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman. | Print a single integer – the answer to the problem. | [
"15 10\nDZFDFZDFDDDDDDF\n",
"6 4\nYJSNPI\n"
] | [
"82\n",
"4\n"
] | In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin. | 1,000 | [
{
"input": "15 10\nDZFDFZDFDDDDDDF",
"output": "82"
},
{
"input": "6 4\nYJSNPI",
"output": "4"
},
{
"input": "5 3\nAOWBY",
"output": "3"
},
{
"input": "1 1\nV",
"output": "1"
},
{
"input": "2 1\nWT",
"output": "1"
},
{
"input": "2 2\nBL",
"output":... | 1,599,641,630 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 155 | 4,198,400 | n,k=map(int,input().split())
s=list(input())
d={}
for i in s:
try:
d[i]+=1
except:
d[i]=1
new=[]
for keys in d:
new.append(d[keys])
new.sort(reverse=True)
i=0
total=0
while(k>0):
if new[i]<=k:
total+=(new[i]**2)
k-=new[i]
i+=1
else:
... | Title: Appleman and Card Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally... | ```python
n,k=map(int,input().split())
s=list(input())
d={}
for i in s:
try:
d[i]+=1
except:
d[i]=1
new=[]
for keys in d:
new.append(d[keys])
new.sort(reverse=True)
i=0
total=0
while(k>0):
if new[i]<=k:
total+=(new[i]**2)
k-=new[i]
i+=1
else... | 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,680,093,596 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | a="abcdefghijklmnopqrstuvwxyz"
word=input()
if sum([c in a for c in word]) < (len(word)+1)/2:
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
a="abcdefghijklmnopqrstuvwxyz"
word=input()
if sum([c in a for c in word]) < (len(word)+1)/2:
print(word.upper())
else:
print(word.lower())
``` | 0 |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,692,360,192 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | h=int(input())
g=list(map(int,input().split()))
y=0
for i in range(h):
y+=g[i]
if y>sum(g[i+1:]):break
print(i+1) | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
h=int(input())
g=list(map(int,input().split()))
y=0
for i in range(h):
y+=g[i]
if y>sum(g[i+1:]):break
print(i+1)
``` | 0 | |
110 | A | Nearly Lucky Number | PROGRAMMING | 800 | [
"implementation"
] | A. Nearly Lucky Number | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d... | The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). | [
"40047\n",
"7747774\n",
"1000000000000000000\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | 500 | [
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
... | 1,696,616,657 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | x = input()
total = 0
for i in range(len(x)):
if x[i] == '4' or x[i] == '7':
total += 1
if total > 7:
break
if total == 4 or total == 7:
print('YES')
else:
print('NO') | Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
x = input()
total = 0
for i in range(len(x)):
if x[i] == '4' or x[i] == '7':
total += 1
if total > 7:
break
if total == 4 or total == 7:
print('YES')
else:
print('NO')
``` | 3.977 |
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,679,330,082 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 46 | 0 | a=input()
b=input()
d=len(a)
c=""
for i in range(d):
if((int(a[i])+int(b[i]))==2):
c=c+"0"
else:
c=c+str(int(a[i])+int(b[i]))
print(c) | 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
a=input()
b=input()
d=len(a)
c=""
for i in range(d):
if((int(a[i])+int(b[i]))==2):
c=c+"0"
else:
c=c+str(int(a[i])+int(b[i]))
print(c)
``` | 3.9885 |
774 | C | Maximum Number | PROGRAMMING | 1,200 | [
"*special",
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.
So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. ... | The first line contains the integer *n* (2<=≤<=*n*<=≤<=100<=000) — the maximum number of sections which can be highlighted on the display. | Print the maximum integer which can be shown on the display of Stepan's newest device. | [
"2\n",
"3\n"
] | [
"1\n",
"7\n"
] | none | 0 | [
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "7"
},
{
"input": "4",
"output": "11"
},
{
"input": "5",
"output": "71"
},
{
"input": "6",
"output": "111"
},
{
"input": "85651",
"output": "711111111111111111111111111111111111111111111111... | 1,546,792,107 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 78 | 0 | t = int(input())
for z in range(t):
n = int(input())
d = {0:6, 1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
s = 0
for i in str(n):
s+=i
| Title: Maximum Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.
So, for example, to show the digit 3 o... | ```python
t = int(input())
for z in range(t):
n = int(input())
d = {0:6, 1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
s = 0
for i in str(n):
s+=i
``` | -1 | |
358 | A | Dima and Continuous Line | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect th... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate. | In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes). | [
"4\n0 10 5 15\n",
"4\n0 15 5 10\n"
] | [
"yes\n",
"no\n"
] | The first test from the statement is on the picture to the left, the second test is on the picture to the right. | 500 | [
{
"input": "4\n0 10 5 15",
"output": "yes"
},
{
"input": "4\n0 15 5 10",
"output": "no"
},
{
"input": "5\n0 1000 2000 3000 1500",
"output": "yes"
},
{
"input": "5\n-724093 710736 -383722 -359011 439613",
"output": "no"
},
{
"input": "50\n384672 661179 -775591 -989... | 1,588,000,581 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | n=int(input())
x = list(map(int, input().split()))
if(n<=3):
print("no")
else:
for i in range(n-3):
if(x[i]<x[i+2]<x[i+1]<x[i+3] or x[i+2]<x[i]<x[i+3]<x[i+1]):
print("yes")
else:
print("no")
| Title: Dima and Continuous Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher g... | ```python
n=int(input())
x = list(map(int, input().split()))
if(n<=3):
print("no")
else:
for i in range(n-3):
if(x[i]<x[i+2]<x[i+1]<x[i+3] or x[i+2]<x[i]<x[i+3]<x[i+1]):
print("yes")
else:
print("no")
``` | 0 | |
73 | A | The Elder Trolls IV: Oblivon | PROGRAMMING | 1,600 | [
"greedy",
"math"
] | A. The Elder Trolls IV: Oblivon | 2 | 256 | Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so ... | The first line of input contains four integer numbers *x*,<=*y*,<=*z*,<=*k* (1<=≤<=*x*,<=*y*,<=*z*<=≤<=106,<=0<=≤<=*k*<=≤<=109). | Output the only number — the answer for the problem.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). | [
"2 2 2 3\n",
"2 2 2 1\n"
] | [
"8",
"2"
] | In the first sample Vasya make 3 pairwise perpendicular cuts. He cuts monster on two parts with the first cut, then he divides each part on two with the second cut, and finally he divides each of the 4 parts on two. | 500 | [
{
"input": "2 2 2 3",
"output": "8"
},
{
"input": "2 2 2 1",
"output": "2"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "1 2 3 3",
"output": "6"
},
{
"input": "20 4 5 12",
"output": "120"
},
{
"input": "100 500 100500 1000000000",
"output":... | 1,699,805,619 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | y=int(input())
s=input()
A=0
D=0
for i in range(s):
if i=="A":
A+=1
else:
D+=1
if A>D:
print("Anton")
elif D>A:
print("Danik")
else:
print("Friendship") | Title: The Elder Trolls IV: Oblivon
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monste... | ```python
y=int(input())
s=input()
A=0
D=0
for i in range(s):
if i=="A":
A+=1
else:
D+=1
if A>D:
print("Anton")
elif D>A:
print("Danik")
else:
print("Friendship")
``` | -1 |
0 | none | none | none | 0 | [
"none"
] | null | null | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of actions Valentin did.
The next *n* lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. Th... | Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. | [
"5\n! abc\n. ad\n. b\n! cd\n? c\n",
"8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e\n",
"7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first test case after the first action it becomes clear that the selected letter is one of the following: *a*, *b*, *c*. After the second action we can note that the selected letter is not *a*. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is *c*, but Valentin p... | 0 | [
{
"input": "5\n! abc\n. ad\n. b\n! cd\n? c",
"output": "1"
},
{
"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e",
"output": "2"
},
{
"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h",
"output": "0"
},
{
"input": "4\n! abcd\n! cdef\n? d\n? c",
"o... | 1,514,214,166 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 5,529,600 | s=set('abcdefghijklmnopqrstuvwxyz')
d=0
for _ in range(int(input())):
a,b=input().split()
if a=='!':s&=set(b)
else:s-=set(b)
if len(s) == 1 and a in '?!': d += 1
print(d)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter... | ```python
s=set('abcdefghijklmnopqrstuvwxyz')
d=0
for _ in range(int(input())):
a,b=input().split()
if a=='!':s&=set(b)
else:s-=set(b)
if len(s) == 1 and a in '?!': d += 1
print(d)
``` | 0 | |
401 | A | Vanya and Cards | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value.
Natasha doesn't like when Vanya spends a long time p... | The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their a... | Print a single number — the answer to the problem. | [
"3 2\n-1 1 2\n",
"2 3\n-2 -2\n"
] | [
"1\n",
"2\n"
] | In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | 500 | [
{
"input": "3 2\n-1 1 2",
"output": "1"
},
{
"input": "2 3\n-2 -2",
"output": "2"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
},
{
"input": "2 2\n-1 -1",
"output": "1"
},
{
"input": "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2",
"output": "4"
},
{
"... | 1,614,233,387 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 108 | 0 |
n,m = map(int,input().split())
t = list(map(int,input().split()))
u= sum(t)
if u==0:print(0)
else:
if abs(u)<=m:print(1)
else:
if abs(u)%m==0:print(abs(u)//m)
else:print((abs(u)//m)+1)
| Title: Vanya and Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each... | ```python
n,m = map(int,input().split())
t = list(map(int,input().split()))
u= sum(t)
if u==0:print(0)
else:
if abs(u)<=m:print(1)
else:
if abs(u)%m==0:print(abs(u)//m)
else:print((abs(u)//m)+1)
``` | 3 | |
552 | A | Vanya and Table | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.
In this table, Vanya chose *n* rectangles with sides that go along borders of squares (some rectangles probably occur mu... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of rectangles.
Each of the following *n* lines contains four integers *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1<=≤<=*x*2<=≤<=100, 1<=≤<=*y*1<=≤<=*y*2<=≤<=100), where *x*1 and *y*1 are the number of the column and row of the lower left cell and *x*2 and *... | In a single line print the sum of all values in the cells of the table. | [
"2\n1 1 2 3\n2 2 3 3\n",
"2\n1 1 3 3\n1 1 3 3\n"
] | [
"10\n",
"18\n"
] | Note to the first sample test:
Values of the table in the first three rows and columns will be as follows:
121
121
110
So, the sum of values will be equal to 10.
Note to the second sample test:
Values of the table in the first three rows and columns will be as follows:
222
222
222
So, the sum of values will ... | 500 | [
{
"input": "2\n1 1 2 3\n2 2 3 3",
"output": "10"
},
{
"input": "2\n1 1 3 3\n1 1 3 3",
"output": "18"
},
{
"input": "5\n4 11 20 15\n7 5 12 20\n10 8 16 12\n7 5 12 15\n2 2 20 13",
"output": "510"
},
{
"input": "5\n4 11 20 20\n6 11 20 16\n5 2 19 15\n11 3 18 15\n3 2 14 11",
"o... | 1,618,458,453 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 124 | 2,150,400 | def proA(arr):
for i in arr:
x,y,a,b=i
ans+= (a-x)*(b-y)
return ans
t=int(input())
for i in range(t):
#n=int(input())
arr.append(list(map(int,input().split())))
#proD(arr)
print(proA(arr)) | Title: Vanya and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.
In this table, Vany... | ```python
def proA(arr):
for i in arr:
x,y,a,b=i
ans+= (a-x)*(b-y)
return ans
t=int(input())
for i in range(t):
#n=int(input())
arr.append(list(map(int,input().split())))
#proD(arr)
print(proA(arr))
``` | -1 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,628,346,755 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 6,656,000 | x,y,z=map(int, input().split())
print([(x+y)*2,x+y+z][max(x,y)*2>=z]) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
x,y,z=map(int, input().split())
print([(x+y)*2,x+y+z][max(x,y)*2>=z])
``` | 0 | |
478 | B | Random Teams | PROGRAMMING | 1,300 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that coul... | The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively. | The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. | [
"5 1\n",
"3 2\n",
"6 3\n"
] | [
"10 10\n",
"1 1\n",
"3 6\n"
] | In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
... | 1,000 | [
{
"input": "5 1",
"output": "10 10"
},
{
"input": "3 2",
"output": "1 1"
},
{
"input": "6 3",
"output": "3 6"
},
{
"input": "5 3",
"output": "2 3"
},
{
"input": "10 2",
"output": "20 36"
},
{
"input": "10 6",
"output": "4 10"
},
{
"input": ... | 1,677,739,633 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 93 | 0 | a,b = ([int(x) for x in input().split()])
c=a-(b-1)
d=(c*(c-1))//2
e=a//b
f=a%b
g=b-f
h=g*(e*(e-1))//2 + f*(e*(e+1))//2
print(h,d) | Title: Random Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is ... | ```python
a,b = ([int(x) for x in input().split()])
c=a-(b-1)
d=(c*(c-1))//2
e=a//b
f=a%b
g=b-f
h=g*(e*(e-1))//2 + f*(e*(e+1))//2
print(h,d)
``` | 3 | |
190 | A | Vasya and the Bus | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had *n* grown-ups and *m* kids..."
The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers cou... | The input file consists of a single line containing two space-separated numbers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=105) — the number of the grown-ups and the number of the children in the bus, correspondingly. | If *n* grown-ups and *m* children could have ridden in the bus, then print on a single line two space-separated integers — the minimum and the maximum possible total bus fare, correspondingly.
Otherwise, print "Impossible" (without the quotes). | [
"1 2\n",
"0 5\n",
"2 2\n"
] | [
"2 2",
"Impossible",
"2 3"
] | In the first sample a grown-up rides with two children and pays two rubles.
In the second sample there are only children in the bus, so the situation is impossible.
In the third sample there are two cases: - Each of the two grown-ups rides with one children and pays one ruble for the tickets. In this case the passen... | 500 | [
{
"input": "1 2",
"output": "2 2"
},
{
"input": "0 5",
"output": "Impossible"
},
{
"input": "2 2",
"output": "2 3"
},
{
"input": "2 7",
"output": "7 8"
},
{
"input": "4 10",
"output": "10 13"
},
{
"input": "6 0",
"output": "6 6"
},
{
"input... | 1,600,714,288 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 248 | 0 |
n,m = map(int,input().split())
if n==0 :
print("IMPOSSIBLE")
else:
if m==0 :
print(n,n)
elif n==m :
print(n,n+m-1)
elif n>m :
print(n,n+m-1)
elif n<m :
print((m//n)*n + m%n ,n+m-1) | Title: Vasya and the Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had *n* grown-ups and *m* kids..."
The latter events happen to be of no importance to us. Vasya is an accountant... | ```python
n,m = map(int,input().split())
if n==0 :
print("IMPOSSIBLE")
else:
if m==0 :
print(n,n)
elif n==m :
print(n,n+m-1)
elif n>m :
print(n,n+m-1)
elif n<m :
print((m//n)*n + m%n ,n+m-1)
``` | 0 | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,639,776,660 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 10,240,000 | import sys
def solve(L,B):
S=0
S2=0
for e in B:
S=S+L.index(e)+1
print(S,len(B)*len(L)-(S-len(B)))
_ = sys.stdin.readline()
L = list(map(int,sys.stdin.readline().split()))
_ = sys.stdin.readline()
B = list(map(int,sys.stdin.readline().split()))
solve(L,B) | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
import sys
def solve(L,B):
S=0
S2=0
for e in B:
S=S+L.index(e)+1
print(S,len(B)*len(L)-(S-len(B)))
_ = sys.stdin.readline()
L = list(map(int,sys.stdin.readline().split()))
_ = sys.stdin.readline()
B = list(map(int,sys.stdin.readline().split()))
solve(L,B)
``` | 0 | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,664,013,427 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | no3=int(input())
no4=list(map(int,input().split()))
while(0 in no4):
no4.remove(0)
no4=set(no4)
print(len(no4))
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
no3=int(input())
no4=list(map(int,input().split()))
while(0 in no4):
no4.remove(0)
no4=set(no4)
print(len(no4))
``` | 3 | |
902 | B | Coloring a Tree | PROGRAMMING | 1,200 | [
"dfs and similar",
"dsu",
"greedy"
] | null | null | You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
You have to color the tree into the given colors using the smallest possible number of steps. On eac... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=104) — the number of vertices in the tree.
The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=<<=*i*), where *p**i* means that there is an edge between vertices *i* and *p**i*.
The third line contains *n* integers *c*1,<... | Print a single integer — the minimum number of steps you have to perform to color the tree into given colors. | [
"6\n1 2 2 1 5\n2 1 1 1 1 1\n",
"7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n"
] | [
"3\n",
"5\n"
] | The tree from the first sample is shown on the picture (numbers are vetices' indices):
<img class="tex-graphics" src="https://espresso.codeforces.com/10324ccdc37f95343acc4f3c6050d8c334334ffa.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On first step we color all vertices in the subtree of vertex 1 into color ... | 1,000 | [
{
"input": "6\n1 2 2 1 5\n2 1 1 1 1 1",
"output": "3"
},
{
"input": "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3",
"output": "5"
},
{
"input": "2\n1\n2 2",
"output": "1"
},
{
"input": "3\n1 1\n2 2 2",
"output": "1"
},
{
"input": "4\n1 2 1\n1 2 3 4",
"output": "4"
},
{
... | 1,644,863,382 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 124 | 5,734,400 | from collections import defaultdict as di
from collections import deque as dq
n=int(input())
coupl = di(list)
nodess = [int(x)-1 for x in input().split()]
for i in range(n-1):
node = nodess[i]
coupl[i+1].append(node)
coupl[node].append(i+1)
colors = [int(x)-1 for x in input().split()]
Q=dq()
... | Title: Coloring a Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
... | ```python
from collections import defaultdict as di
from collections import deque as dq
n=int(input())
coupl = di(list)
nodess = [int(x)-1 for x in input().split()]
for i in range(n-1):
node = nodess[i]
coupl[i+1].append(node)
coupl[node].append(i+1)
colors = [int(x)-1 for x in input().split()]
... | 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,653,576,405 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | s=int(input())
s1=int(input())
a=str(s)
y=str(s1)
x=""
for i in range(len(a)):
if(a[i]==y[i]):
x=x+"0"
else:
x=x+"1"
print("".join(list(x)))
| 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
s=int(input())
s1=int(input())
a=str(s)
y=str(s1)
x=""
for i in range(len(a)):
if(a[i]==y[i]):
x=x+"0"
else:
x=x+"1"
print("".join(list(x)))
``` | -1 |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,672,005,283 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 46 | 2,867,200 | n, k = input().split()
# n, k = 10, 6
k = int(k)
numbers = []
counter = 0
if k > 4:
for _ in range(int(n)):
i = input()
for j in range(k, 10):
if j not in i:
break
else:
counter += 1
else:
for _ in range(int(n)):
i = input()
... | Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve... | ```python
n, k = input().split()
# n, k = 10, 6
k = int(k)
numbers = []
counter = 0
if k > 4:
for _ in range(int(n)):
i = input()
for j in range(k, 10):
if j not in i:
break
else:
counter += 1
else:
for _ in range(int(n)):
i ... | -1 | |
433 | A | Kitahara Haruki's Gift | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equa... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple. | In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes). | [
"3\n100 200 100\n",
"4\n100 100 100 200\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | 500 | [
{
"input": "3\n100 200 100",
"output": "YES"
},
{
"input": "4\n100 100 100 200",
"output": "NO"
},
{
"input": "1\n100",
"output": "NO"
},
{
"input": "1\n200",
"output": "NO"
},
{
"input": "2\n100 100",
"output": "YES"
},
{
"input": "2\n200 200",
"o... | 1,636,710,121 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<stdio.h>
int main()
{
int i,a[101],b,c,d,e,f,g,m,n;
scanf("%d",&i);
c=0;
d=0;
e=0;
g=0;
for(b=1;b<=i;b++)
{
scanf("%d",&a[b]);
getchar();
if(a[b]==100)
d++;
if(a[b]==200)
e++;
c=c+a[b];
}
for(m=0;m<=d;m++)
{
... | Title: Kitahara Haruki's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't w... | ```python
#include<stdio.h>
int main()
{
int i,a[101],b,c,d,e,f,g,m,n;
scanf("%d",&i);
c=0;
d=0;
e=0;
g=0;
for(b=1;b<=i;b++)
{
scanf("%d",&a[b]);
getchar();
if(a[b]==100)
d++;
if(a[b]==200)
e++;
c=c+a[b];
}
for(m=0;m<=d;m+... | -1 | |
804 | A | Find Amir | PROGRAMMING | 1,000 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* an... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of schools. | Print single integer: the minimum cost of tickets needed to visit all schools. | [
"2\n",
"10\n"
] | [
"0\n",
"4\n"
] | In the first example we can buy a ticket between the schools that costs <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c67d72010e0498bfd065a6a38fdeaec90358507b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "2",
"output": "0"
},
{
"input": "10",
"output": "4"
},
{
"input": "43670",
"output": "21834"
},
{
"input": "4217",
"output": "2108"
},
{
"input": "17879",
"output": "8939"
},
{
"input": "31809",
"output": "15904"
},
{
"input": "... | 1,655,516,842 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | x = int(input())
print((x-1)/2) | Title: Find Amir
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel b... | ```python
x = int(input())
print((x-1)/2)
``` | 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,609,510,637 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 248 | 0 | n=int(input())
l=list(map(int,input().split()))
a,b,c,d=0,0,0,0
for i in range(n):
if l[i]%2==0:
a+=1
b=i
else:
c+=1
d=i
if b==1:
print(b+1)
elif c==1:
print(d+1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n=int(input())
l=list(map(int,input().split()))
a,b,c,d=0,0,0,0
for i in range(n):
if l[i]%2==0:
a+=1
b=i
else:
c+=1
d=i
if b==1:
print(b+1)
elif c==1:
print(d+1)
``` | 0 |
893 | C | Rumor | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Ove... | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
... | Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example ... | 0 | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n10000000... | 1,665,558,208 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 530 | 16,793,600 | from collections import defaultdict
n,m = list(map(int,input().split()))
arr = list(map(int,input().split()))
parent = [i for i in range(n+1)]
rank = [0]*(n+1)
def find(p):
while p != parent[p]:
p = parent[p]
return p
def union(x, y):
x = find(x)
y = find(y)
if x!=y... | Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte... | ```python
from collections import defaultdict
n,m = list(map(int,input().split()))
arr = list(map(int,input().split()))
parent = [i for i in range(n+1)]
rank = [0]*(n+1)
def find(p):
while p != parent[p]:
p = parent[p]
return p
def union(x, y):
x = find(x)
y = find(y)
... | 3 | |
633 | A | Ebony and Ivory | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of ... | The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. | Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. | [
"4 6 15\n",
"3 2 7\n",
"6 11 6\n"
] | [
"No\n",
"Yes\n",
"Yes\n"
] | In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. | 250 | [
{
"input": "4 6 15",
"output": "No"
},
{
"input": "3 2 7",
"output": "Yes"
},
{
"input": "6 11 6",
"output": "Yes"
},
{
"input": "3 12 15",
"output": "Yes"
},
{
"input": "5 5 10",
"output": "Yes"
},
{
"input": "6 6 7",
"output": "No"
},
{
"... | 1,681,464,856 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 134 | 93 | 1,536,000 | a, b, c = map(int, input().split())
ans = "NO"
for i in range(c+1):
tmp = c - a*i
if tmp >= 0 and tmp%b == 0:
#print(i, (c-a*i)//b)
ans = "YES"
break
print(ans) | Title: Ebony and Ivory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
F... | ```python
a, b, c = map(int, input().split())
ans = "NO"
for i in range(c+1):
tmp = c - a*i
if tmp >= 0 and tmp%b == 0:
#print(i, (c-a*i)//b)
ans = "YES"
break
print(ans)
``` | 3 | |
400 | B | Inna and New Matrix of Candies | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"schedules"
] | null | null | Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The g... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 2<=≤<=*m*<=≤<=1000).
Next *n* lines each contain *m* characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a can... | In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field. | [
"3 4\n*G*S\nG**S\n*G*S\n",
"1 3\nS*G\n"
] | [
"2\n",
"-1\n"
] | none | 1,000 | [
{
"input": "3 4\n*G*S\nG**S\n*G*S",
"output": "2"
},
{
"input": "1 3\nS*G",
"output": "-1"
},
{
"input": "10 10\nG********S\n*G*******S\n**G******S\n***G*****S\n****G****S\n*****G***S\n******G**S\n*******G*S\n********GS\nG********S",
"output": "9"
},
{
"input": "5 10\nG***S**... | 1,461,713,289 | 4,089 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 4,608,000 | '''
Created on 27.4.2016
@author: Ivan
'''
import sys
class Pair:
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return str(self.x) + " " + str(self.y)
def __eq__(self, other):
return self.x == other.x and self.y == other.y
def __hash__(... | Title: Inna and New Matrix of Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of th... | ```python
'''
Created on 27.4.2016
@author: Ivan
'''
import sys
class Pair:
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return str(self.x) + " " + str(self.y)
def __eq__(self, other):
return self.x == other.x and self.y == other.y
def... | 0 | |
254 | A | Cards with Numbers | PROGRAMMING | 1,200 | [
"constructive algorithms",
"sortings"
] | null | null | Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces. | If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You... | [
"3\n20 30 10 30 20 10\n",
"1\n1 2\n"
] | [
"4 2\n1 5\n6 3\n",
"-1"
] | none | 500 | [
{
"input": "3\n20 30 10 30 20 10",
"output": "4 2\n1 5\n6 3"
},
{
"input": "1\n1 2",
"output": "-1"
},
{
"input": "5\n2 2 2 2 2 1 2 2 1 2",
"output": "2 1\n3 4\n7 5\n6 9\n10 8"
},
{
"input": "5\n2 1 2 2 1 1 1 1 1 2",
"output": "3 1\n2 5\n7 6\n8 9\n10 4"
},
{
"inpu... | 1,686,132,668 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 498 | 75,468,800 | import string
from collections import deque
alph = string.ascii_lowercase
def main():
with open('input.txt', 'r') as fin:
f = fin.readlines()
n = int(f[0])
a = list(map(int, f[1].split()))
d = {i:0 for i in a}
for i in a:
d[i] += 1
flag = 1
for i in li... | Title: Cards with Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card wit... | ```python
import string
from collections import deque
alph = string.ascii_lowercase
def main():
with open('input.txt', 'r') as fin:
f = fin.readlines()
n = int(f[0])
a = list(map(int, f[1].split()))
d = {i:0 for i in a}
for i in a:
d[i] += 1
flag = 1
f... | 3 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,587,792,836 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | x, y, z = map(int, input().split())
tracking = (x + y) * 2
if tracking < z:
print(tracking)
else:
print(x+y+z) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
x, y, z = map(int, input().split())
tracking = (x + y) * 2
if tracking < z:
print(tracking)
else:
print(x+y+z)
``` | 0 | |
999 | C | Alphabetic Removals | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next ite... | The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove.
The second line contains the string $s$ consisting of $n$ lowercase Latin letters. | Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times.
If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). | [
"15 3\ncccaabababaccbc\n",
"15 9\ncccaabababaccbc\n",
"1 1\nu\n"
] | [
"cccbbabaccbc\n",
"cccccc\n",
""
] | none | 0 | [
{
"input": "15 3\ncccaabababaccbc",
"output": "cccbbabaccbc"
},
{
"input": "15 9\ncccaabababaccbc",
"output": "cccccc"
},
{
"input": "5 2\nzyzyx",
"output": "zzy"
},
{
"input": "4 3\nhack",
"output": "k"
},
{
"input": "4 3\nzzzz",
"output": "z"
},
{
"i... | 1,682,240,564 | 2,264 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 56,934,400 | n,k=map(int,input().split())
a=[i for i in input()]
d={}
for i in a:
d[i]=d.get(i,0)+1
p=list(d.keys())
p.sort()
z="a"
flag=True
for i in p:
if k>=d[i]:
k-=d[i]
else:
z=i
flag=False
break
t=""
if flag:
z=chr(ord(p[-1])+1)
for i in a:
if i>z:
... | Title: Alphabetic Removals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is... | ```python
n,k=map(int,input().split())
a=[i for i in input()]
d={}
for i in a:
d[i]=d.get(i,0)+1
p=list(d.keys())
p.sort()
z="a"
flag=True
for i in p:
if k>=d[i]:
k-=d[i]
else:
z=i
flag=False
break
t=""
if flag:
z=chr(ord(p[-1])+1)
for i in a:
if i... | 0 | |
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\... | 1,617,174,720 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 139 | 7,168,000 | n=int(input())
m=input().split()
sum1=0
weak=[]
strong=[]
for i in range(n):
m[i]=int(m[i])
for i in m:
if i%2==0:
weak.append(i)
if i%2==1:
strong.append(i)
sum1+=sum(weak)
strong.sort()
if len(strong)%2==0:
sum1+=sum(strong)
if len(strong)%2==1:
... | Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, th... | ```python
n=int(input())
m=input().split()
sum1=0
weak=[]
strong=[]
for i in range(n):
m[i]=int(m[i])
for i in m:
if i%2==0:
weak.append(i)
if i%2==1:
strong.append(i)
sum1+=sum(weak)
strong.sort()
if len(strong)%2==0:
sum1+=sum(strong)
if len(stro... | 0 | |
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He lik... | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
... | 1,634,081,550 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 154 | 6,758,400 | # import inbuilt standard input output
from sys import stdin, stdout
def main():
len_ = int(stdin.readline())
if len_%2 == 0:
str_ = []
for j in range(0, len_, 2):
str_.append(str(j + 2))
str_.append(str(j + 1))
string_ = " ".join(str_)
stdout.write(strin... | Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ... | ```python
# import inbuilt standard input output
from sys import stdin, stdout
def main():
len_ = int(stdin.readline())
if len_%2 == 0:
str_ = []
for j in range(0, len_, 2):
str_.append(str(j + 2))
str_.append(str(j + 1))
string_ = " ".join(str_)
stdout.w... | 3 | |
92 | B | Binary Number | PROGRAMMING | 1,300 | [
"greedy"
] | B. Binary Number | 1 | 256 | Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divide... | The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106. | Print the required number of actions. | [
"1\n",
"1001001\n",
"101110\n"
] | [
"0\n",
"12\n",
"8\n"
] | Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide... | 1,000 | [
{
"input": "1",
"output": "0"
},
{
"input": "1001001",
"output": "12"
},
{
"input": "101110",
"output": "8"
},
{
"input": "11",
"output": "3"
},
{
"input": "11110001101",
"output": "16"
},
{
"input": "101010100100111100011111001111100001010101111110101... | 1,605,937,841 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 10 | 186 | 8,601,600 | s = input()[::-1]
pr = 0
ans = 0
if s == '1':
print(0)
exit()
for i in s:
if i == '0' and pr == 0:
ans += 1
elif i == '0' and pr == 1:
ans += 2
elif i == '1' and pr == 1:
ans += 1
elif i == '1' and pr == 0:
ans += 2
pr = 1
print(ans) | Title: Binary Number
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to ... | ```python
s = input()[::-1]
pr = 0
ans = 0
if s == '1':
print(0)
exit()
for i in s:
if i == '0' and pr == 0:
ans += 1
elif i == '0' and pr == 1:
ans += 2
elif i == '1' and pr == 1:
ans += 1
elif i == '1' and pr == 0:
ans += 2
pr = 1
print(a... | 0 |
757 | B | Bash's Big Day | PROGRAMMING | 1,400 | [
"greedy",
"math",
"number theory"
] | null | null | Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.
But Zulu warns him that a group of *k*<=><=1 Pokemon with strengths {*... | The input consists of two lines.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105), the number of Pokemon in the lab.
The next line contains *n* space separated integers, where the *i*-th of them denotes *s**i* (1<=≤<=*s**i*<=≤<=105), the strength of the *i*-th Pokemon. | Print single integer — the maximum number of Pokemons Bash can take. | [
"3\n2 3 4\n",
"5\n2 3 4 6 7\n"
] | [
"2\n",
"3\n"
] | *gcd* (greatest common divisor) of positive integers set {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>} is the maximum positive integer that divides all the integers {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a... | 1,000 | [
{
"input": "3\n2 3 4",
"output": "2"
},
{
"input": "5\n2 3 4 6 7",
"output": "3"
},
{
"input": "3\n5 6 4",
"output": "2"
},
{
"input": "8\n41 74 4 27 85 39 100 36",
"output": "4"
},
{
"input": "6\n89 20 86 81 62 23",
"output": "3"
},
{
"input": "71\n23... | 1,615,566,308 | 2,147,483,647 | PyPy 3 | OK | TESTS | 134 | 467 | 10,854,400 | from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
factors = defaultdict(int)
for i in range(n):
root = int(a[i]**0.5)
for j in range(2,root+1):
if a[i]%j==0:
factors[j]+=1
while a[i]%j==0:
a[i]//=j
if a[i]>1:
f... | Title: Bash's Big Day
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon fr... | ```python
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
factors = defaultdict(int)
for i in range(n):
root = int(a[i]**0.5)
for j in range(2,root+1):
if a[i]%j==0:
factors[j]+=1
while a[i]%j==0:
a[i]//=j
if a[i]>1:
... | 3 | |
366 | B | Dima and To-do List | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in ... | The first line of the input contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103), where *a**i* is the power Inna tells Dima off with if she is present in the room while he is doing the *i*-th task.
It is guaranteed that *n*... | In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do. | [
"6 2\n3 2 1 6 5 4\n",
"10 5\n1 3 5 7 9 9 4 1 8 5\n"
] | [
"1\n",
"3\n"
] | Explanation of the first example.
If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as *k* = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. I... | 1,000 | [
{
"input": "6 2\n3 2 1 6 5 4",
"output": "1"
},
{
"input": "10 5\n1 3 5 7 9 9 4 1 8 5",
"output": "3"
},
{
"input": "20 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "10 10\n8 4 5 7 6 9 2 2 3 5",
"output": "7"
},
{
"input": "50 10\n1 2 3... | 1,633,281,724 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 6,963,200 | n, k = map(int, input().split())
tasks = list(map(int, input().split()))
min_sum = 10 ** 7
min_start = 1
for i in range(n):
temp = 0
for j in range(i, i+n, k):
temp += tasks[j % n]
if temp < min_sum:
min_sum = temp
min_start = i + 1
print(min_start)
| Title: Dima and To-do List
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything h... | ```python
n, k = map(int, input().split())
tasks = list(map(int, input().split()))
min_sum = 10 ** 7
min_start = 1
for i in range(n):
temp = 0
for j in range(i, i+n, k):
temp += tasks[j % n]
if temp < min_sum:
min_sum = temp
min_start = i + 1
print(min_start)
... | 0 | |
465 | A | inc ARG | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell.
The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan... | Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. | [
"4\n1100\n",
"4\n1111\n"
] | [
"3\n",
"4\n"
] | In the first sample the cell ends up with value 0010, in the second sample — with 0000. | 500 | [
{
"input": "4\n1100",
"output": "3"
},
{
"input": "4\n1111",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "1"
},
{
"input": "2\n01",
"output": "1"
},
{
"input": "2\n1... | 1,633,950,364 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 61 | 6,963,200 | n = int(input())
s = input()
change = 0
in_hand = 1
for i in range(n):
if (int(s[i]) + in_hand) == 0:
pass
elif (int(s[i]) + in_hand) == 1 and s[i] == "1":
pass
elif (int(s[i]) + in_hand) == 1 and in_hand == 1:
in_hand = 0
change += 1
else:
change... | Title: inc ARG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea... | ```python
n = int(input())
s = input()
change = 0
in_hand = 1
for i in range(n):
if (int(s[i]) + in_hand) == 0:
pass
elif (int(s[i]) + in_hand) == 1 and s[i] == "1":
pass
elif (int(s[i]) + in_hand) == 1 and in_hand == 1:
in_hand = 0
change += 1
else:
... | 3 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,686,974,575 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | def can_divide_watermelon(w):
# Check if the weight is even and greater than 2
if w % 2 == 0 and w > 2:
return "YES"
else:
return "NO"
# Get the input weight of the watermelon
w = int(input())
# Check if the watermelon can be divided as desired
result = can_divide_watermelon(w)
# Print th... | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
def can_divide_watermelon(w):
# Check if the weight is even and greater than 2
if w % 2 == 0 and w > 2:
return "YES"
else:
return "NO"
# Get the input weight of the watermelon
w = int(input())
# Check if the watermelon can be divided as desired
result = can_divide_watermelon(w)
... | 3.954 |
776 | A | A Serial Killer | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and t... | Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. | [
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"icm codeforces\n1\ncodeforces technex\n"
] | [
"ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n",
"icm codeforces\nicm technex\n"
] | In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears. | 500 | [
{
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"
},
{
"input": "icm codeforces\n1\ncodeforces technex",
"output": "icm codeforces\nicm technex"
},
{
"input": "a b\n3\na c\n... | 1,530,190,368 | 468 | Python 3 | OK | TESTS | 57 | 108 | 0 | a, b = input().split(' ')
n = int(input())
print(a, b)
for i in range(n):
c, d = input().split(' ')
if c == a:
a = d
else:
b = d
print(a, b)
| Title: A Serial Killer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The... | ```python
a, b = input().split(' ')
n = int(input())
print(a, b)
for i in range(n):
c, d = input().split(' ')
if c == a:
a = d
else:
b = d
print(a, b)
``` | 3 | |
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first positi... | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4... | 1,619,871,237 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 1,123 | 102,400 | from sys import stdin
n=int(stdin.readline())
a=[int(x) for x in stdin.readline().split()]
for i in range(n):
c=0
for j in range(n):
if a[i]<a[j]:
c+=1
print(c+1,end=" ")
| Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the star... | ```python
from sys import stdin
n=int(stdin.readline())
a=[int(x) for x in stdin.readline().split()]
for i in range(n):
c=0
for j in range(n):
if a[i]<a[j]:
c+=1
print(c+1,end=" ")
``` | 3 | |
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (withou... | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa... | 1,674,982,934 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 296 | 0 | n = int(input().strip())
cnt = 0
for i in range(n):
s = input().strip()
if s == "Icosahedron":
cnt += 20
if s == "Cube":
cnt += 6
if s == "Tetrahedron":
cnt += 4
if s == "Dodecahedron":
cnt += 12
if s == "Octahedron":
cnt += 8
print(cnt)
| Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe... | ```python
n = int(input().strip())
cnt = 0
for i in range(n):
s = input().strip()
if s == "Icosahedron":
cnt += 20
if s == "Cube":
cnt += 6
if s == "Tetrahedron":
cnt += 4
if s == "Dodecahedron":
cnt += 12
if s == "Octahedron":
cnt += 8
print(cnt)
``` | 3 | |
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,656,389,029 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 58 | 109 | 512,000 | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
if(k == 1):
print(n)
exit()
for i in range(61, -1, -1):
c = 1 << i
if(n & c):
break
print(2 * c - 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
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
if(k == 1):
print(n)
exit()
for i in range(61, -1, -1):
c = 1 << i
if(n & c):
break
print(2 * c - 1)
``` | 3 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,688,464,057 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | s = input()
l = []
for i in s:
if i != '{' and i != '}' and i != ' ' and i != ',':
l.append(i)
c = 0
print(len(set(l))) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
s = input()
l = []
for i in s:
if i != '{' and i != '}' and i != ' ' and i != ',':
l.append(i)
c = 0
print(len(set(l)))
``` | 3 | |
29 | A | Spit Problem | PROGRAMMING | 1,000 | [
"brute force"
] | A. Spit Problem | 2 | 256 | In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.
... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at wh... | If there are two camels, which spitted at each other, output YES. Otherwise, output NO. | [
"2\n0 1\n1 -1\n",
"3\n0 1\n1 1\n2 -2\n",
"5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "2\n0 1\n1 -1",
"output": "YES"
},
{
"input": "3\n0 1\n1 1\n2 -2",
"output": "NO"
},
{
"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1",
"output": "YES"
},
{
"input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n759... | 1,595,796,375 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 6,656,000 | # -*- coding: utf-8 -*-
lista,dist,cont = [],[],0
n = int(input())
for i in range(n):
x,y = map(int,input().split())
lista.append(x)
dist.append(x+y)
for i in range(n):
if dist[i] in lista:
if lista[i] == dist[lista.index(dist[i])]: cont = 1; break
if cont == 0: print('NO')
el... | Title: Spit Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know ... | ```python
# -*- coding: utf-8 -*-
lista,dist,cont = [],[],0
n = int(input())
for i in range(n):
x,y = map(int,input().split())
lista.append(x)
dist.append(x+y)
for i in range(n):
if dist[i] in lista:
if lista[i] == dist[lista.index(dist[i])]: cont = 1; break
if cont == 0: print... | 3.933102 |
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,577,463,825 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | t=int(input())
l1=list(map(int,input().split(" ")[1:]))
only_odd = [num for num in l1 if num % 2 == 1]
only_even = [num for num in l1 if num % 2 == 0]
if(len(only_odd)>len(only_even)):
for elem in only_even:
print(elem)
else:
for elem in only_odd:
print(elem) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
t=int(input())
l1=list(map(int,input().split(" ")[1:]))
only_odd = [num for num in l1 if num % 2 == 1]
only_even = [num for num in l1 if num % 2 == 0]
if(len(only_odd)>len(only_even)):
for elem in only_even:
print(elem)
else:
for elem in only_odd:
print(elem)
``` | 0 |
557 | A | Ilya and Diplomas | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"math"
] | null | null | Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly... | The first line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=3·106) — the number of schoolchildren who will participate in the Olympiad.
The next line of the input contains two integers *min*1 and *max*1 (1<=≤<=*min*1<=≤<=*max*1<=≤<=106) — the minimum and maximum limits on the number of diplomas of the fir... | In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas.
The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first... | [
"6\n1 5\n2 6\n3 7\n",
"10\n1 2\n1 3\n1 5\n",
"6\n1 3\n2 2\n2 2\n"
] | [
"1 2 3 \n",
"2 3 5 \n",
"2 2 2 \n"
] | none | 500 | [
{
"input": "6\n1 5\n2 6\n3 7",
"output": "1 2 3 "
},
{
"input": "10\n1 2\n1 3\n1 5",
"output": "2 3 5 "
},
{
"input": "6\n1 3\n2 2\n2 2",
"output": "2 2 2 "
},
{
"input": "55\n1 1000000\n40 50\n10 200",
"output": "5 40 10 "
},
{
"input": "3\n1 1\n1 1\n1 1",
"o... | 1,435,676,980 | 580 | Python 3 | OK | TESTS | 56 | 155 | 6,348,800 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict, deque
# Guide:
# 1. construct complex data types while reading (e.g. graph adj list)
# 2. avoid any non-necessary time/memory usage
#... | Title: Ilya and Diplomas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the re... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict, deque
# Guide:
# 1. construct complex data types while reading (e.g. graph adj list)
# 2. avoid any non-necessary time/memo... | 3 | |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,696,858,089 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 92 | 0 | divisors = [4,7,44,47,74,77,444,447,474,744,774,777]
n = int(input())
for number in divisors:
if n%number == 0:
print('YES')
exit()
print('NO') | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
divisors = [4,7,44,47,74,77,444,447,474,744,774,777]
n = int(input())
for number in divisors:
if n%number == 0:
print('YES')
exit()
print('NO')
``` | 0 | |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,600,965,284 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 218 | 0 | """
Solution to Codeforces Problem 119A : https://codeforces.com/problemset/problem/119/A
"""
import math
def solve(a, b, n):
while 0 < n:
for ix, value in enumerate([a, b]):
n -= math.gcd(value, n)
if n == 0:
print(ix)
if __name__ == "__main__":
... | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
"""
Solution to Codeforces Problem 119A : https://codeforces.com/problemset/problem/119/A
"""
import math
def solve(a, b, n):
while 0 < n:
for ix, value in enumerate([a, b]):
n -= math.gcd(value, n)
if n == 0:
print(ix)
if __name__ == "__ma... | 3 | |
701 | A | Cards | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards ... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card. | Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print... | [
"6\n1 5 7 4 4 3\n",
"4\n10 10 10 10\n"
] | [
"1 3\n6 2\n4 5\n",
"1 2\n3 4\n"
] | In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable. | 500 | [
{
"input": "6\n1 5 7 4 4 3",
"output": "1 3\n6 2\n4 5"
},
{
"input": "4\n10 10 10 10",
"output": "1 4\n2 3"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,688,707,456 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 |
def cards(n, card_values):
target_sum = sum(card_values) // (n // 2)
player_1 = []
player_2 = []
for i in range(n-1):
for j in range(i+1, n):
card_sum = card_values[i] + card_values[j]
if card_sum == target_sum:
if (i+1 not in player_2) and (j+1 not i... | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one p... | ```python
def cards(n, card_values):
target_sum = sum(card_values) // (n // 2)
player_1 = []
player_2 = []
for i in range(n-1):
for j in range(i+1, n):
card_sum = card_values[i] + card_values[j]
if card_sum == target_sum:
if (i+1 not in player_2) and ... | 0 | |
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th... | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"inp... | 1,687,377,345 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 51 | 108 | 19,046,400 | #author: sushmanth
from sys import stdin
input = stdin.readline
inp = lambda : list(map(int,input().split()))
def answer():
s = 0
for i in range(k):
s += a[i]
ans , index = s , 1
for i in range(k , n):
s -= a[i - k]
s += a[i]
if(ans > s):
... | Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ... | ```python
#author: sushmanth
from sys import stdin
input = stdin.readline
inp = lambda : list(map(int,input().split()))
def answer():
s = 0
for i in range(k):
s += a[i]
ans , index = s , 1
for i in range(k , n):
s -= a[i - k]
s += a[i]
if(ans > s):... | 3 | |
660 | C | Hard Process | PROGRAMMING | 1,600 | [
"binary search",
"dp",
"two pointers"
] | null | null | You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*). | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*. | On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones.
On the second line print *n* integers *a**j* — the elements of the array *a* after the changes.
If there are multiple answers, you can print any one of them. | [
"7 1\n1 0 0 1 1 0 1\n",
"10 2\n1 0 0 1 0 1 0 1 0 1\n"
] | [
"4\n1 0 0 1 1 1 1\n",
"5\n1 0 0 1 1 1 1 1 0 1\n"
] | none | 0 | [
{
"input": "7 1\n1 0 0 1 1 0 1",
"output": "4\n1 0 0 1 1 1 1"
},
{
"input": "10 2\n1 0 0 1 0 1 0 1 0 1",
"output": "5\n1 0 0 1 1 1 1 1 0 1"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "7 0\n0 1 0 0 0 1 0",
"o... | 1,691,773,140 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = int(input())
m = {}
def fun(i, le, d, i1, a):
if (i, le, d, i1) in m:
return m[(i, le, d, i1)]
if i == n:
m[(i, le, d, i1)] = le
return le
if le == 0:
m[(i, le, d, i1)] = max(fun(i + 1, 1, 0, i, a), fun(i + 1, 0, 0, i + 1, a))
return m[(i, le, d, i1)]
... | Title: Hard Process
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can ch... | ```python
n = int(input())
m = {}
def fun(i, le, d, i1, a):
if (i, le, d, i1) in m:
return m[(i, le, d, i1)]
if i == n:
m[(i, le, d, i1)] = le
return le
if le == 0:
m[(i, le, d, i1)] = max(fun(i + 1, 1, 0, i, a), fun(i + 1, 0, 0, i + 1, a))
return m[(i, le,... | -1 | |
474 | B | Worms | PROGRAMMING | 1,200 | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (... | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the f... | 1,000 | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,689,325,429 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,867,200 | import numpy as np
n = int(input())
nlist = list(map(int,input().split()[:n]))
n_array = np.array(nlist)
# nlist = [[32,4,3],[32,43,4],[4,78,9],[4,3,4]]
m = int(input())
mlist = list(map(int,input().split()[:m]))
m_array = np.array(mlist)
for i in range(m):
sum = 0
tar = m_array[i]
for j in ran... | Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers:... | ```python
import numpy as np
n = int(input())
nlist = list(map(int,input().split()[:n]))
n_array = np.array(nlist)
# nlist = [[32,4,3],[32,43,4],[4,78,9],[4,3,4]]
m = int(input())
mlist = list(map(int,input().split()[:m]))
m_array = np.array(mlist)
for i in range(m):
sum = 0
tar = m_array[i]
fo... | -1 | |
777 | B | Game of Credit Cards | PROGRAMMING | 1,300 | [
"data structures",
"dp",
"greedy",
"sortings"
] | null | null | After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on the... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits in the cards Sherlock and Moriarty are going to use.
The second line contains *n* digits — Sherlock's credit card number.
The third line contains *n* digits — Moriarty's credit card number. | First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty. | [
"3\n123\n321\n",
"2\n88\n00\n"
] | [
"0\n2\n",
"2\n0\n"
] | First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks. | 1,000 | [
{
"input": "3\n123\n321",
"output": "0\n2"
},
{
"input": "2\n88\n00",
"output": "2\n0"
},
{
"input": "1\n4\n5",
"output": "0\n1"
},
{
"input": "1\n8\n7",
"output": "1\n0"
},
{
"input": "2\n55\n55",
"output": "0\n0"
},
{
"input": "3\n534\n432",
"out... | 1,589,601,472 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 529 | 6,963,200 | n=int(input())
s=input()
m=input()
mt=[]
st=[]
for i in range(0,n):
countm=0
for j in range(0,n):
if(s[i]>m[j]):
countm+=1
mt.append(countm)
for i in range(0,n):
counts=0
for j in range(0,n):
if(m[i]>s[j]):
counts+=1
st.append(counts)
prin... | Title: Game of Credit Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simpl... | ```python
n=int(input())
s=input()
m=input()
mt=[]
st=[]
for i in range(0,n):
countm=0
for j in range(0,n):
if(s[i]>m[j]):
countm+=1
mt.append(countm)
for i in range(0,n):
counts=0
for j in range(0,n):
if(m[i]>s[j]):
counts+=1
st.append(cou... | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,666,654,234 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | m, n = map(int, input().split())
a = max(m, n)
b = min(m, n)
ans = 0
while a > 0 and b > 0:
num = a // 2
ans += num * 2
a -= 2 * num
b -= num
m = a
n = b
a = max(m, n)
b = min(m, n)
# print(f"ans={ans}, a={a}, b={b} ")
print(ans) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m, n = map(int, input().split())
a = max(m, n)
b = min(m, n)
ans = 0
while a > 0 and b > 0:
num = a // 2
ans += num * 2
a -= 2 * num
b -= num
m = a
n = b
a = max(m, n)
b = min(m, n)
# print(f"ans={ans}, a={a}, b={b} ")
print(ans)
``` | 0 |
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894"... | 1,632,933,109 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 108 | 20,172,800 | n,k=map(int,input().split())
print(((n+1)//k+((n+1)%k>0))*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
n,k=map(int,input().split())
print(((n+1)//k+((n+1)%k>0))*k)
``` | 3 | |
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats num... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on,... | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The ligh... | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 ... | 1,589,809,169 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 6,656,000 | houselevers, houses = map(int, input().split())
counter = 0
list1 = []
for i in range(houselevers):
list1.extend([int(h) for h in input().split()])
for b in range(0, houses*2, 2):
if list1[b] + list1[b+1] > 0:
counter += 1
print(counter)
| Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vital... | ```python
houselevers, houses = map(int, input().split())
counter = 0
list1 = []
for i in range(houselevers):
list1.extend([int(h) for h in input().split()])
for b in range(0, houses*2, 2):
if list1[b] + list1[b+1] > 0:
counter += 1
print(counter)
``` | 0 | |
293 | A | Weird Game | PROGRAMMING | 1,500 | [
"games",
"greedy"
] | null | null | Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game.
Roman leaves a word for each of them. Each word consists of 2·*n* binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves f... | The first line contains integer *n* (1<=≤<=*n*<=≤<=106). The second line contains string *s* — Yaroslav's word. The third line contains string *t* — Andrey's word.
It is guaranteed that both words consist of 2·*n* characters "0" and "1". | Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes. | [
"2\n0111\n0001\n",
"3\n110110\n001001\n",
"3\n111000\n000111\n",
"4\n01010110\n00101101\n",
"4\n01100000\n10010011\n"
] | [
"First\n",
"First\n",
"Draw\n",
"First\n",
"Second\n"
] | none | 500 | [
{
"input": "2\n0111\n0001",
"output": "First"
},
{
"input": "3\n110110\n001001",
"output": "First"
},
{
"input": "3\n111000\n000111",
"output": "Draw"
},
{
"input": "4\n01010110\n00101101",
"output": "First"
},
{
"input": "4\n01100000\n10010011",
"output": "Se... | 1,603,271,980 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 5,427,200 | n = int(input())
s=input()
t=input()
s_1 = 0
t_1 = 0
for i in range(2*n):
if s[i]=='1':
s_1+=1
if t[i]=='1':
t_1+=1
first = 0
second = 0
r = 0
for i in range(2*n):
if s[i]=='1' and t[i]=='0':
first+=1
elif s[i]=='0' and t[i]=='1':
second+=1
elif s[i]=='1' and t[i]==... | Title: Weird Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game.
Roman leaves a word for each of them. Each word consists of 2·... | ```python
n = int(input())
s=input()
t=input()
s_1 = 0
t_1 = 0
for i in range(2*n):
if s[i]=='1':
s_1+=1
if t[i]=='1':
t_1+=1
first = 0
second = 0
r = 0
for i in range(2*n):
if s[i]=='1' and t[i]=='0':
first+=1
elif s[i]=='0' and t[i]=='1':
second+=1
elif s[i]=='1' ... | 0 | |
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with t... | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — ... | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10... | 1,679,820,327 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 67 | 108 | 3,993,600 | from sys import stdin,stdout
input,print = stdin.readline,stdout.write
n=int(input())
back=-10**9
prev=-1
count=0
for i in range(n):
pos,curr=map(int,input().split())
#print(str(back),str(prev),str(pos),str(curr),str(count))
dist=pos-back
if prev==-1:
if curr<dist:
coun... | Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described b... | ```python
from sys import stdin,stdout
input,print = stdin.readline,stdout.write
n=int(input())
back=-10**9
prev=-1
count=0
for i in range(n):
pos,curr=map(int,input().split())
#print(str(back),str(prev),str(pos),str(curr),str(count))
dist=pos-back
if prev==-1:
if curr<dist:
... | 3 | |
371 | A | K-Periodic Array | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"math"
] | null | null | This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.
Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represented by array *b* written exactly times consecutively. In other words, array *a* is *k*-periodic, if it... | The first line of the input contains a pair of integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100), where *n* is the length of the array and the value *n* is divisible by *k*. The second line contains the sequence of elements of the given array *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), *a**i* is the *i*-th element of ... | Print the minimum number of array elements we need to change to make the array *k*-periodic. If the array already is *k*-periodic, then print 0. | [
"6 2\n2 1 2 2 2 1\n",
"8 4\n1 1 2 1 1 1 2 1\n",
"9 3\n2 1 1 1 2 1 1 1 2\n"
] | [
"1\n",
"0\n",
"3\n"
] | In the first sample it is enough to change the fourth element from 2 to 1, then the array changes to [2, 1, 2, 1, 2, 1].
In the second sample, the given array already is 4-periodic.
In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as [1, 1, 1, 1... | 500 | [
{
"input": "6 2\n2 1 2 2 2 1",
"output": "1"
},
{
"input": "8 4\n1 1 2 1 1 1 2 1",
"output": "0"
},
{
"input": "9 3\n2 1 1 1 2 1 1 1 2",
"output": "3"
},
{
"input": "1 1\n2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 2\n2 2... | 1,661,538,055 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 46 | 0 | def contarMudancas(n, k):
vetor = list(map(int, input().split(' ')))
cont1 = []
cont2 = []
for i in range(k):
cont1.append(0)
cont2.append(0)
for i in range(n):
if vetor[i] == 1:
cont1[i % k] += 1
else:
cont2[i % k] += 1
minMudancas = 0
... | Title: K-Periodic Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.
Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represent... | ```python
def contarMudancas(n, k):
vetor = list(map(int, input().split(' ')))
cont1 = []
cont2 = []
for i in range(k):
cont1.append(0)
cont2.append(0)
for i in range(n):
if vetor[i] == 1:
cont1[i % k] += 1
else:
cont2[i % k] += 1
minMudanc... | 3 | |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,696,489,048 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | def check3(i) :
if(n[i] not in ch): return 0
if(n[i] != '1'): return 0
if((i+1)<ln) :
if(n[i+1] not in ch): return 0
if(n[i+1] != '4') :
return 1
else :
if((i+2)<ln) :
if(n[i+2] not in ch): return 0
if(n[i+2] != '4'): return 2
else: return 3
return 1
n = input()
ln = len(n)
ch = '14';
i = 0... | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
def check3(i) :
if(n[i] not in ch): return 0
if(n[i] != '1'): return 0
if((i+1)<ln) :
if(n[i+1] not in ch): return 0
if(n[i+1] != '4') :
return 1
else :
if((i+2)<ln) :
if(n[i+2] not in ch): return 0
if(n[i+2] != '4'): return 2
else: return 3
return 1
n = input()
ln = len(n)
ch = '... | 0 | |
765 | E | Tree Folding | PROGRAMMING | 2,200 | [
"dfs and similar",
"dp",
"greedy",
"implementation",
"trees"
] | null | null | Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex *v*, and two disjoint (except for *v*) paths of equal length *a*0<==<=*v*, *a*1, ..., *a**k*, and *b*0<==<=*v*, *b*1, ..., *b**k*. Additionally, vertices *a*1, ..., *a**k*, *b*1, ..., *b**k* must not have any neighbou... | The first line of input contains the number of vertices *n* (2<=≤<=*n*<=≤<=2·105).
Next *n*<=-<=1 lines describe edges of the tree. Each of these lines contains two space-separated integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — indices of endpoints of the corresponding edge. It is guaranteed that the gi... | If it is impossible to obtain a path, print -1. Otherwise, print the minimum number of edges in a possible path. | [
"6\n1 2\n2 3\n2 4\n4 5\n1 6\n",
"7\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n"
] | [
"3\n",
"-1\n"
] | In the first sample case, a path of three edges is obtained after merging paths 2 - 1 - 6 and 2 - 4 - 5.
It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths 1 - 3 - 4 and 1 - 5 - 6, since vertex 6 additionally has a neighbour 7 that is not present in the co... | 2,500 | [
{
"input": "6\n1 2\n2 3\n2 4\n4 5\n1 6",
"output": "3"
},
{
"input": "7\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "3\n3 1\n1 2",
"output": "1"
},
{
"input": "10\n5 10\n7 8\n8 3\n2 6\n3 2\n9 7\n4 5\n10 1\n6 4... | 1,681,926,453 | 5,553 | PyPy 3 | OK | TESTS | 54 | 904 | 82,534,400 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
G = [set() for _ in range(n + 1)]
for _ in range(n - 1):
u, v = map(int, input().split())
G[u].add(v)
G[v].add(u)
q = []
x = [set() for _ in range(n + 1)]
cnt = [len(g) for g in G]
for i in range(1,... | Title: Tree Folding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex *v*, and two disjoint (except for *v*) paths of equal length *a*0<==<=*v*, *a*1, ..., *a**k*, and *b*0<==<=*v*, *b*1, .... | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
G = [set() for _ in range(n + 1)]
for _ in range(n - 1):
u, v = map(int, input().split())
G[u].add(v)
G[v].add(u)
q = []
x = [set() for _ in range(n + 1)]
cnt = [len(g) for g in G]
for i i... | 3 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,662,631,552 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | m,n=sorted(map(int,input().split()));print(m,(n-m)//2) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
m,n=sorted(map(int,input().split()));print(m,(n-m)//2)
``` | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,687,011,853 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | m = int(input("m= "))
n = int(input("n= "))
a = int(input("a= "))
if n%a == 0:
k = n/a
else:
k = (n//a)+1
if m%a == 0:
p = m/a
else:
p = (m//a)+1
print(k*p) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
m = int(input("m= "))
n = int(input("n= "))
a = int(input("a= "))
if n%a == 0:
k = n/a
else:
k = (n//a)+1
if m%a == 0:
p = m/a
else:
p = (m//a)+1
print(k*p)
``` | -1 |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,693,068,402 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 0 | def word_change(word):
if word.isupper() or word[0].islower() and word[1:].isupper():
return word.swapcase()
else:
return word
word = input()
res = word_change(word)
print(res) | Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
def word_change(word):
if word.isupper() or word[0].islower() and word[1:].isupper():
return word.swapcase()
else:
return word
word = input()
res = word_change(word)
print(res)
``` | 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,621,718,969 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | a,b,c,d = map(int, input().split())
g = a*b
others = b*c - a*c + a*d
print(g/others) | 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())
g = a*b
others = b*c - a*c + a*d
print(g/others)
``` | 0 | |
16 | B | Burglar and Matches | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | B. Burglar and Matches | 0 | 64 | A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactl... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. | Output the only number — answer to the problem. | [
"7 3\n5 10\n2 5\n3 6\n",
"3 3\n1 3\n2 2\n3 1\n"
] | [
"62\n",
"7\n"
] | none | 0 | [
{
"input": "7 3\n5 10\n2 5\n3 6",
"output": "62"
},
{
"input": "3 3\n1 3\n2 2\n3 1",
"output": "7"
},
{
"input": "1 1\n1 2",
"output": "2"
},
{
"input": "1 2\n1 9\n1 6",
"output": "9"
},
{
"input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1",
"ou... | 1,584,631,281 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 218 | 307,200 |
n,m=map(int,input().split())
l=[]
for i in range(m):
x,y=map(int,input().split())
l.append((x,y))
l.sort(key=lambda x:x[1],reverse=True)
ans=0
for i in range(m):
if l[i][0]>=n:
x=n
else:
x=l[i][0]
n-=x
ans+=x*l[i][1]
print(ans) | Title: Burglar and Matches
Time Limit: 0 seconds
Memory Limit: 64 megabytes
Problem Description:
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* mat... | ```python
n,m=map(int,input().split())
l=[]
for i in range(m):
x,y=map(int,input().split())
l.append((x,y))
l.sort(key=lambda x:x[1],reverse=True)
ans=0
for i in range(m):
if l[i][0]>=n:
x=n
else:
x=l[i][0]
n-=x
ans+=x*l[i][1]
print(ans)
``` | 3 |
63 | A | Sinking Ship | PROGRAMMING | 900 | [
"implementation",
"sortings",
"strings"
] | A. Sinking Ship | 2 | 256 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a stri... | The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spa... | Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. | [
"6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n"
] | [
"Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n"
] | none | 500 | [
{
"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"
},
{
"input": "1\nA captain",
"output": "A"
},
{
"input": "1\nAbcdefjhij captain",
"output": "Abcdefjhij"
},
{
"input": "5\nA captain... | 1,579,368,616 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 216 | 307,200 | n=int(input())
r=[]
w=[]
m=[]
c=[]
for p in range(n):
a,b=[i for i in input().split()]
if b=="rat":
r.insert(0,a)
elif b=="woman" or b=="child":
w.insert(0,a)
elif b=="man":
m.insert(0,a)
elif b=="captain":
c.insert(0,a)
r.sort()
w.sort()
m.sort()
fo... | Title: Sinking Ship
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to ... | ```python
n=int(input())
r=[]
w=[]
m=[]
c=[]
for p in range(n):
a,b=[i for i in input().split()]
if b=="rat":
r.insert(0,a)
elif b=="woman" or b=="child":
w.insert(0,a)
elif b=="man":
m.insert(0,a)
elif b=="captain":
c.insert(0,a)
r.sort()
w.sort()
m.... | 0 |
849 | A | Odds and Ends | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numb... | The first line of input contains a non-negative integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence.
The second line contains *n* space-separated non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — the elements of the sequence. | Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower). | [
"3\n1 3 5\n",
"5\n1 0 1 5 1\n",
"3\n4 3 1\n",
"4\n3 9 9 3\n"
] | [
"Yes\n",
"Yes\n",
"No\n",
"No\n"
] | In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.
In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.
In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.
In ... | 500 | [
{
"input": "3\n1 3 5",
"output": "Yes"
},
{
"input": "5\n1 0 1 5 1",
"output": "Yes"
},
{
"input": "3\n4 3 1",
"output": "No"
},
{
"input": "4\n3 9 9 3",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "5\n100 99 100 99 99",
"out... | 1,623,912,710 | 2,147,483,647 | PyPy 3 | OK | TESTS | 74 | 93 | 0 | n = int(input())
daf = list(map(int, input().split()))
if n%2 == 0 or daf[0]%2 == 0 or daf[-1]%2 == 0:
print("NO")
else:
print("YES")
| Title: Odds and Ends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd num... | ```python
n = int(input())
daf = list(map(int, input().split()))
if n%2 == 0 or daf[0]%2 == 0 or daf[-1]%2 == 0:
print("NO")
else:
print("YES")
``` | 3 | |
808 | D | Array Division | PROGRAMMING | 1,900 | [
"binary search",
"data structures",
"implementation"
] | null | null | Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element ... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the size of the array.
The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. | Print YES if Vasya can divide the array after moving one element. Otherwise print NO. | [
"3\n1 3 2\n",
"5\n1 2 3 4 5\n",
"5\n2 2 3 4 5\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | 0 | [
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "5\n2 2 3 4 5",
"output": "YES"
},
{
"input": "5\n72 32 17 46 82",
"output": "NO"
},
{
"input": "6\n26 10 70 11 69 57",
"output": "NO"
},
{
"input": "7\n4... | 1,694,010,253 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 32 | 171 | 18,124,800 | n = int(input())
arr = list(map(int, input().split(' ')))
pref_sum = [0] * (n + 1)
for ind in range(1, n + 1):
pref_sum[ind] = pref_sum[ind - 1] + arr[ind - 1]
prev_els = set()
prev_els.add(arr[0])
ind = 1
half_sum = sum(arr) / 2
while ind < n:
prev_els.add(arr[ind])
if abs(half_sum - pref_sum[ind]) in p... | Title: Array Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to... | ```python
n = int(input())
arr = list(map(int, input().split(' ')))
pref_sum = [0] * (n + 1)
for ind in range(1, n + 1):
pref_sum[ind] = pref_sum[ind - 1] + arr[ind - 1]
prev_els = set()
prev_els.add(arr[0])
ind = 1
half_sum = sum(arr) / 2
while ind < n:
prev_els.add(arr[ind])
if abs(half_sum - pref_sum[... | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,681,145,342 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | a, b = map(int, input().split())
if a % 2 == 0 and b % 2 == 0:
print(a*b//2)
else:
if a % 2 == 1 and b % 2 == 0:
print((a-1)*b//2 + (a-1)//2)
else:
print((b-1)*a//2 + (b-1)//2)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
a, b = map(int, input().split())
if a % 2 == 0 and b % 2 == 0:
print(a*b//2)
else:
if a % 2 == 1 and b % 2 == 0:
print((a-1)*b//2 + (a-1)//2)
else:
print((b-1)*a//2 + (b-1)//2)
``` | 0 |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,616,539,848 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 31 | 124 | 0 | M,N=map(int,input().split())
if M==1 and N==1:
print("No es posible")
else:
print(int(M*N) // 2) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
M,N=map(int,input().split())
if M==1 and N==1:
print("No es posible")
else:
print(int(M*N) // 2)
``` | 0 |
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,516,373,136 | 636 | PyPy 3 | OK | TESTS | 254 | 109 | 19,968,000 | n = int(input())
h, m = [int(z) for z in input().split()]
if "7" in str(h) or "7" in str(m):
print(0)
exit(0)
def time(x):
t = x // 60
m = x % 60
return t, m
cur = h * 60 + m
cnt = 0
while True:
cur -= n
cnt += 1
if cur < 0:
cur += 24 * 60
a, b = time(cur)
... | 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
n = int(input())
h, m = [int(z) for z in input().split()]
if "7" in str(h) or "7" in str(m):
print(0)
exit(0)
def time(x):
t = x // 60
m = x % 60
return t, m
cur = h * 60 + m
cnt = 0
while True:
cur -= n
cnt += 1
if cur < 0:
cur += 24 * 60
a, b = tim... | 3 | |
507 | C | Guess Your Way Out! | PROGRAMMING | 1,700 | [
"implementation",
"math",
"trees"
] | null | null | Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height *h*. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node.
Let's index all the leaf nodes from the left t... | Input consists of two integers *h*,<=*n* (1<=≤<=*h*<=≤<=50, 1<=≤<=*n*<=≤<=2*h*). | Output a single integer representing the number of nodes (excluding the exit node) Amr is going to visit before reaching the exit by following this algorithm. | [
"1 2\n",
"2 3\n",
"3 6\n",
"10 1024\n"
] | [
"2",
"5",
"10",
"2046"
] | A perfect binary tree of height *h* is a binary tree consisting of *h* + 1 levels. Level 0 consists of a single node called root, level *h* consists of 2<sup class="upper-index">*h*</sup> nodes called leaves. Each node that is not a leaf has exactly two children, left and right one.
Following picture illustrates the ... | 1,500 | [
{
"input": "1 2",
"output": "2"
},
{
"input": "2 3",
"output": "5"
},
{
"input": "3 6",
"output": "10"
},
{
"input": "10 1024",
"output": "2046"
},
{
"input": "10 577",
"output": "1345"
},
{
"input": "11 550",
"output": "408"
},
{
"input": ... | 1,614,601,977 | 2,147,483,647 | PyPy 3 | OK | TESTS | 62 | 93 | 0 | from sys import stdin,stdout
nmbr = lambda: int(input())
lst = lambda: list(map(int, input().split()))
def fn(s,e,left,dpth):
global ans
if s==e:return
mid=(s+e)>>1
left^=1
nodes=(1<<(h-dpth+1))-1
if s<=n<=mid:
if left==0:
ans+=nodes//2
fn(s,mid,1,dpth+1)
... | Title: Guess Your Way Out!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height *h*. The player is initially standing at the root of the tree ... | ```python
from sys import stdin,stdout
nmbr = lambda: int(input())
lst = lambda: list(map(int, input().split()))
def fn(s,e,left,dpth):
global ans
if s==e:return
mid=(s+e)>>1
left^=1
nodes=(1<<(h-dpth+1))-1
if s<=n<=mid:
if left==0:
ans+=nodes//2
fn(s,mid,... | 3 | |
177 | G1 | Fibonacci Strings | PROGRAMMING | 2,400 | [
"strings"
] | null | null | Fibonacci strings are defined as follows:
- *f*1 = «a» - *f*2 = «b» - *f**n* = *f**n*<=-<=1 *f**n*<=-<=2, *n*<=><=2
Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba".
You are given a Fibonacci string and *m* strings *s**i*. For each string *s**i*, find the number of times it occurs in... | The first line contains two space-separated integers *k* and *m* — the number of a Fibonacci string and the number of queries, correspondingly.
Next *m* lines contain strings *s**i* that correspond to the queries. It is guaranteed that strings *s**i* aren't empty and consist only of characters "a" and "b".
The input ... | For each string *s**i* print the number of times it occurs in the given Fibonacci string as a substring. Since the numbers can be large enough, print them modulo 1000000007 (109<=+<=7). Print the answers for the strings in the order in which they are given in the input. | [
"6 5\na\nb\nab\nba\naba\n"
] | [
"3\n5\n3\n3\n1\n"
] | none | 30 | [
{
"input": "6 5\na\nb\nab\nba\naba",
"output": "3\n5\n3\n3\n1"
},
{
"input": "10 10\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab",
"output": "12\n21\n21\n0\n12\n21\n21\n0\n12\n21"
},
{
"input": "10 10\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb",
"output": "0\n12\n21\n0\n12\n8\n0\n0... | 1,685,408,480 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS1 | 2 | 92 | 0 | MOD = 10**9 + 7
def count_queries(k, queries):
fib1 = "a"
fib2 = "b"
for _ in range(2, k):
fib1, fib2 = fib2, fib2 + fib1
fib_k = fib2 if k > 1 else fib1
counts = []
for query in queries:
count = fib_k.count(query)
counts.append(count % MOD)
ret... | Title: Fibonacci Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fibonacci strings are defined as follows:
- *f*1 = «a» - *f*2 = «b» - *f**n* = *f**n*<=-<=1 *f**n*<=-<=2, *n*<=><=2
Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba".
You are given a... | ```python
MOD = 10**9 + 7
def count_queries(k, queries):
fib1 = "a"
fib2 = "b"
for _ in range(2, k):
fib1, fib2 = fib2, fib2 + fib1
fib_k = fib2 if k > 1 else fib1
counts = []
for query in queries:
count = fib_k.count(query)
counts.append(count % MOD)
... | 0 | |
845 | A | Chess Tourney | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizer... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100).
The second line contains 2·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≤<=*a**i*<=≤<=1000). | If it's possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | [
"2\n1 3 2 4\n",
"1\n3 3\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2\n1 3 2 4",
"output": "YES"
},
{
"input": "1\n3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 2 2 3 3 3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1 2 2 2 2 2",
"output": "YES"
},
{
"input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000... | 1,503,331,932 | 4,032 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n=int(input())
x=input().split()
i=0
q=0
while(i<2*n):
if(x[i]>=x[i+1]):
q=1
print("NO")
break
i=i+2
if(q==0):
print("YES") | Title: Chess Tourney
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by... | ```python
n=int(input())
x=input().split()
i=0
q=0
while(i<2*n):
if(x[i]>=x[i+1]):
q=1
print("NO")
break
i=i+2
if(q==0):
print("YES")
``` | 0 | |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of int... | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10"... | 1,696,081,131 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 42 | 122 | 0 | n, m = map(int, input().split())
c = 0
for b in range(100):
a = m - b ** 2
if a ** 2 + b == n:
c += 1
print(c) | Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi... | ```python
n, m = map(int, input().split())
c = 0
for b in range(100):
a = m - b ** 2
if a ** 2 + b == n:
c += 1
print(c)
``` | 0 | |
776 | A | A Serial Killer | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and t... | Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. | [
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"icm codeforces\n1\ncodeforces technex\n"
] | [
"ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n",
"icm codeforces\nicm technex\n"
] | In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears. | 500 | [
{
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"
},
{
"input": "icm codeforces\n1\ncodeforces technex",
"output": "icm codeforces\nicm technex"
},
{
"input": "a b\n3\na c\n... | 1,640,866,945 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 108 | 0 | a, b = map(str, input().split())
n = int(input())
lst = [a, b]
lst_output = [a, b]
for i in range(n):
c, d = map(str, input().split())
lst.append(c)
lst.append(d)
def all_index(lst1, word):
all_index1 = []
for k in range(len(lst1)):
if lst1[k] == word:
all_index1.... | Title: A Serial Killer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The... | ```python
a, b = map(str, input().split())
n = int(input())
lst = [a, b]
lst_output = [a, b]
for i in range(n):
c, d = map(str, input().split())
lst.append(c)
lst.append(d)
def all_index(lst1, word):
all_index1 = []
for k in range(len(lst1)):
if lst1[k] == word:
a... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
W... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). | Print the *k*-rounding of *n*. | [
"375 4\n",
"10000 1\n",
"38101 0\n",
"123456789 8\n"
] | [
"30000\n",
"10000\n",
"38101\n",
"12345678900000000\n"
] | none | 0 | [
{
"input": "375 4",
"output": "30000"
},
{
"input": "10000 1",
"output": "10000"
},
{
"input": "38101 0",
"output": "38101"
},
{
"input": "123456789 8",
"output": "12345678900000000"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output":... | 1,554,167,201 | 2,147,483,647 | Python 3 | OK | TESTS | 96 | 109 | 0 | entrada = input()
a = int(entrada.split()[0])
k = int(entrada.split()[1])
"""
if(a%s == 0):
print(a)
else:
i = 2
mmc = a*s
p = sqrt(a)
while i <= p:
if s%i == 0 and a%i == 0:
mmc = int(mmc/i)
a = int(a/i)
s = int(s/i)
else:
i+=1
print(mmc)
"""
ult = int(a%10)
a2 = a
while(... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000... | ```python
entrada = input()
a = int(entrada.split()[0])
k = int(entrada.split()[1])
"""
if(a%s == 0):
print(a)
else:
i = 2
mmc = a*s
p = sqrt(a)
while i <= p:
if s%i == 0 and a%i == 0:
mmc = int(mmc/i)
a = int(a/i)
s = int(s/i)
else:
i+=1
print(mmc)
"""
ult = int(a%10)
a2 ... | 3 | |
997 | A | Convert to Ones | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$.
You can apply the following operations any number of times:
- Choose some substring of string $a$ (for examp... | The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $a$ of length $n$, consist... | Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations. | [
"5 1 10\n01000\n",
"5 10 1\n01000\n",
"7 2 3\n1111111\n"
] | [
"11\n",
"2\n",
"0\n"
] | In the first sample, at first you need to reverse substring $[1 \dots 2]$, and then you need to invert substring $[2 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «10000» $\to$ «11111».
The total cost of operations is $1 + 10 = 11$.
In the second sample, at first you need to invert substring $[1... | 500 | [
{
"input": "5 1 10\n01000",
"output": "11"
},
{
"input": "5 10 1\n01000",
"output": "2"
},
{
"input": "7 2 3\n1111111",
"output": "0"
},
{
"input": "1 60754033 959739508\n0",
"output": "959739508"
},
{
"input": "1 431963980 493041212\n1",
"output": "0"
},
... | 1,585,382,284 | 2,147,483,647 | PyPy 3 | OK | TESTS | 115 | 171 | 3,072,000 | import sys
n,x,y=map(int,sys.stdin.readline().split())
s=input()
a=0
for i in range(n-1):
if s[i]=='0':
if s[i]!=s[i+1]:
a+=1
if s[n-1]=='0':
a+=1
if a==0:
print(0)
else:
print((a-1)*(min(x,y))+y) | Title: Convert to Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$.
You can a... | ```python
import sys
n,x,y=map(int,sys.stdin.readline().split())
s=input()
a=0
for i in range(n-1):
if s[i]=='0':
if s[i]!=s[i+1]:
a+=1
if s[n-1]=='0':
a+=1
if a==0:
print(0)
else:
print((a-1)*(min(x,y))+y)
``` | 3 | |
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat... | The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one ... | Print one integer number — the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5... | 1,530,324,971 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 124 | 0 | [_,k]=list(map(int,input().split(' ')))
a=list(map(int,input().split(' ')))
for i in sorted(a,reverse=True):
if k%i==0:
break
print(k//i)
| Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each ... | ```python
[_,k]=list(map(int,input().split(' ')))
a=list(map(int,input().split(' ')))
for i in sorted(a,reverse=True):
if k%i==0:
break
print(k//i)
``` | 3 | |
1,009 | A | Game Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$.
Games in the shop are ordered from left to right, Maxim tries to buy ... | The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet.
The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game.
The third line of the inp... | Print a single integer — the number of games Maxim will buy. | [
"5 4\n2 4 5 2 4\n5 3 4 6\n",
"5 2\n20 40 50 20 40\n19 20\n",
"6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n"
] | [
"3\n",
"0\n",
"4\n"
] | The first example is described in the problem statement.
In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.
In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti... | 0 | [
{
"input": "5 4\n2 4 5 2 4\n5 3 4 6",
"output": "3"
},
{
"input": "5 2\n20 40 50 20 40\n19 20",
"output": "0"
},
{
"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000",
"output": "4"
},
{
"input": "5 1\n1 1 1 1 1\n5",
"output": "1"
},
{
"input": "5 1\n10 1 1 1 1\n... | 1,694,205,275 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 46 | 0 | n,m=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
i1,i2=0,0
while(i1!=n and i2!=m):
if l1[i1]<=l2[i2]:
i2+=1
i1+=1
print(i2) | Title: Game Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the ... | ```python
n,m=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
i1,i2=0,0
while(i1!=n and i2!=m):
if l1[i1]<=l2[i2]:
i2+=1
i1+=1
print(i2)
``` | 3 | |
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,575,567,783 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 17 | 248 | 0 | v=[]
n=[]
s=0
z=int(input())
x=list(map(int,input().split()))
for c in x:
if c not in v:
v.append(c)
if z>1 and len(v)==1:
s=99999
for b in v:
n.append(x.count(b))
#print('n=',n)
m=max(n)
n.remove(m)
#print('nnnnnnn=',n)
for a in n:
s=s+a
#print('s='... | 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
v=[]
n=[]
s=0
z=int(input())
x=list(map(int,input().split()))
for c in x:
if c not in v:
v.append(c)
if z>1 and len(v)==1:
s=99999
for b in v:
n.append(x.count(b))
#print('n=',n)
m=max(n)
n.remove(m)
#print('nnnnnnn=',n)
for a in n:
s=s+a
#... | 0 | |
348 | C | Subset Sums | PROGRAMMING | 2,500 | [
"brute force",
"data structures"
] | null | null | You are given an array *a*1,<=*a*2,<=...,<=*a**n* and *m* sets *S*1,<=*S*2,<=...,<=*S**m* of indices of elements of this array. Let's denote *S**k*<==<={*S**k*,<=*i*} (1<=≤<=*i*<=≤<=|*S**k*|). In other words, *S**k*,<=*i* is some element from set *S**k*.
In this problem you have to answer *q* queries of the two types:... | The first line contains integers *n*,<=*m*,<=*q* (1<=≤<=*n*,<=*m*,<=*q*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=108) — elements of array *a*.
Each of the following *m* lines describes one set of indices. The *k*-th line first contains a positive integer, representing t... | After each first type query print the required sum on a single line.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"5 3 5\n5 -5 5 1 -4\n2 1 2\n4 2 1 4 5\n2 2 5\n? 2\n+ 3 4\n? 1\n+ 2 1\n? 2\n"
] | [
"-3\n4\n9\n"
] | none | 1,500 | [
{
"input": "5 3 5\n5 -5 5 1 -4\n2 1 2\n4 2 1 4 5\n2 2 5\n? 2\n+ 3 4\n? 1\n+ 2 1\n? 2",
"output": "-3\n4\n9"
},
{
"input": "10 10 10\n0 0 0 1 -5 8 7 2 9 -2\n8 1 9 7 8 2 5 10 3\n2 7 10\n8 8 7 1 4 2 5 10 9\n2 7 5\n8 9 3 6 4 8 1 2 10\n2 9 2\n8 4 2 9 1 10 7 5 3\n2 3 6\n8 2 8 5 9 4 1 6 10\n2 5 2\n? 1\n? 3... | 1,646,162,613 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,048,000 | n = int(input())
arr2 = input()
arr2 = arr2.split(' ')
arr = list(map(int,arr2))
fin = []
def sum(arr, n):
total = 1 << n
for i in range(total):
s = 0
for j in range(n):
if ((i & (1 << j)) != 0):
s += arr[j]
fin.append(s)
sum(arr, n);
fin.sor... | Title: Subset Sums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a*1,<=*a*2,<=...,<=*a**n* and *m* sets *S*1,<=*S*2,<=...,<=*S**m* of indices of elements of this array. Let's denote *S**k*<==<={*S**k*,<=*i*} (1<=≤<=*i*<=≤<=|*S**k*|). In other words, *S**k*,<=*i* i... | ```python
n = int(input())
arr2 = input()
arr2 = arr2.split(' ')
arr = list(map(int,arr2))
fin = []
def sum(arr, n):
total = 1 << n
for i in range(total):
s = 0
for j in range(n):
if ((i & (1 << j)) != 0):
s += arr[j]
fin.append(s)
sum(arr, n)... | -1 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,695,113,436 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 31 | 0 | k,n,w = map(int,input().split())
print(max(0,k*w*(w+1)//2-n))
| Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
k,n,w = map(int,input().split())
print(max(0,k*w*(w+1)//2-n))
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the ... | The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in.
It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal. | In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final.
Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1. | [
"4 1 2\n",
"8 2 6\n",
"8 7 5\n"
] | [
"1\n",
"Final!\n",
"2\n"
] | In the first example teams 1 and 2 meet in the first round.
In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.
In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the firs... | 0 | [
{
"input": "4 1 2",
"output": "1"
},
{
"input": "8 2 6",
"output": "Final!"
},
{
"input": "8 7 5",
"output": "2"
},
{
"input": "128 30 98",
"output": "Final!"
},
{
"input": "256 128 256",
"output": "Final!"
},
{
"input": "256 2 127",
"output": "7"
... | 1,520,154,229 | 1,429 | Python 3 | OK | TESTS | 64 | 77 | 5,632,000 | n, a, b = map(int, input().split())
for i in range(8):
a = (a + 1) // 2
b = (b + 1) // 2
if 2 ** (i + 1) == n:
print('Final!')
break
elif a == b:
print(i + 1)
break | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the ord... | ```python
n, a, b = map(int, input().split())
for i in range(8):
a = (a + 1) // 2
b = (b + 1) // 2
if 2 ** (i + 1) == n:
print('Final!')
break
elif a == b:
print(i + 1)
break
``` | 3 | |
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*... | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
}... | 1,595,216,026 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 218 | 20,172,800 | a=input()
b=input()
c=''
for i in list(a):
if i== '0':
pass
else:
c+=i
d=''
for i in list(b):
if i=='0':
pass
else:
d+=i
j=str(int(a)+int(b))
l=''
for i in list(j):
if i=='0' :
pass
else:
l+=i
if ((int(a)+int(b)) ==( int(l) )):
print("YES")
else:
print("NO") | Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu... | ```python
a=input()
b=input()
c=''
for i in list(a):
if i== '0':
pass
else:
c+=i
d=''
for i in list(b):
if i=='0':
pass
else:
d+=i
j=str(int(a)+int(b))
l=''
for i in list(j):
if i=='0' :
pass
else:
l+=i
if ((int(a)+int(b)) ==( int(l) )):
print("YES")
else:
pri... | 0 |
495 | B | Modular Equations | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and... | In the only line of the input two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=109) are given. | If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation . | [
"21 5\n",
"9435152 272\n",
"10 10\n"
] | [
"2\n",
"282\n",
"infinity\n"
] | In the first sample the answers of the Modular Equation are 8 and 16 since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6f5ff39ebd209bf990adaf91f4b82f9687097224.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "21 5",
"output": "2"
},
{
"input": "9435152 272",
"output": "282"
},
{
"input": "10 10",
"output": "infinity"
},
{
"input": "0 1000000000",
"output": "0"
},
{
"input": "11 2",
"output": "2"
},
{
"input": "1 0",
"output": "1"
},
{
... | 1,434,056,313 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 62 | 0 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
#
(a, b) = (int(i) for i in input().split())
start = time.time()
ans = 0
if ( a == b):
ans = "infinity"
elif (a > b):
i = 1
max = (a-b) ** 0.5
while(i <= max ):
if (divmod(a-b, i)[1] == 0):
if i > b:
an... | Title: Modular Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed'... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
#
(a, b) = (int(i) for i in input().split())
start = time.time()
ans = 0
if ( a == b):
ans = "infinity"
elif (a > b):
i = 1
max = (a-b) ** 0.5
while(i <= max ):
if (divmod(a-b, i)[1] == 0):
if i > b:
... | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,671,455,261 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | n,m,a=map(int,input().split())
if n%a==0:
len=int(n/a)
else:
len=int(n/a+1)
if m%a==0:
bre=int(m/a)
else:
bre=int(m/a+1)
print(len+bre) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n,m,a=map(int,input().split())
if n%a==0:
len=int(n/a)
else:
len=int(n/a+1)
if m%a==0:
bre=int(m/a)
else:
bre=int(m/a+1)
print(len+bre)
``` | 0 |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,679,350,591 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 5,939,200 | n, t = map(int, input().split())
a = list(map(int, input().split()))
maxx = 0
for i in range(n):
for j in range(i, n):
sres = a[i:j + 1]
if sum(sres) <= t:
maxx = max(maxx, len(sres))
print(maxx)
| Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
n, t = map(int, input().split())
a = list(map(int, input().split()))
maxx = 0
for i in range(n):
for j in range(i, n):
sres = a[i:j + 1]
if sum(sres) <= t:
maxx = max(maxx, len(sres))
print(maxx)
``` | 0 | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,556,831,130 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 248 | 409,600 | s = str(input())
if "0" not in s:
print(s[0:-1])
exit()
ind = s.index("0")
s = s[0 : ind] + s[1 + ind::]
print(s)
| Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
s = str(input())
if "0" not in s:
print(s[0:-1])
exit()
ind = s.index("0")
s = s[0 : ind] + s[1 + ind::]
print(s)
``` | 3 | |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,693,279,019 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 310 | 7,680,000 | number_of_magnets = int(input())
_list = []
for i in range(number_of_magnets):
x = input()
_list.append(x)
number_of_groups = 1
for i in range(len(_list)):
if i != len(_list) - 1:
if _list[i] != _list[i+1]:
number_of_groups += 1
print(number_of_groups)
| Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
number_of_magnets = int(input())
_list = []
for i in range(number_of_magnets):
x = input()
_list.append(x)
number_of_groups = 1
for i in range(len(_list)):
if i != len(_list) - 1:
if _list[i] != _list[i+1]:
number_of_groups += 1
print(number_of_groups)
``` | 3 | |
424 | B | Megacity | PROGRAMMING | 1,200 | [
"binary search",
"greedy",
"implementation",
"sortings"
] | null | null | The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.
The city of Tomsk can be represented as point on the plane with ... | The first line of the input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=103; 1<=≤<=*s*<=<<=106) — the number of locatons around Tomsk city and the population of the city. Then *n* lines follow. The *i*-th line contains three integers — the *x**i* and *y**i* coordinate values of the *i*-th location and the numbe... | In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity.
The answer is considered correct if the absolute or relative error don'... | [
"4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1\n",
"4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1\n",
"2 1\n1 1 999997\n2 2 1\n"
] | [
"2.8284271\n",
"1.4142136\n",
"-1"
] | none | 1,000 | [
{
"input": "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1",
"output": "2.8284271"
},
{
"input": "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1",
"output": "1.4142136"
},
{
"input": "2 1\n1 1 999997\n2 2 1",
"output": "-1"
},
{
"input": "4 999998\n3 3 10\n-3 3 10\n3 -3 10\n-3 -3 10",
"out... | 1,524,493,480 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 155 | 8,089,600 | import queue
import math
if __name__ == '__main__':
n, s = map(int, input().split())
pq = queue.PriorityQueue()
for i in range(n):
x, y, k = map(int, input().split())
r = math.sqrt(x**2 + y**2)
pq.put((r, k))
r = 0
while pq.empty() == False and s < 1000000:
... | Title: Megacity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding... | ```python
import queue
import math
if __name__ == '__main__':
n, s = map(int, input().split())
pq = queue.PriorityQueue()
for i in range(n):
x, y, k = map(int, input().split())
r = math.sqrt(x**2 + y**2)
pq.put((r, k))
r = 0
while pq.empty() == False and s < 10... | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,652,387,255 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 31 | 0 | import math
arr = input().split()
m = int(arr[0])
n = int(arr[1])
a = int(arr[2])
def theatreSquare(m, n, a):
topSide = math.ceil(n/a)
leftSide = math.ceil(m/a)
return topSide*leftSide
print(theatreSquare(m,n,a)) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
import math
arr = input().split()
m = int(arr[0])
n = int(arr[1])
a = int(arr[2])
def theatreSquare(m, n, a):
topSide = math.ceil(n/a)
leftSide = math.ceil(m/a)
return topSide*leftSide
print(theatreSquare(m,n,a))
``` | 3.9845 |
109 | A | Lucky Sum of Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | A. Lucky Sum of Digits | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. | Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. | [
"11\n",
"10\n"
] | [
"47\n",
"-1\n"
] | none | 500 | [
{
"input": "11",
"output": "47"
},
{
"input": "10",
"output": "-1"
},
{
"input": "64",
"output": "4477777777"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "7"
},
{
"input": "12",
"outpu... | 1,560,627,252 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 2,048,000 | x = int(input())
def som2(y):
sum = 0
while(y != 0):
r = y%10
y = y//10
if((r == 4) or (r == 7)):
sum = sum+r
else:
sum = 0
break
return sum
i = 3
u = 0
while(u == 0):
an = som2(i)
if(an == 0):
i = i+1
else:
... | Title: Lucky Sum of Digits
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
x = int(input())
def som2(y):
sum = 0
while(y != 0):
r = y%10
y = y//10
if((r == 4) or (r == 7)):
sum = sum+r
else:
sum = 0
break
return sum
i = 3
u = 0
while(u == 0):
an = som2(i)
if(an == 0):
i = i+1
e... | 0 |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,643,019,527 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 186 | 0 | a,b = map(int,input().split()) ; c = 7-(max(a,b)) ; d = (str(c)+'/'+str(6))
if d == '3/6': print('1/2')
elif d == '2/6': print('1/3')
elif d == '4/6': print('2/3')
elif d == '5/6': print('5/6')
elif d == '6/6': print('1/1')
elif d == '1/6': print('1/6') | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
a,b = map(int,input().split()) ; c = 7-(max(a,b)) ; d = (str(c)+'/'+str(6))
if d == '3/6': print('1/2')
elif d == '2/6': print('1/3')
elif d == '4/6': print('2/3')
elif d == '5/6': print('5/6')
elif d == '6/6': print('1/1')
elif d == '1/6': print('1/6')
``` | 3.907 |
78 | C | Beaver Game | PROGRAMMING | 2,000 | [
"dp",
"games",
"number theory"
] | C. Beaver Game | 1 | 256 | Two beavers, Timur and Marsel, play the following game.
There are *n* logs, each of exactly *m* meters in length. The beavers move in turns. For each move a beaver chooses a log and gnaws it into some number (more than one) of equal parts, the length of each one is expressed by an integer and is no less than *k* meter... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=109). | Print "Timur", if Timur wins, or "Marsel", if Marsel wins. You should print everything without the quotes. | [
"1 15 4\n",
"4 9 5\n"
] | [
"Timur",
"Marsel"
] | In the first sample the beavers only have one log, of 15 meters in length. Timur moves first. The only move he can do is to split the log into 3 parts each 5 meters in length. Then Marsel moves but he can't split any of the resulting logs, as *k* = 4. Thus, the winner is Timur.
In the second example the beavers have 4... | 1,500 | [
{
"input": "1 15 4",
"output": "Timur"
},
{
"input": "4 9 5",
"output": "Marsel"
},
{
"input": "14 30 9",
"output": "Marsel"
},
{
"input": "81 180 53",
"output": "Timur"
},
{
"input": "225 187 20",
"output": "Marsel"
},
{
"input": "501 840 11",
"ou... | 1,552,977,970 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 124 | 0 | from sys import exit
def IsPrime(n):
d = 2
if n != 1:
while n % d != 0:
d += 1
return d == n
p = False
n, m, k = [int(i) for i in input().split()]
for i in range(m // 2, k - 1, -1):
if m % i == 0:
p = True
if p==False:
print('Marsel')
quit()
if ... | Title: Beaver Game
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Two beavers, Timur and Marsel, play the following game.
There are *n* logs, each of exactly *m* meters in length. The beavers move in turns. For each move a beaver chooses a log and gnaws it into some number (more than one) of... | ```python
from sys import exit
def IsPrime(n):
d = 2
if n != 1:
while n % d != 0:
d += 1
return d == n
p = False
n, m, k = [int(i) for i in input().split()]
for i in range(m // 2, k - 1, -1):
if m % i == 0:
p = True
if p==False:
print('Marsel')
q... | 0 |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,632,352,006 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | list = []
n =int(input())
for i in range(0,n):
o = int(input())
if o != 0 and o not in list:
list.append(o)
print(len(list))
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
list = []
n =int(input())
for i in range(0,n):
o = int(input())
if o != 0 and o not in list:
list.append(o)
print(len(list))
``` | -1 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,667,432,308 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 9 | 92 | 0 | from sys import stdin
input = stdin.readline
from collections import defaultdict
scores_by_name = defaultdict(int)
winner = None
max_score = float('-inf')
for l in range(int(input())):
name, sc = map(str, input().split())
sc = int(sc)
scores_by_name[name] += sc
if len(scores_by_name) == 1:
wi... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
from sys import stdin
input = stdin.readline
from collections import defaultdict
scores_by_name = defaultdict(int)
winner = None
max_score = float('-inf')
for l in range(int(input())):
name, sc = map(str, input().split())
sc = int(sc)
scores_by_name[name] += sc
if len(scores_by_name) == 1:
... | 0 |
366 | B | Dima and To-do List | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in ... | The first line of the input contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103), where *a**i* is the power Inna tells Dima off with if she is present in the room while he is doing the *i*-th task.
It is guaranteed that *n*... | In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do. | [
"6 2\n3 2 1 6 5 4\n",
"10 5\n1 3 5 7 9 9 4 1 8 5\n"
] | [
"1\n",
"3\n"
] | Explanation of the first example.
If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as *k* = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. I... | 1,000 | [
{
"input": "6 2\n3 2 1 6 5 4",
"output": "1"
},
{
"input": "10 5\n1 3 5 7 9 9 4 1 8 5",
"output": "3"
},
{
"input": "20 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "10 10\n8 4 5 7 6 9 2 2 3 5",
"output": "7"
},
{
"input": "50 10\n1 2 3... | 1,642,958,560 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 512,000 | import math
def main_function():
n, k = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
positions = n // k
divided = [0 for i in range(k + 1)]
indexes = [(i + 1) % k for i in range(len(a))]
#print(indexes)
for i in range(len(a)):
j = i +... | Title: Dima and To-do List
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything h... | ```python
import math
def main_function():
n, k = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
positions = n // k
divided = [0 for i in range(k + 1)]
indexes = [(i + 1) % k for i in range(len(a))]
#print(indexes)
for i in range(len(a)):
... | 0 | |
420 | A | Start Up | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out... | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | [
"AHA\n",
"Z\n",
"XO\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "AHA",
"output": "YES"
},
{
"input": "Z",
"output": "NO"
},
{
"input": "XO",
"output": "NO"
},
{
"input": "AAA",
"output": "YES"
},
{
"input": "AHHA",
"output": "YES"
},
{
"input": "BAB",
"output": "NO"
},
{
"input": "OMMMAAMMMO"... | 1,608,014,123 | 2,147,483,647 | PyPy 3 | OK | TESTS | 80 | 140 | 1,843,200 | s = str(input())
output = "YES"
for j in range(len(s)):
if s[j] in ['A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y']:
continue
else:
output = "NO"
break
p1, p2 = 0, len(s) - 1
while p1 < p2:
if s[p1] != s[p2]:
output = "NO"
break
p1 += 1
p2... | Title: Start Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of ... | ```python
s = str(input())
output = "YES"
for j in range(len(s)):
if s[j] in ['A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y']:
continue
else:
output = "NO"
break
p1, p2 = 0, len(s) - 1
while p1 < p2:
if s[p1] != s[p2]:
output = "NO"
break
p1 +=... | 3 | |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,690,352,074 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | a = int(input())
if a % 4 == 0 or a % 7 == 7: print('YES')
else: print('NO') | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
a = int(input())
if a % 4 == 0 or a % 7 == 7: print('YES')
else: print('NO')
``` | 0 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,632,923,028 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 6,758,400 | lp= [360]
for i in range(3,181):
if 180%i==0:
lp.append(i)
n=int(input())
for i in range(n):
d=int(input())
print("YES" if d in lp and d>=60 else "NO")
| Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can... | ```python
lp= [360]
for i in range(3,181):
if 180%i==0:
lp.append(i)
n=int(input())
for i in range(n):
d=int(input())
print("YES" if d in lp and d>=60 else "NO")
``` | 0 |
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.