contestId int64 0 1.01k | index stringclasses 40
values | name stringlengths 2 54 | type stringclasses 2
values | rating int64 0 3.4k | tags listlengths 0 7 | title stringclasses 393
values | time-limit stringclasses 7
values | memory-limit stringclasses 6
values | problem-description stringlengths 0 2.97k | input-specification stringlengths 4 1.87k | output-specification stringlengths 4 1.12k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 3.5k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 1
value | testset stringclasses 9
values | passedTestCount int64 1 402 | timeConsumedMillis int64 15 8.06k | memoryConsumedBytes int64 0 514M | code stringlengths 11 61.4k | prompt stringlengths 297 7.35k | response stringlengths 25 61.4k | score float64 2.82 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,696,402,131 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 46 | 0 | k, n, w = map(int, input().split())
total = (w * (w + 1)) // 2
total *= k
if total - n > 0:
print(total - n)
else:
print(0) | 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())
total = (w * (w + 1)) // 2
total *= k
if total - n > 0:
print(total - n)
else:
print(0)
``` | 3 | |
414 | B | Mashmokh and ACM | PROGRAMMING | 1,400 | [
"combinatorics",
"dp",
"number theory"
] | null | null | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced prog... | The first line of input contains two space-separated integers *n*,<=*k*Β (1<=β€<=*n*,<=*k*<=β€<=2000). | Output a single integer β the number of good sequences of length *k* modulo 1000000007 (109<=+<=7). | [
"3 2\n",
"6 4\n",
"2 1\n"
] | [
"5\n",
"39\n",
"2\n"
] | In the first sample the good sequences are: [1,β1],β[2,β2],β[3,β3],β[1,β2],β[1,β3]. | 1,000 | [
{
"input": "3 2",
"output": "5"
},
{
"input": "6 4",
"output": "39"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "1478 194",
"output": "312087753"
},
{
"input": "1415 562",
"output": "953558593"
},
{
"input": "1266 844",
"output": "735042656"
... | 1,535,295,445 | 2,147,483,647 | Python 3 | OK | TESTS | 65 | 639 | 0 | def C(n,k):
w=1
for i in range(n-k+1,n+1):
w*=i
for i in range (1,k+1):
w//=i
return w
n,k=[int(x) for x in input().split()]
ans=0
for i in range(1,n+1):
pp=1;
i1=i;
for j in range(2,i+1):
sch=0;
while(i1%j==0):
sch+=1
... | Title: Mashmokh and ACM
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join h... | ```python
def C(n,k):
w=1
for i in range(n-k+1,n+1):
w*=i
for i in range (1,k+1):
w//=i
return w
n,k=[int(x) for x in input().split()]
ans=0
for i in range(1,n+1):
pp=1;
i1=i;
for j in range(2,i+1):
sch=0;
while(i1%j==0):
sch+... | 3 | |
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors... | In the first line of input there is one integer $n$ ($0 \le n \le 6$)Β β the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ... | In the first line output one integer $m$ ($0 \le m \le 6$)Β β the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReal... | 1,607,150,355 | 2,147,483,647 | PyPy 3 | OK | TESTS | 64 | 140 | 0 | lst = []
ans = {'purple' : 'Power', 'green' : 'Time', 'blue': 'Space', "orange" : "Soul", "red" : "Reality", "yellow" : "Mind"}
for i in range(int(input())):
lst.append(input())
a = []
for i in ans.keys():
if i not in lst:
a.append(ans[i])
print(len(a))
for i in a:
print(i) | Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So... | ```python
lst = []
ans = {'purple' : 'Power', 'green' : 'Time', 'blue': 'Space', "orange" : "Soul", "red" : "Reality", "yellow" : "Mind"}
for i in range(int(input())):
lst.append(input())
a = []
for i in ans.keys():
if i not in lst:
a.append(ans[i])
print(len(a))
for i in a:
print(i)
``` | 3 | |
618 | A | Slime Combining | PROGRAMMING | 800 | [
"implementation"
] | null | null | Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other *n*<=-<=1 slimes one by one. When you add a slime, you place it at the right of... | The first line of the input will contain a single integer, *n* (1<=β€<=*n*<=β€<=100<=000). | Output a single line with *k* integers, where *k* is the number of slimes in the row after you've finished the procedure described in the problem statement. The *i*-th of these numbers should be the value of the *i*-th slime from the left. | [
"1\n",
"2\n",
"3\n",
"8\n"
] | [
"1\n",
"2\n",
"2 1\n",
"4\n"
] | In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. S... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "2 1"
},
{
"input": "8",
"output": "4"
},
{
"input": "100000",
"output": "17 16 11 10 8 6"
},
{
"input": "12345",
"output": "14 13 6 5 4 1"
},
{
"in... | 1,454,088,757 | 1,357 | Python 3 | OK | TESTS | 27 | 61 | 0 | n = int(input())
import math
s = ''
a = 1
while n > 0 :
a = int(math.log2(n)) + 1
s += str(a) + ' '
n -= 2 ** (a - 1)
print(s)
| Title: Slime Combining
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, y... | ```python
n = int(input())
import math
s = ''
a = 1
while n > 0 :
a = int(math.log2(n)) + 1
s += str(a) + ' '
n -= 2 ** (a - 1)
print(s)
``` | 3 | |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=β€<=*n*<=β€<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit β Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,640,304,801 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 154 | 0 | if __name__ == '__main__':
number = input()
spell_num = 0
while len(number) >= 2:
n = 0
for i in number:
n += int(i)
number = str(n)
spell_num += 1
print(spell_num) | Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
if __name__ == '__main__':
number = input()
spell_num = 0
while len(number) >= 2:
n = 0
for i in number:
n += int(i)
number = str(n)
spell_num += 1
print(spell_num)
``` | 3.9615 |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=β€<=|*s*|<=β€<=50). The second line contains the string *t* (1<=β€<=|*t*|<=β€<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,587,320,078 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 280 | 0 | a=str(input())
b=str(input())
x=int(0)
y=int(0)
while x<len(b):
if b[x]==a[y]:
y=y+1
x=x+1
print(y+1) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
a=str(input())
b=str(input())
x=int(0)
y=int(0)
while x<len(b):
if b[x]==a[y]:
y=y+1
x=x+1
print(y+1)
``` | 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,668,252,812 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 | n=input()
l=[i for i in n]
upper=0
lower=0
for i in l:
if i.isupper():
upper=upper+1
else:
lower=lower+1
if upper>lower:
for i in l:
print(i.upper(),end="")
elif lower>upper:
for i in l:
print(i.lower(),end="")
else:
for i in l:
pr... | 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
n=input()
l=[i for i in n]
upper=0
lower=0
for i in l:
if i.isupper():
upper=upper+1
else:
lower=lower+1
if upper>lower:
for i in l:
print(i.upper(),end="")
elif lower>upper:
for i in l:
print(i.lower(),end="")
else:
for i in l:
... | 3.969 |
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million... | The first input line contains integer number *k*, the second line contains integer number *l* (2<=β€<=*k*,<=*l*<=β€<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number β the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "N... | 1,588,874,869 | 2,147,483,647 | PyPy 3 | OK | TESTS | 64 | 312 | 20,172,800 | n =int(input())
m = int(input())
i=0
val =n
while(val<=m):
if(val==m):
print("YES")
print(i)
exit()
val *=n
i+=1
print("NO")
| Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa... | ```python
n =int(input())
m = int(input())
i=0
val =n
while(val<=m):
if(val==m):
print("YES")
print(i)
exit()
val *=n
i+=1
print("NO")
``` | 3 | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=β€<=*n*<=β€<=105) β the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=*n*) β the elements of array.
The third line contains integer *m* (1<=β€<=*m*<=β€<=105) β the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,688,375,778 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 372 | 24,883,200 | size = int(input())
main = list(map(int, input().split()))
twoDarr = [[0] for _ in range(size+1)]
counter = 1
for x in main:
if twoDarr[x] == [0]:
twoDarr[x][0] = counter
else:
twoDarr[x].append(counter)
counter+=1
qurries = int(input())
list_qur = list(map(int, input().split()))
petya =... | 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
size = int(input())
main = list(map(int, input().split()))
twoDarr = [[0] for _ in range(size+1)]
counter = 1
for x in main:
if twoDarr[x] == [0]:
twoDarr[x][0] = counter
else:
twoDarr[x].append(counter)
counter+=1
qurries = int(input())
list_qur = list(map(int, input().split())... | 3 | |
447 | A | DZY Loves Hash | PROGRAMMING | 800 | [
"implementation"
] | null | null | DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==... | The first line contains two integers, *p* and *n* (2<=β€<=*p*,<=*n*<=β€<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=β€<=*x**i*<=β€<=109). | Output a single integer β the answer to the problem. | [
"10 5\n0\n21\n53\n41\n53\n",
"5 5\n0\n1\n2\n3\n4\n"
] | [
"4\n",
"-1\n"
] | none | 500 | [
{
"input": "10 5\n0\n21\n53\n41\n53",
"output": "4"
},
{
"input": "5 5\n0\n1\n2\n3\n4",
"output": "-1"
},
{
"input": "10 6\n811966798\n734823552\n790326404\n929189974\n414343256\n560346537",
"output": "4"
},
{
"input": "2 2\n788371161\n801743052",
"output": "-1"
},
{
... | 1,405,770,245 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 93 | 0 | p,n = map(int, input().split())
hash_table = []
for i in range(0, n):
x = int(input())
if x % p in hash_table:
print(i + 1)
quit()
else:
hash_table.append(x % p)
print(-1)
| Title: DZY Loves Hash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbere... | ```python
p,n = map(int, input().split())
hash_table = []
for i in range(0, n):
x = int(input())
if x % p in hash_table:
print(i + 1)
quit()
else:
hash_table.append(x % p)
print(-1)
``` | 3 | |
632 | A | Grandma Laura and Apples | PROGRAMMING | 1,200 | [] | null | null | Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers she had *n* buyers and each of them bought exactly half of the apples she had at the moment of the purchase and ... | The first line contains two integers *n* and *p* (1<=β€<=*n*<=β€<=40,<=2<=β€<=*p*<=β€<=1000) β the number of the buyers and the cost of one apple. It is guaranteed that the number *p* is even.
The next *n* lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of th... | Print the only integer *a* β the total money grandma should have at the end of the day.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"2 10\nhalf\nhalfplus\n",
"3 10\nhalfplus\nhalfplus\nhalfplus\n"
] | [
"15\n",
"55\n"
] | In the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer. | 0 | [
{
"input": "2 10\nhalf\nhalfplus",
"output": "15"
},
{
"input": "3 10\nhalfplus\nhalfplus\nhalfplus",
"output": "55"
},
{
"input": "10 328\nhalf\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalf\nhalf\nhalfplus\nhalfplus",
"output": "258300"
},
{
"input": "1 2\nhalfplus",
"... | 1,649,766,476 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 9 | 46 | 0 | n, p = (int(x) for x in input().split())
b = [input() for _ in range(n)]
a = 0
ans = 0
for i in reversed(b):
a *= 2
if i == 'halfplus':
a += 1
ans += p//2
ans += p * (a//2)
print(ans) | Title: Grandma Laura and Apples
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers sh... | ```python
n, p = (int(x) for x in input().split())
b = [input() for _ in range(n)]
a = 0
ans = 0
for i in reversed(b):
a *= 2
if i == 'halfplus':
a += 1
ans += p//2
ans += p * (a//2)
print(ans)
``` | 3 | |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5Β·*i* minutes to solve th... | The only line of the input contains two integers *n* and *k* (1<=β€<=*n*<=β€<=10, 1<=β€<=*k*<=β€<=240)Β β the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5β+β10β=β15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar... | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
... | 1,686,063,242 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 46 | 0 | a = input().split(" ")
n = int(a[0])
time = 240 - int(a[1])
for i in range(1,n+1):
if time >= 5*i:
time -= 5*i
i += 1
elif time < 5*i:
break
print(i-1) | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem... | ```python
a = input().split(" ")
n = int(a[0])
time = 240 - int(a[1])
for i in range(1,n+1):
if time >= 5*i:
time -= 5*i
i += 1
elif time < 5*i:
break
print(i-1)
``` | 3 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,622,039,947 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | print('YES' if ''.join([_ for _ in reversed(input())]) == input() else 'NO') | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
print('YES' if ''.join([_ for _ in reversed(input())]) == input() else 'NO')
``` | 3.969 |
32 | A | Reconnaissance | PROGRAMMING | 800 | [
"brute force"
] | A. Reconnaissance | 2 | 256 | According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Som... | The first line contains two integers *n* and *d* (1<=β€<=*n*<=β€<=1000,<=1<=β€<=*d*<=β€<=109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 1... | Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*. | [
"5 10\n10 20 50 60 65\n",
"5 1\n55 30 29 31 55\n"
] | [
"6\n",
"6\n"
] | none | 500 | [
{
"input": "5 10\n10 20 50 60 65",
"output": "6"
},
{
"input": "5 1\n55 30 29 31 55",
"output": "6"
},
{
"input": "6 10\n4 6 4 1 9 3",
"output": "30"
},
{
"input": "7 100\n19 1694 261 162 1 234 513",
"output": "8"
},
{
"input": "8 42\n37 53 74 187 568 22 5 65",
... | 1,567,926,188 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 528 | 307,200 | n, d = map(int, input().split())
data = sorted(map(int, input().split()))
res = 0
for i in range(n):
for j in range(i + 1, n):
if data[j] - data[i] > d:
break
res += 2
print(res)
| Title: Reconnaissance
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob h... | ```python
n, d = map(int, input().split())
data = sorted(map(int, input().split()))
res = 0
for i in range(n):
for j in range(i + 1, n):
if data[j] - data[i] > d:
break
res += 2
print(res)
``` | 3.867428 |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=β€<=*k*<=β€<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=β€<=|*s*|<=β€<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,686,755,031 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 124 | 0 | k = int(input())
word = [*input()]
flag = 0
letters = list(set(word))
numbers = []
for i in range(len(letters)):
if word.count(letters[i]) % k != 0:
flag = 1
else:
numbers.append(word.count(letters[i]) // k)
if flag == 1:
print(-1)
else:
copy = []
for t in range(len... | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
k = int(input())
word = [*input()]
flag = 0
letters = list(set(word))
numbers = []
for i in range(len(letters)):
if word.count(letters[i]) % k != 0:
flag = 1
else:
numbers.append(word.count(letters[i]) // k)
if flag == 1:
print(-1)
else:
copy = []
for t in... | 3 | |
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,550,000,537 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 216 | 0 | a, b, n = map(int, input().split())
def gcd(a, b):
if a == 0:
return b
elif b == 0:
return a
m = max(a, b)
n = min(a, b)
r = m % n
while r > 0:
m = n
n = r
r = m % n
return n
while True:
x = gcd(a, n)
if n < x:
... | 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
a, b, n = map(int, input().split())
def gcd(a, b):
if a == 0:
return b
elif b == 0:
return a
m = max(a, b)
n = min(a, b)
r = m % n
while r > 0:
m = n
n = r
r = m % n
return n
while True:
x = gcd(a, n)
if n < x... | 3 | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=β€<=*n*<=β€<=1000) β the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer β the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,697,840,189 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | n = int(input())
p = 0
for i in range(n):
s = input()
if s.count("1")>=2:
p+=1
print(p)
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
n = int(input())
p = 0
for i in range(n):
s = input()
if s.count("1")>=2:
p+=1
print(p)
``` | 3 | |
286 | A | Lucky Permutation | PROGRAMMING | 1,400 | [
"constructive algorithms",
"math"
] | null | null | A permutation *p* of size *n* is the sequence *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct integers, each of them is from 1 to *n* (1<=β€<=*p**i*<=β€<=*n*).
A lucky permutation is such permutation *p*, that any integer *i* (1<=β€<=*i*<=β€<=*n*) meets this condition *p**p**i*<==<=*n*<=-<=*i*<=+<=1.
You have inte... | The first line contains integer *n* (1<=β€<=*n*<=β€<=105) β the required permutation size. | Print "-1" (without the quotes) if the lucky permutation *p* of size *n* doesn't exist.
Otherwise, print *n* distinct integers *p*1,<=*p*2,<=...,<=*p**n* (1<=β€<=*p**i*<=β€<=*n*) after a space β the required permutation.
If there are multiple answers, you can print any of them. | [
"1\n",
"2\n",
"4\n",
"5\n"
] | [
"1 \n",
"-1\n",
"2 4 1 3 \n",
"2 5 3 1 4 \n"
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "-1"
},
{
"input": "4",
"output": "2 4 1 3 "
},
{
"input": "5",
"output": "2 5 3 1 4 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "100000",
"output": "2 100000 4 99998 6 99996 8 99994... | 1,379,097,997 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 780 | 3,276,800 | n=int(input())
L=[0]*(n+1)
X=[False]*(n+1)
if(n%4!=0 and n%4!=1):
print(-1)
else:
for i in range(1,n+1):
if(X[i]):
continue
X[i]=True
X[n-i+1]=True
for j in range(i+1,n+1):
if(X[j]):
continue
X[j]=True
X[n-j+1]=T... | Title: Lucky Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation *p* of size *n* is the sequence *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct integers, each of them is from 1 to *n* (1<=β€<=*p**i*<=β€<=*n*).
A lucky permutation is such permutation *p*, that a... | ```python
n=int(input())
L=[0]*(n+1)
X=[False]*(n+1)
if(n%4!=0 and n%4!=1):
print(-1)
else:
for i in range(1,n+1):
if(X[i]):
continue
X[i]=True
X[n-i+1]=True
for j in range(i+1,n+1):
if(X[j]):
continue
X[j]=True
... | 3 | |
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,622,093,606 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | n=input()
nlist=[int(a) for a in n.split()]
width=nlist[0]
length=nlist[1]
if length%2==0:
print(int(length*width/2))
else:
print(int(length//2*width+width//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
n=input()
nlist=[int(a) for a in n.split()]
width=nlist[0]
length=nlist[1]
if length%2==0:
print(int(length*width/2))
else:
print(int(length//2*width+width//2))
``` | 3.969 |
505 | A | Mr. Kitayuta's Gift | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "tes... | The only line of the input contains a string *s* (1<=β€<=|*s*|<=β€<=10). Each character in *s* is a lowercase English letter. | If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted. | [
"revive\n",
"ee\n",
"kitayuta\n"
] | [
"reviver\n",
"eye",
"NA\n"
] | For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | 500 | [
{
"input": "revive",
"output": "reviver"
},
{
"input": "ee",
"output": "eee"
},
{
"input": "kitayuta",
"output": "NA"
},
{
"input": "evima",
"output": "NA"
},
{
"input": "a",
"output": "aa"
},
{
"input": "yutampo",
"output": "NA"
},
{
"inpu... | 1,459,292,943 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 4,608,000 | a=input()
for i in range(26):
for j in range(len(a)+1):
b=a[:j]+chr(97+i)+a[j:]
if b==b[::-1]:print(b);exit()
print('NA') | Title: Mr. Kitayuta's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that re... | ```python
a=input()
for i in range(26):
for j in range(len(a)+1):
b=a[:j]+chr(97+i)+a[j:]
if b==b[::-1]:print(b);exit()
print('NA')
``` | 3 | |
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task β he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels th... | The first line contains integer *n* (1<=β€<=*n*<=β€<=109) β the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1,β2,β3,β4,β5,β6,β7,β8,β9,β10,β11,β12,β13, which totals to 17 digits.
Note to the second sample. The books get numbers 1,β2,β3,β4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"... | 1,606,545,148 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 156 | 0 | # RawCoder : https://clck.ru/S8wGG
n = int(input())
if(n <= 9):print(n)
else:
le = len(str(n))
s = ""
req = 0
for k in range(1,le):
s += str(k)
print((n * le) - (int(s)*9)) | Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task β he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assig... | ```python
# RawCoder : https://clck.ru/S8wGG
n = int(input())
if(n <= 9):print(n)
else:
le = len(str(n))
s = ""
req = 0
for k in range(1,le):
s += str(k)
print((n * le) - (int(s)*9))
``` | 3 | |
735 | B | Urbanization | PROGRAMMING | 1,100 | [
"greedy",
"number theory",
"sortings"
] | null | null | Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* of them is equal to *a**i*. Authorities plan to build two cities, first for *n*1 people and second ... | The first line of the input contains three integers *n*, *n*1 and *n*2 (1<=β€<=*n*,<=*n*1,<=*n*2<=β€<=100<=000, *n*1<=+<=*n*2<=β€<=*n*)Β β the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line conta... | Print one real valueΒ β the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your ... | [
"2 1 1\n1 5\n",
"4 2 1\n1 4 2 3\n"
] | [
"6.00000000\n",
"6.50000000\n"
] | In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (*a*<sub class="lower-index">3</sub>β+β*a*<sub class=... | 1,000 | [
{
"input": "2 1 1\n1 5",
"output": "6.00000000"
},
{
"input": "4 2 1\n1 4 2 3",
"output": "6.50000000"
},
{
"input": "3 1 2\n1 2 3",
"output": "4.50000000"
},
{
"input": "10 4 6\n3 5 7 9 12 25 67 69 83 96",
"output": "88.91666667"
},
{
"input": "19 7 12\n1 2 4 8 1... | 1,515,217,097 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 187 | 30,924,800 | def solve():
n,n1,n2 = map(int, input().split())
lo = min([n1, n2])
hi = max([n1, n2])
l = list(map(int,input().split()))
l.sort(reverse=True)
#print(l)
s1 = sum(l[:lo])
s2 = sum(l[lo:lo+hi])
#print(s1)
#print(s2)
ans = (s1/lo) + (s2/hi)
print(ans)
solve() | Title: Urbanization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* o... | ```python
def solve():
n,n1,n2 = map(int, input().split())
lo = min([n1, n2])
hi = max([n1, n2])
l = list(map(int,input().split()))
l.sort(reverse=True)
#print(l)
s1 = sum(l[:lo])
s2 = sum(l[lo:lo+hi])
#print(s1)
#print(s2)
ans = (s1/lo) + (s2/hi)
print(ans)
... | 3 | |
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should cons... | The first line contains two positive integers *n* and *k* (2<=β€<=*n*<=β€<=100, 2<=β€<=*k*<=β€<=*min*(*n*,<=26)) β the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords β java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords β python, because its length is equal to 6 and it consists of 6 distinct lowercase letter... | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcde... | 1,658,781,925 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 46 | 0 | n, k =map(int,input().split())
wordlist = []
c = k
for i in range(n):
if len(wordlist)==n:
break
wordlist.append(chr(97+(i%k)))
if len(wordlist)==n:
break
print(''.join(wordlist)) | Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the foll... | ```python
n, k =map(int,input().split())
wordlist = []
c = k
for i in range(n):
if len(wordlist)==n:
break
wordlist.append(chr(97+(i%k)))
if len(wordlist)==n:
break
print(''.join(wordlist))
``` | 3 | |
716 | B | Complete the Word | PROGRAMMING | 1,300 | [
"greedy",
"two pointers"
] | null | null | ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not n... | The first and only line of the input contains a single string *s* (1<=β€<=|*s*|<=β€<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember... | If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line.
Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks... | [
"ABC??FGHIJK???OPQR?TUVWXY?\n",
"WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n",
"??????????????????????????\n",
"AABCDEFGHIJKLMNOPQRSTUVW??M\n"
] | [
"ABCDEFGHIJKLMNOPQRZTUVWXYS",
"-1",
"MNBVCXZLKJHGFDSAQPWOEIRUYT",
"-1"
] | In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZT... | 1,000 | [
{
"input": "ABC??FGHIJK???OPQR?TUVWXY?",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO",
"output": "-1"
},
{
"input": "??????????????????????????",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "AABCDEFGHIJKLMNO... | 1,583,428,246 | 2,147,483,647 | Python 3 | OK | TESTS | 115 | 764 | 819,200 | import math
#q=int(input())
q=1
for _ in range(q):
s=list(input())
n=len(s)
flag=False
file=[]
for i in range(n-25):
l=s[i:i+26]
k=[0]*26
ques=0
for j in range(26):
if l[j]!='?':
k[ord(l[j])-65]+=1
else:
... | Title: Complete the Word
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In pa... | ```python
import math
#q=int(input())
q=1
for _ in range(q):
s=list(input())
n=len(s)
flag=False
file=[]
for i in range(n-25):
l=s[i:i+26]
k=[0]*26
ques=0
for j in range(26):
if l[j]!='?':
k[ord(l[j])-65]+=1
else:... | 3 | |
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu... | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=β€<=*n*,<=*m*,<=*a*,<=*b*<=β€<=1000) β the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer β the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"... | 1,697,909,715 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 19 | 62 | 0 | n, m, a, b=map(int,input().split())
if b/m>=a:
print(n*a)
else:
s=(n//m)*b
x= n%m
s+=min(x*a,b)
print(s)
| Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl... | ```python
n, m, a, b=map(int,input().split())
if b/m>=a:
print(n*a)
else:
s=(n//m)*b
x= n%m
s+=min(x*a,b)
print(s)
``` | 3 | |
714 | A | Meeting of Old Friends | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Today an outstanding event is going to happen in the forestΒ β hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya.
Filya works a lot and he plans to ... | The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=β€<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=β€<=1018, *l*1<=β€<=*r*1, *l*2<=β€<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. | Print one integerΒ β the number of minutes Sonya and Filya will be able to spend together. | [
"1 10 9 20 1\n",
"1 100 50 200 75\n"
] | [
"2\n",
"50\n"
] | In the first sample, they will be together during minutes 9 and 10.
In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. | 500 | [
{
"input": "1 10 9 20 1",
"output": "2"
},
{
"input": "1 100 50 200 75",
"output": "50"
},
{
"input": "6 6 5 8 9",
"output": "1"
},
{
"input": "1 1000000000 1 1000000000 1",
"output": "999999999"
},
{
"input": "5 100 8 8 8",
"output": "0"
},
{
"input":... | 1,603,271,179 | 2,147,483,647 | PyPy 3 | OK | TESTS | 96 | 155 | 0 |
l1,r1,l2,r2,k=map(int,input().split())
ans=0
# if l2>=l1 and r1>=r2:
# ans=r2-l2+1
# if l2<=k<=r2:
# ans-=1
# else:
# pass
# elif l1>=l2 and r2<=r1 and r2>=l1:
# ans=r2-l1+1
# if l1<=k<=r2:
# ans-=1
# else:
# pass
# elif l2>=l1 and r2>=r1 and r1>=l2:
# ans=r1-l2+1
# if l2<=k<=r2:
# ... | Title: Meeting of Old Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today an outstanding event is going to happen in the forestΒ β hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusi... | ```python
l1,r1,l2,r2,k=map(int,input().split())
ans=0
# if l2>=l1 and r1>=r2:
# ans=r2-l2+1
# if l2<=k<=r2:
# ans-=1
# else:
# pass
# elif l1>=l2 and r2<=r1 and r2>=l1:
# ans=r2-l1+1
# if l1<=k<=r2:
# ans-=1
# else:
# pass
# elif l2>=l1 and r2>=r1 and r1>=l2:
# ans=r1-l2+1
# if l2<=k... | 3 | |
106 | B | Choosing Laptop | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | B. Choosing Laptop | 2 | 256 | Vasya is choosing a laptop. The shop has *n* laptops to all tastes.
Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties.
If all three properties of a laptop are strictly less than those propertie... | The first line contains number *n* (1<=β€<=*n*<=β€<=100).
Then follow *n* lines. Each describes a laptop as *speed* *ram* *hdd* *cost*. Besides,
- *speed*, *ram*, *hdd* and *cost* are integers - 1000<=β€<=*speed*<=β€<=4200 is the processor's speed in megahertz - 256<=β€<=*ram*<=β€<=4096 the RAM volume in megabytes - 1... | Print a single number β the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to *n* in the order in which they are given in the input data. | [
"5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150\n"
] | [
"4"
] | In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop. | 1,000 | [
{
"input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150",
"output": "4"
},
{
"input": "2\n1500 500 50 755\n1600 600 80 700",
"output": "2"
},
{
"input": "2\n1500 512 50 567\n1600 400 70 789",
"output": "1"
},
{
"input": "4\n10... | 1,620,832,010 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 124 | 6,963,200 | x = []
n = int(input())
for i in range(n):
a, b, c, d = map(int, input().split())
x.append((a,b,c,d))
y = 1001
for i in range(n):
f = 0
for j in range(n):
if x[i][0] < x[j][0] and x[i][1] < x[j][1] and x[i][2] < x[j][2]:
f = 1
break
if f == 0:
if x[i][3] < y:
y = x[i][3]
ans = i
pri... | Title: Choosing Laptop
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is choosing a laptop. The shop has *n* laptops to all tastes.
Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in ... | ```python
x = []
n = int(input())
for i in range(n):
a, b, c, d = map(int, input().split())
x.append((a,b,c,d))
y = 1001
for i in range(n):
f = 0
for j in range(n):
if x[i][0] < x[j][0] and x[i][1] < x[j][1] and x[i][2] < x[j][2]:
f = 1
break
if f == 0:
if x[i][3] < y:
y = x[i][3]
an... | 3.95603 |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=β€<=*n*<=β€<=105) β the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,689,489,538 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | s = int(input())
t = 0
for i in range(1,s):
s -= 1
if i%s==0:
t += 1
print(t)
| Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
s = int(input())
t = 0
for i in range(1,s):
s -= 1
if i%s==0:
t += 1
print(t)
``` | 3 | |
369 | C | Valera and Elections | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | The city Valera lives in is going to hold elections to the city Parliament.
The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, fo... | The first line contains a single integer *n* (2<=β€<=*n*<=β€<=105) β the number of districts in the city.
Then *n*<=-<=1 lines follow. Each line contains the description of a city road as three positive integers *x**i*, *y**i*, *t**i* (1<=β€<=*x**i*,<=*y**i*<=β€<=*n*, 1<=β€<=*t**i*<=β€<=2) β the districts connected by the *... | In the first line print a single non-negative number *k* β the minimum size of the required subset of candidates. Then on the second line print *k* space-separated integers *a*1,<=*a*2,<=... *a**k* β the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print a... | [
"5\n1 2 2\n2 3 2\n3 4 2\n4 5 2\n",
"5\n1 2 1\n2 3 2\n2 4 1\n4 5 1\n",
"5\n1 2 2\n1 3 2\n1 4 2\n1 5 2\n"
] | [
"1\n5 \n",
"1\n3 \n",
"4\n5 4 3 2 \n"
] | none | 1,500 | [
{
"input": "5\n1 2 2\n2 3 2\n3 4 2\n4 5 2",
"output": "1\n5 "
},
{
"input": "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1",
"output": "1\n3 "
},
{
"input": "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2",
"output": "4\n5 4 3 2 "
},
{
"input": "5\n1 5 1\n5 4 2\n4 3 1\n3 2 2",
"output": "1\n2 "
},
{
... | 1,679,031,180 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 74 | 483 | 54,476,800 | import sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
d = [defaultdict(int) for i in range(n+1)]
for i in range(n-1):
a, b, c = map(int, input().split())
d[a][b] = c
d[b][a] = c
q = [(1, -1)]
x = [0]*(n+1)
ew = []
while q:
a, b = q.pop()
if a > ... | Title: Valera and Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The city Valera lives in is going to hold elections to the city Parliament.
The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other... | ```python
import sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
d = [defaultdict(int) for i in range(n+1)]
for i in range(n-1):
a, b, c = map(int, input().split())
d[a][b] = c
d[b][a] = c
q = [(1, -1)]
x = [0]*(n+1)
ew = []
while q:
a, b = q.pop()
... | 3 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,698,429,095 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 124 | 0 | n=input()
item=[x for x in n]
s=item[0]
s=s.upper()
item[0]=s
s1=''.join(item)
print(s1) | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
n=input()
item=[x for x in n]
s=item[0]
s=s.upper()
item[0]=s
s1=''.join(item)
print(s1)
``` | 3 | |
306 | A | Candies | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus has got *n* candies and *m* friends (*n*<=β₯<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *... | The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=β€<=*n*,<=*m*<=β€<=100;*n*<=β₯<=*m*) β the number of candies and the number of Polycarpus's friends. | Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value. | [
"12 3\n",
"15 4\n",
"18 7\n"
] | [
"4 4 4 ",
"3 4 4 4 ",
"2 2 2 3 3 3 3 "
] | Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces. | 500 | [
{
"input": "12 4",
"output": "3 3 3 3 "
},
{
"input": "15 6",
"output": "2 2 2 3 3 3 "
},
{
"input": "18 8",
"output": "2 2 2 2 2 2 3 3 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "2 1",
"output": "2 "
},
{
"input": "100 1",
"output": "100 ... | 1,609,756,060 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 216 | 0 | n,m=map(int,input().split())
l=[]
if n%m==0:
for i in range(m):
l.append(n//m)
print(*l)
else:
for i in range(n%m):
l.append((n//m)+1)
for i in range(m-n%m):
l.append(n//m)
print(*l) | Title: Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has got *n* candies and *m* friends (*n*<=β₯<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most ... | ```python
n,m=map(int,input().split())
l=[]
if n%m==0:
for i in range(m):
l.append(n//m)
print(*l)
else:
for i in range(n%m):
l.append((n//m)+1)
for i in range(m-n%m):
l.append(n//m)
print(*l)
``` | 3 | |
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the mini... | The only line containing one integer *x* (1<=β€<=*x*<=β€<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th ... | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697... | 1,683,471,121 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 62 | 0 | i=0
ls=[0]
c=0
n = int(input())
while 2**i <= n:
i+=1
i-=1
for j in range(i,-1,-1):
c+=n//(2**j)
n=n%(2**j)
print(c) | Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split... | ```python
i=0
ls=[0]
c=0
n = int(input())
while 2**i <= n:
i+=1
i-=1
for j in range(i,-1,-1):
c+=n//(2**j)
n=n%(2**j)
print(c)
``` | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=β€<=*n*<=β€<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=β€<=*x**i*,<=*y**i*,<=*z**i*<=β€<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,627,894,187 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 154 | 6,963,200 | n = int(input())
x = 0
y = 0
z = 0
for i in range(n):
lst = list(map(int, input().strip().split()))[:3]
x += lst[0]
y += lst[1]
z += lst[2]
if (x == 0 and y == 0 and z == 0):
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
x = 0
y = 0
z = 0
for i in range(n):
lst = list(map(int, input().strip().split()))[:3]
x += lst[0]
y += lst[1]
z += lst[2]
if (x == 0 and y == 0 and z == 0):
print("YES")
else:
print("NO")
``` | 3.94853 |
476 | A | Dreamoon and Stairs | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? | The single line contains two space separated integers *n*, *m* (0<=<<=*n*<=β€<=10000,<=1<=<<=*m*<=β€<=10). | Print a single integer β the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead. | [
"10 2\n",
"3 5\n"
] | [
"6\n",
"-1\n"
] | For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5. | 500 | [
{
"input": "10 2",
"output": "6"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "29 7",
"output": "21"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "10000 2",
"output": "5000"
},
{
"input": "10000 ... | 1,697,791,583 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | import math
stairs, m = map(int, input().split())
found = False
if m > stairs:
print(-1)
exit()
for i in range(math.ceil(stairs / 2), stairs + 1):
if i % m == 0 and stairs >= math.ceil(i / m) * m:
print(i)
found = True
break
if not found:
print(-1)
| Title: Dreamoon and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb ... | ```python
import math
stairs, m = map(int, input().split())
found = False
if m > stairs:
print(-1)
exit()
for i in range(math.ceil(stairs / 2), stairs + 1):
if i % m == 0 and stairs >= math.ceil(i / m) * m:
print(i)
found = True
break
if not found:
print(-1)
``` | 3 | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers β *n* and *m* (2<=β€<=*n*<=<<=*m*<=β€<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=β€<=*n*<=<<=*m*<=β€<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,673,202,482 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 45 | 124 | 0 | n,m = map(int,input().split())
if m > n:
f = 1
for i in range(1,m//2+1):
if m % i == 0:
f = f + 1
if f == 2:
li = []
for j in range(n+1,m+1):
c = 1
for k in range(1,n+1//2+1):
if j % k == 0:
c = c + 1... | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
n,m = map(int,input().split())
if m > n:
f = 1
for i in range(1,m//2+1):
if m % i == 0:
f = f + 1
if f == 2:
li = []
for j in range(n+1,m+1):
c = 1
for k in range(1,n+1//2+1):
if j % k == 0:
... | 3.969 |
355 | A | Vasya and Digital Root | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation"
] | null | null | Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.
Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to:
1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<... | The first line contains two integers *k* and *d* (1<=β€<=*k*<=β€<=1000;β0<=β€<=*d*<=β€<=9). | In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist.
The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes. | [
"4 4\n",
"5 1\n",
"1 0\n"
] | [
"5881\n",
"36172\n",
"0\n"
] | For the first test sample *dr*(5881)ββ=ββ*dr*(22)ββ=ββ4.
For the second test sample *dr*(36172)ββ=ββ*dr*(19)ββ=ββ*dr*(10)ββ=ββ1. | 500 | [
{
"input": "4 4",
"output": "5881"
},
{
"input": "5 1",
"output": "36172"
},
{
"input": "1 0",
"output": "0"
},
{
"input": "8 7",
"output": "49722154"
},
{
"input": "487 0",
"output": "No solution"
},
{
"input": "1000 5",
"output": "854193955406789... | 1,591,623,170 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 108 | 0 | k,d=input().split();
k=int(k);
d=int(d);
if(d==0):
if(k==1):
print("0");
else:
print("No solution");
else:
r=d*(pow(10,k-1));
print(r);
| Title: Vasya and Digital Root
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.
Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=... | ```python
k,d=input().split();
k=int(k);
d=int(d);
if(d==0):
if(k==1):
print("0");
else:
print("No solution");
else:
r=d*(pow(10,k-1));
print(r);
``` | 3 | |
679 | A | Bear and Prime 100 | PROGRAMMING | 1,400 | [
"constructive algorithms",
"interactive",
"math"
] | null | null | This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden numberΒ β an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite.
Integer *x*<=><=1 is called prime if it has exactly two d... | After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise. | Up to 20 times you can ask a queryΒ β print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input.
In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flu... | [
"yes\nno\nyes\n",
"no\nyes\nno\nno\nno\n"
] | [
"2\n80\n5\ncomposite\n",
"58\n59\n78\n78\n2\nprime\n"
] | The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The hi... | 750 | [
{
"input": "30",
"output": "composite 4"
},
{
"input": "59",
"output": "prime 15"
},
{
"input": "2",
"output": "prime 16"
},
{
"input": "7",
"output": "prime 16"
},
{
"input": "9",
"output": "composite 3"
},
{
"input": "13",
"output": "prime 15"
... | 1,622,581,869 | 2,147,483,647 | PyPy 3 | OK | TESTS | 59 | 155 | 0 | prime=[1 for i in range(101)]
prime[0]=0
prime[1]=0
for i in range(2,101):
if prime[i]==1:
for j in range(i*i,101,i):
prime[j]=0
ans=[]
for i in range(2,101):
if prime[i]:
ans.append(i)
ans=ans[:-9]
ans.append(4)
ans.append(9)
ans.append(25)
ans.append(49)
#print(len(... | Title: Bear and Prime 100
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden numberΒ β an integer from interval [2,<=100]. Your task is to say i... | ```python
prime=[1 for i in range(101)]
prime[0]=0
prime[1]=0
for i in range(2,101):
if prime[i]==1:
for j in range(i*i,101,i):
prime[j]=0
ans=[]
for i in range(2,101):
if prime[i]:
ans.append(i)
ans=ans[:-9]
ans.append(4)
ans.append(9)
ans.append(25)
ans.append(49)
#... | 3 | |
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=β€<=*n*,<=*k*<=β€<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894"... | 1,609,962,847 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 171 | 0 | def numbers(n, k):
return n + k - n%k
n, k = map(int, input().split())
print(numbers(n, k)) | Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *... | ```python
def numbers(n, k):
return n + k - n%k
n, k = map(int, input().split())
print(numbers(n, k))
``` | 3 | |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* β a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=β€<=*n*<=β€<=105) β the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=β€<=*x**i*<=β€<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,683,139,273 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 171 | 16,281,600 | n=int(input())
lst=list(map(int,input().split()))
print(lst[1]-lst[0],lst[-1]-lst[0])
x,y=0,0
for i in range(1,n-1):
ch=""
x,y=lst[i]-lst[i-1],lst[i+1]-lst[i]
if x<y:
ch+=str(x)+" "
else:
ch+=str(y)+" "
x,y=lst[i]-lst[0],lst[n-1]-lst[i]
if x<y:
ch+=str(y)
... | Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* β a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
n=int(input())
lst=list(map(int,input().split()))
print(lst[1]-lst[0],lst[-1]-lst[0])
x,y=0,0
for i in range(1,n-1):
ch=""
x,y=lst[i]-lst[i-1],lst[i+1]-lst[i]
if x<y:
ch+=str(x)+" "
else:
ch+=str(y)+" "
x,y=lst[i]-lst[0],lst[n-1]-lst[i]
if x<y:
ch+=... | 3 | |
1,005 | A | Tanya and Stairways | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $1$ to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains $3$ steps, and the second contains $4$ ... | The first line contains $n$ ($1 \le n \le 1000$) β the total number of numbers pronounced by Tanya.
The second line contains integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1000$) β all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway wit... | In the first line, output $t$ β the number of stairways that Tanya climbed. In the second line, output $t$ numbers β the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways. | [
"7\n1 2 3 1 2 3 4\n",
"4\n1 1 1 1\n",
"5\n1 2 3 4 5\n",
"5\n1 2 1 2 1\n"
] | [
"2\n3 4 ",
"4\n1 1 1 1 ",
"1\n5 ",
"3\n2 2 1 "
] | none | 0 | [
{
"input": "7\n1 2 3 1 2 3 4",
"output": "2\n3 4 "
},
{
"input": "4\n1 1 1 1",
"output": "4\n1 1 1 1 "
},
{
"input": "5\n1 2 3 4 5",
"output": "1\n5 "
},
{
"input": "5\n1 2 1 2 1",
"output": "3\n2 2 1 "
},
{
"input": "1\n1",
"output": "1\n1 "
},
{
"inp... | 1,633,034,716 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 77 | 6,963,200 | n = int(input())
l = list(map(int, input().split()))
cur_stair = 1
ladders_length = []
ladders_cnt = 1
for i in range(1, len(l)):
if l[i] <= l[i-1]:
ladders_length.append(cur_stair)
ladders_cnt += 1
cur_stair = 0
cur_stair += 1
ladders_length.append(cur_stair)
print(lad... | Title: Tanya and Stairways
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $1$ to the number of steps in this stairway. She speaks every number aloud. For ... | ```python
n = int(input())
l = list(map(int, input().split()))
cur_stair = 1
ladders_length = []
ladders_cnt = 1
for i in range(1, len(l)):
if l[i] <= l[i-1]:
ladders_length.append(cur_stair)
ladders_cnt += 1
cur_stair = 0
cur_stair += 1
ladders_length.append(cur_stair)
... | 3 | |
710 | A | King Moves | PROGRAMMING | 800 | [
"implementation"
] | null | null | The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wik... | The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. | Print the only integer *x* β the number of moves permitted for the king. | [
"e4\n"
] | [
"8\n"
] | none | 0 | [
{
"input": "e4",
"output": "8"
},
{
"input": "a1",
"output": "3"
},
{
"input": "h8",
"output": "3"
},
{
"input": "a4",
"output": "5"
},
{
"input": "g7",
"output": "8"
},
{
"input": "e1",
"output": "5"
},
{
"input": "b2",
"output": "8"
... | 1,549,122,017 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 93 | 0 | move = input()
c = move[0]
d = int(move[1])
moves = 0
if c=='a' or c=='h':
moves = 3
if 1<d<8:
moves += 2
else:
moves = 8
if d==1 or d==8:
moves -=3
print(moves)
| Title: King Moves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check... | ```python
move = input()
c = move[0]
d = int(move[1])
moves = 0
if c=='a' or c=='h':
moves = 3
if 1<d<8:
moves += 2
else:
moves = 8
if d==1 or d==8:
moves -=3
print(moves)
``` | 3 | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=β€<=*x*<=β€<=1<=000<=000)Β β The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,697,627,559 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 46 | 0 | n = int(input())
print(n % 5 and n // 5 + 1 or n // 5) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
n = int(input())
print(n % 5 and n // 5 + 1 or n // 5)
``` | 3 | |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=β€<=*k*<=β€<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=β€<=|*s*|<=β€<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,662,273,164 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 124 | 0 | #ζεεε
₯εγ―γγγͺοΌοΌ
#carpe diem
'''
βββ βββ ββββ ββββ βββ βββββββββ
βββ βββ βββββ βββββ βββ βββββββββ
ββββββββββββ βββββββββββ ββββββββββββββ ββββββ βββββββββ ββββββββββ
βββ βββ βββββββββββ βββ βββ
ββββββββ βββ βββ βββ βββ βββ βββ
... | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
#ζεεε
₯εγ―γγγͺοΌοΌ
#carpe diem
'''
βββ βββ ββββ ββββ βββ βββββββββ
βββ βββ βββββ βββββ βββ βββββββββ
ββββββββββββ βββββββββββ ββββββββββββββ ββββββ βββββββββ ββββββββββ
βββ βββ βββββββββββ βββ βββ
ββββββββ βββ βββ βββ βββ βββ ... | 3 | |
753 | A | Santa Claus and Candies | PROGRAMMING | 1,000 | [
"dp",
"greedy",
"math"
] | null | null | Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. | The only line contains positive integer number *n* (1<=β€<=*n*<=β€<=1000) β number of candies Santa Claus has. | Print to the first line integer number *k* β maximal number of kids which can get candies.
Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*.
If there are many solutions, print any of them. | [
"5\n",
"9\n",
"2\n"
] | [
"2\n2 3\n",
"3\n3 5 1\n",
"1\n2 \n"
] | none | 500 | [
{
"input": "5",
"output": "2\n1 4 "
},
{
"input": "9",
"output": "3\n1 2 6 "
},
{
"input": "2",
"output": "1\n2 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "3",
"output": "2\n1 2 "
},
{
"input": "1000",
"output": "44\n1 2 3 4 5 6 7 8 9 10 ... | 1,574,756,497 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 140 | 0 | a=int(input())
# n2 + n -2*a
r=int((-1+(1+8*a)**0.5)//2)
print(r)
extra=a-(r*(r+1))//2
ans=[i for i in range(1,r+1)]
ans[-1]+=extra
print(*ans)
| Title: Santa Claus and Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer n... | ```python
a=int(input())
# n2 + n -2*a
r=int((-1+(1+8*a)**0.5)//2)
print(r)
extra=a-(r*(r+1))//2
ans=[i for i in range(1,r+1)]
ans[-1]+=extra
print(*ans)
``` | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=β€<=*n*<=β€<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=β€<=*x**i*,<=*y**i*,<=*z**i*<=β€<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,663,238,979 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | num=int(input())
m,n,k=0,0,0
for i in range(num):
a,b,c=map(int,input().split())
m+=a;n+=b;k+=c
if m==0 and n==0 and k==0:
print('YES')
else:
print('NO')
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
num=int(input())
m,n,k=0,0,0
for i in range(num):
a,b,c=map(int,input().split())
m+=a;n+=b;k+=c
if m==0 and n==0 and k==0:
print('YES')
else:
print('NO')
``` | 3.977 |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=Γ<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer β the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,695,208,726 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | raw = 0
column = 0
for i in range(5):
curr = input()
if curr.count("1") > 0:
raw = i
curr = list(map(int, curr.split(' ')))
for j in range(5):
if curr[j] == 1:
column = j
print(abs(raw - 2) + abs(column - 2)) | Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=Γ<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
raw = 0
column = 0
for i in range(5):
curr = input()
if curr.count("1") > 0:
raw = i
curr = list(map(int, curr.split(' ')))
for j in range(5):
if curr[j] == 1:
column = j
print(abs(raw - 2) + abs(column - 2))
``` | 3 | |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers β the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number β the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1βΓβ1βΓβ1, in the second oneΒ β 2βΓβ2βΓβ3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,601,894,767 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 278 | 0 | import math
a,b,c=map(int,input().split())
a1=(a*c/b)**0.5
a2=(a*b/c)**0.5
a3=(b*c/a)**0.5
print(int(4*(a1+a2+a3))) | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
import math
a,b,c=map(int,input().split())
a1=(a*c/b)**0.5
a2=(a*b/c)**0.5
a3=(b*c/a)**0.5
print(int(4*(a1+a2+a3)))
``` | 3 | |
918 | A | Eleven | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the ... | The first and only line of input contains an integer *n* (1<=β€<=*n*<=β€<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | 500 | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooo... | 1,595,848,697 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 109 | 6,656,000 | a=int(input())
b=1
c=2
x=[]
s=""
while(b<=a):
d=b+c
x. append(b)
b=c
c=d
for i in range(1,a+1):
if i in x:
s=s+'O'
else:
s=s+'o'
print(s)
| Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should o... | ```python
a=int(input())
b=1
c=2
x=[]
s=""
while(b<=a):
d=b+c
x. append(b)
b=c
c=d
for i in range(1,a+1):
if i in x:
s=s+'O'
else:
s=s+'o'
print(s)
``` | 3 | |
766 | A | Mahmoud and Longest Uncommon Subsequence | PROGRAMMING | 1,000 | [
"constructive algorithms",
"strings"
] | null | null | While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence ... | The first line contains string *a*, and the second lineΒ β string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. | If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*. | [
"abcd\ndefgh\n",
"a\na\n"
] | [
"5\n",
"-1\n"
] | In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*. | 500 | [
{
"input": "abcd\ndefgh",
"output": "5"
},
{
"input": "a\na",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddd... | 1,673,968,077 | 2,147,483,647 | Python 3 | OK | TESTS | 73 | 46 | 102,400 | a=input()
b=input()
if a==b:
res=-1
else:
res=max(len(a),len(b))
print(res) | Title: Mahmoud and Longest Uncommon Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two ... | ```python
a=input()
b=input()
if a==b:
res=-1
else:
res=max(len(a),len(b))
print(res)
``` | 3 | |
707 | C | Pythagorean Triples | PROGRAMMING | 1,500 | [
"math",
"number theory"
] | null | null | Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.
For example, tripl... | The only line of the input contains single integer *n* (1<=β€<=*n*<=β€<=109)Β β the length of some side of a right triangle. | Print two integers *m* and *k* (1<=β€<=*m*,<=*k*<=β€<=1018), such that *n*, *m* and *k* form a Pythagorean triple, in the only line.
In case if there is no any Pythagorean triple containing integer *n*, print <=-<=1 in the only line. If there are many answers, print any of them. | [
"3\n",
"6\n",
"1\n",
"17\n",
"67\n"
] | [
"4 5",
"8 10",
"-1",
"144 145",
"2244 2245"
] | Illustration for the first sample. | 1,500 | [
{
"input": "3",
"output": "4 5"
},
{
"input": "6",
"output": "8 10"
},
{
"input": "1",
"output": "-1"
},
{
"input": "17",
"output": "144 145"
},
{
"input": "67",
"output": "2244 2245"
},
{
"input": "10",
"output": "24 26"
},
{
"input": "14"... | 1,656,248,682 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 90 | 62 | 28,364,800 | n = int(input())
if n % 2 == 0:
x = (n // 2) ** 2
n1 = x - 1
n2 = x + 1
else:
x = (n ** 2) // 2
n1 = x
n2 = x + 1
if n1 != n != n2 and n1 > 0 and n2 > 0:
print(n1, n2)
else:
print(-1)
| Title: Pythagorean Triples
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segm... | ```python
n = int(input())
if n % 2 == 0:
x = (n // 2) ** 2
n1 = x - 1
n2 = x + 1
else:
x = (n ** 2) // 2
n1 = x
n2 = x + 1
if n1 != n != n2 and n1 > 0 and n2 > 0:
print(n1, n2)
else:
print(-1)
``` | 3 | |
343 | A | Rational Resistance | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance *R*0<==<=1. Elements with other resistance can be constructed from these resistors. In this problem, we wil... | The single input line contains two space-separated integers *a* and *b* (1<=β€<=*a*,<=*b*<=β€<=1018). It is guaranteed that the fraction is irreducible. It is guaranteed that a solution always exists. | Print a single number β the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is recommended to use the cin, cout streams or the %I64d specifier. | [
"1 1\n",
"3 2\n",
"199 200\n"
] | [
"1\n",
"3\n",
"200\n"
] | In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5305da389756aab6... | 500 | [
{
"input": "1 1",
"output": "1"
},
{
"input": "3 2",
"output": "3"
},
{
"input": "199 200",
"output": "200"
},
{
"input": "1 1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "21 8",
"output": "7... | 1,671,956,136 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 53 | 154 | 0 | import sys
input = sys.stdin.readline
def gcd(a, b):
if(b == 0):
return 0
return a // b + gcd(b, a % b)
a, b = map(int, input().split())
print(gcd(a, b)) | Title: Rational Resistance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance *R... | ```python
import sys
input = sys.stdin.readline
def gcd(a, b):
if(b == 0):
return 0
return a // b + gcd(b, a % b)
a, b = map(int, input().split())
print(gcd(a, b))
``` | 3 | |
139 | A | Petr and Book | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. S... | The first input line contains the single integer *n* (1<=β€<=*n*<=β€<=1000) β the number of pages in the book.
The second line contains seven non-negative space-separated integers that do not exceed 1000 β those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and... | Print a single number β the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. | [
"100\n15 20 20 15 10 30 45\n",
"2\n1 0 0 0 0 0 0\n"
] | [
"6\n",
"1\n"
] | Note to the first sample:
By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else).
Note to the second... | 500 | [
{
"input": "100\n15 20 20 15 10 30 45",
"output": "6"
},
{
"input": "2\n1 0 0 0 0 0 0",
"output": "1"
},
{
"input": "100\n100 200 100 200 300 400 500",
"output": "1"
},
{
"input": "3\n1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "1\n1 1 1 1 1 1 1",
"output": "1... | 1,659,241,652 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 92 | 0 | n = int(input())
lst = list(map(int, input().split()))
day=0
flag=0
while True:
day=0
for i in range(len(lst)):
if n<=lst[i]:
print(day+1)
flag=1
break
else:
n-=lst[i]
day+=1
if flag==1:
break | Title: Petr and Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight s... | ```python
n = int(input())
lst = list(map(int, input().split()))
day=0
flag=0
while True:
day=0
for i in range(len(lst)):
if n<=lst[i]:
print(day+1)
flag=1
break
else:
n-=lst[i]
day+=1
if flag==1:
... | 3 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=β€<=*n*<=β€<=2000;Β 1<=β€<=*k*<=β€<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=β€<=*y**i*<=β€<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number β the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,686,679,701 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | n, m = map(int, input().split())
ans = 0
temp = 5 - m
l = list(map(int, input().split()))
for i in range(n):
temp2 = l[i]
if(temp2 <= temp):
ans += 1
print(ans // 3) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n, m = map(int, input().split())
ans = 0
temp = 5 - m
l = list(map(int, input().split()))
for i in range(n):
temp2 = l[i]
if(temp2 <= temp):
ans += 1
print(ans // 3)
``` | 3 | |
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,678,695,565 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 62 | 0 | from math import comb
n,m=map(int,input().split())
maxi=comb(n-m+1,2)
if m%n==0:
mini=m*comb(m//n,2)
else:
mini=n%m*(comb(n//m+1,2))+(m-n%m)*(comb(n//m,2))
print(mini,maxi) | 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
from math import comb
n,m=map(int,input().split())
maxi=comb(n-m+1,2)
if m%n==0:
mini=m*comb(m//n,2)
else:
mini=n%m*(comb(n//m+1,2))+(m-n%m)*(comb(n//m,2))
print(mini,maxi)
``` | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=β€<=*n*<=β€<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,673,110,701 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n = int(input())
b=[]
for i in range(n):
a = input()
b.append(a)
for i in b:
if len(i) <= 10:
print(i)
else:
f=[]
f.append(i[0])
f.append(len(i)-2)
f.append(i[len(i)-1])
for j in f:
print(j,end='')
print() | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
n = int(input())
b=[]
for i in range(n):
a = input()
b.append(a)
for i in b:
if len(i) <= 10:
print(i)
else:
f=[]
f.append(i[0])
f.append(len(i)-2)
f.append(i[len(i)-1])
for j in f:
print(j,end='')
print()
``` | 3.977 |
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi... | The first line contains two integers, *n* and *m* (1<=β€<=*n*<=β€<=3000, 1<=β€<=*m*<=β€<=3000) β the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel... | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input"... | 1,671,486,460 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 62 | 102,400 | n, m = input().split()
d = dict()
for _ in range(int(m)):
a, b = input().split()
v = min((a, b), key=len)
d[a] = v
print(*[d[k] for k in input().split()]) | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first ... | ```python
n, m = input().split()
d = dict()
for _ in range(int(m)):
a, b = input().split()
v = min((a, b), key=len)
d[a] = v
print(*[d[k] for k in input().split()])
``` | 3 | |
825 | A | Binary Protocol | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in ord... | The first line contains one integer number *n* (1<=β€<=*n*<=β€<=89) β length of the string *s*.
The second line contains string *s* β sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts... | Print the decoded number. | [
"3\n111\n",
"9\n110011101\n"
] | [
"3\n",
"2031\n"
] | none | 0 | [
{
"input": "3\n111",
"output": "3"
},
{
"input": "9\n110011101",
"output": "2031"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "3\n100",
"output": "100"
},
{
"input": "5\n10001",
"output": "1001"
},
{
"input": "14\n11001100011000",
"output": "... | 1,500,218,132 | 632 | Python 3 | OK | TESTS | 13 | 62 | 4,608,000 | def main():
N = int(input())
S = list(input())
count = 0
res = ""
for s in S:
if s == "1":
count += 1
else:
res += str(count)
count = 0
res += str(count)
print(res)
if __name__ == "__main__":
# global stime
#... | Title: Binary Protocol
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' charact... | ```python
def main():
N = int(input())
S = list(input())
count = 0
res = ""
for s in S:
if s == "1":
count += 1
else:
res += str(count)
count = 0
res += str(count)
print(res)
if __name__ == "__main__":
# global st... | 3 | |
437 | C | The Child and Toy | PROGRAMMING | 1,400 | [
"graphs",
"greedy",
"sortings"
] | null | null | On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of *n* parts and *m* ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts.... | The first line contains two integers *n* and *m* (1<=β€<=*n*<=β€<=1000; 0<=β€<=*m*<=β€<=2000). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (0<=β€<=*v**i*<=β€<=105). Then followed *m* lines, each line contains two integers *x**i* and *y**i*, representing a rope from part *x**i* to part *y**i* (1<=β€<=*x**... | Output the minimum total energy the child should spend to remove all *n* parts of the toy. | [
"4 3\n10 20 30 40\n1 4\n1 2\n2 3\n",
"4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n",
"7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4\n"
] | [
"40\n",
"400\n",
"160\n"
] | One of the optimal sequence of actions in the first sample is:
- First, remove part 3, cost of the action is 20. - Then, remove part 2, cost of the action is 10. - Next, remove part 4, cost of the action is 10. - At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20β+β10β+β10β+... | 1,500 | [
{
"input": "4 3\n10 20 30 40\n1 4\n1 2\n2 3",
"output": "40"
},
{
"input": "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4",
"output": "400"
},
{
"input": "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4",
"output": "160"
},
{
"input": "1 0\n23333",
... | 1,596,740,055 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 108 | 6,963,200 | n, m = map(int, input().split())
cost = [0] + list(map(int, input().split()))
res = 0
for i in range(m):
x, y = map(int, input().split())
res += min(cost[x], cost[y])
print(res) | Title: The Child and Toy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of *n* parts and *m* ropes. Each rope links two parts, but ev... | ```python
n, m = map(int, input().split())
cost = [0] + list(map(int, input().split()))
res = 0
for i in range(m):
x, y = map(int, input().split())
res += min(cost[x], cost[y])
print(res)
``` | 3 | |
897 | A | Scarborough Fair | PROGRAMMING | 800 | [
"implementation"
] | null | null | Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Althou... | The first line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100).
The second line contains a string *s* of length *n*, consisting of lowercase English letters.
Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=β€<=*l*<=β€<=*r*<=β€<=*n*, *c*1,<=*c*2 are lowercase English letters), ... | Output string *s* after performing *m* operations described above. | [
"3 1\nioi\n1 1 i n\n",
"5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n"
] | [
"noi",
"gaaak"
] | For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak. | 500 | [
{
"input": "3 1\nioi\n1 1 i n",
"output": "noi"
},
{
"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g",
"output": "gaaak"
},
{
"input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n... | 1,612,445,465 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 62 | 0 | n,m=map(int,input().split())
s=input()
for i in range(m):
l,r,c1,c2=input().split()
s=s[:int(l)-1]+s[int(l)-1:int(r)].replace(c1,c2)+s[int(r):]
print(s) | Title: Scarborough Fair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get ... | ```python
n,m=map(int,input().split())
s=input()
for i in range(m):
l,r,c1,c2=input().split()
s=s[:int(l)-1]+s[int(l)-1:int(r)].replace(c1,c2)+s[int(r):]
print(s)
``` | 3 | |
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer *n* (1<=β€<=*n*<=β€<=100) β the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=β€<=*x**i*,<=*y**i*<=β€<=1000) β the coordinates of the *i*-th snow drift.
Note that the north direction coinΡides with the direction of *Oy* ... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182... | 1,644,778,159 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 92 | 0 | n = int(input())
coords = []
for _ in range(n):
nx, ny = map(int, input().split())
coords.append((nx, ny))
def search(x, y, v):
v.append((x, y))
for nx, ny in coords:
if (nx == x and ny != y) or (nx != x and ny == y):
if (nx, ny) not in v:
search(nx, ny, v)
ret... | Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha... | ```python
n = int(input())
coords = []
for _ in range(n):
nx, ny = map(int, input().split())
coords.append((nx, ny))
def search(x, y, v):
v.append((x, y))
for nx, ny in coords:
if (nx == x and ny != y) or (nx != x and ny == y):
if (nx, ny) not in v:
search(nx, ny, ... | 3 | |
779 | A | Pupils Redistribution | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | In Berland each high school student is characterized by academic performance β integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consists of exactly *n* students. An academic performance of each student is known β integer value between 1 and ... | The first line of the input contains integer number *n* (1<=β€<=*n*<=β€<=100) β number of students in both groups.
The second line contains sequence of integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=5), where *a**i* is academic performance of the *i*-th student of the group *A*.
The third line contains se... | Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained. | [
"4\n5 4 4 4\n5 5 4 5\n",
"6\n1 1 1 1 1 1\n5 5 5 5 5 5\n",
"1\n5\n3\n",
"9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1\n"
] | [
"1\n",
"3\n",
"-1\n",
"4\n"
] | none | 500 | [
{
"input": "4\n5 4 4 4\n5 5 4 5",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1\n5 5 5 5 5 5",
"output": "3"
},
{
"input": "1\n5\n3",
"output": "-1"
},
{
"input": "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1",
"output": "4"
},
{
"input": "1\n1\n2",
"output": "-1"
... | 1,657,310,353 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 46 | 0 | n = int(input())
A = map(int, input().split())
B = map(int, input().split())
dic_a = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
dic_b = dic_a.copy()
for x, y in zip(A, B):
dic_a[x] += 1
dic_b[y] += 1
c = 0
res = 0
for i in range(1, 6):
value = dic_a[i]-dic_b[i]
if abs(value) % 2 != 0:
c = 1
else:
... | Title: Pupils Redistribution
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland each high school student is characterized by academic performance β integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consis... | ```python
n = int(input())
A = map(int, input().split())
B = map(int, input().split())
dic_a = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
dic_b = dic_a.copy()
for x, y in zip(A, B):
dic_a[x] += 1
dic_b[y] += 1
c = 0
res = 0
for i in range(1, 6):
value = dic_a[i]-dic_b[i]
if abs(value) % 2 != 0:
c = 1
... | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,567,686,855 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 0 | n=int(input())
ans=0
l=[int(x) for x in input().split()]
x=n+1
y=sum(l)
for i in range(1,6):
if (y+i)%x!=1:
ans+=1
print(ans) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n=int(input())
ans=0
l=[int(x) for x in input().split()]
x=n+1
y=sum(l)
for i in range(1,6):
if (y+i)%x!=1:
ans+=1
print(ans)
``` | 3 | |
401 | C | Team | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing ... | The first line contains two integers: *n* (1<=β€<=*n*<=β€<=106) β the number of cards containing number 0; *m* (1<=β€<=*m*<=β€<=106) β the number of cards containing number 1. | In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. | [
"1 2\n",
"4 8\n",
"4 10\n",
"1 5\n"
] | [
"101\n",
"110110110101\n",
"11011011011011\n",
"-1\n"
] | none | 1,500 | [
{
"input": "1 2",
"output": "101"
},
{
"input": "4 8",
"output": "110110110101"
},
{
"input": "4 10",
"output": "11011011011011"
},
{
"input": "1 5",
"output": "-1"
},
{
"input": "3 4",
"output": "1010101"
},
{
"input": "3 10",
"output": "-1"
},
... | 1,610,887,380 | 2,147,483,647 | PyPy 3 | OK | TESTS | 81 | 280 | 13,004,800 | fast=lambda:stdin.readline().strip()
zzz=lambda:[int(i) for i in fast().split()]
z,zz=input,lambda:list(map(int,z().split()))
szz,graph,mod,szzz=lambda:sorted(zz()),{},10**9+7,lambda:sorted(zzz())
from re import *
from sys import *
from math import *
from heapq import *
from queue import *
from bisect import *... | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each t... | ```python
fast=lambda:stdin.readline().strip()
zzz=lambda:[int(i) for i in fast().split()]
z,zz=input,lambda:list(map(int,z().split()))
szz,graph,mod,szzz=lambda:sorted(zz()),{},10**9+7,lambda:sorted(zzz())
from re import *
from sys import *
from math import *
from heapq import *
from queue import *
from bisec... | 3 | |
766 | A | Mahmoud and Longest Uncommon Subsequence | PROGRAMMING | 1,000 | [
"constructive algorithms",
"strings"
] | null | null | While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence ... | The first line contains string *a*, and the second lineΒ β string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. | If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*. | [
"abcd\ndefgh\n",
"a\na\n"
] | [
"5\n",
"-1\n"
] | In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*. | 500 | [
{
"input": "abcd\ndefgh",
"output": "5"
},
{
"input": "a\na",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddd... | 1,645,781,406 | 2,147,483,647 | Python 3 | OK | TESTS | 73 | 46 | 0 | a = str(input())
b = str(input())
if len(a) > len(b):
print(len(a))
elif len(a) < len(b):
print(len(b))
elif len(a) == len(b):
if a == b:
print(-1)
else:
print(len(a)) | Title: Mahmoud and Longest Uncommon Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two ... | ```python
a = str(input())
b = str(input())
if len(a) > len(b):
print(len(a))
elif len(a) < len(b):
print(len(b))
elif len(a) == len(b):
if a == b:
print(-1)
else:
print(len(a))
``` | 3 | |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | The only line contains two integers: *n* and *m* (3<=β€<=*n*,<=*m*<=β€<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#... | 1,688,188,673 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | i, j = map(int, input().split())
o = 0
for i in range(i):
if i%2 == 0:
print("#"*j)
elif i == (4*o)+1:
print("."*(j-1)+"#")
o = o+1
else:
print("#"+"."*(j-1)) | Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*... | ```python
i, j = map(int, input().split())
o = 0
for i in range(i):
if i%2 == 0:
print("#"*j)
elif i == (4*o)+1:
print("."*(j-1)+"#")
o = o+1
else:
print("#"+"."*(j-1))
``` | 3 | |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=β€<=*x*1,<=*x*2,<=*x*3<=β€<=100)Β β the coordinates of the houses of the first, the second and the third friends respectively. | Print one integerΒ β the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,684,086,649 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | x1, x2, x3 = map(int, input().split())
# Sort the points
points = [x1, x2, x3]
points.sort()
# Calculate the middle point and the total distance
middle_point = points[1]
total_distance = abs(middle_point - x1) + abs(middle_point - x2) + abs(middle_point - x3)
print(total_distance) | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
x1, x2, x3 = map(int, input().split())
# Sort the points
points = [x1, x2, x3]
points.sort()
# Calculate the middle point and the total distance
middle_point = points[1]
total_distance = abs(middle_point - x1) + abs(middle_point - x2) + abs(middle_point - x3)
print(total_distance)
``` | 3 | |
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=β€<=*n*<=β€<=105) β the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7... | 1,687,585,615 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 77 | 12,800,000 | n=int(input())
ans = 1
j = 1
l=list(map(int,input().split()))
for i in range(1,n):
if l[i]>l[i-1]:
j+=1
else:
j=1
if j>ans:
ans=j
print(ans) | Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called... | ```python
n=int(input())
ans = 1
j = 1
l=list(map(int,input().split()))
for i in range(1,n):
if l[i]>l[i-1]:
j+=1
else:
j=1
if j>ans:
ans=j
print(ans)
``` | 3 | |
612 | B | HDD is Outdated Technology | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.
One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read s... | The first line contains a positive integer *n* (1<=β€<=*n*<=β€<=2Β·105) β the number of fragments.
The second line contains *n* different integers *f**i* (1<=β€<=*f**i*<=β€<=*n*) β the number of the fragment written in the *i*-th sector. | Print the only integer β the number of time units needed to read the file. | [
"3\n3 1 2\n",
"5\n1 3 5 4 2\n"
] | [
"3\n",
"10\n"
] | In the second example the head moves in the following way:
- 1->2 means movement from the sector 1 to the sector 5, i.e. it takes 4 time units - 2->3 means movement from the sector 5 to the sector 2, i.e. it takes 3 time units - 3->4 means movement from the sector 2 to the sector 4, i.e. it takes 2 time un... | 0 | [
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "5\n1 3 5 4 2",
"output": "10"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "10\n8 2 10 3 4 6 1 7 9 5",
"output": "40"
... | 1,565,979,050 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 265 | 14,233,600 | def hdd(n, lst):
res, answer = [0] * n, 0
for i in range(n):
res[lst[i] - 1] = i
for i in range(n - 1):
answer += abs(res[i] - res[i + 1])
return answer
m = int(input())
a = [int(j) for j in input().split()]
print(hdd(m, a))
| Title: HDD is Outdated Technology
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.
One of the ... | ```python
def hdd(n, lst):
res, answer = [0] * n, 0
for i in range(n):
res[lst[i] - 1] = i
for i in range(n - 1):
answer += abs(res[i] - res[i + 1])
return answer
m = int(input())
a = [int(j) for j in input().split()]
print(hdd(m, a))
``` | 3 | |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=β€<=*a*1,<=*a*2,<=*a*3,<=*a*4<=β€<=104).
The second line contains string *s* (1<=β€<=|*s*|<=β€<=105), where the *Ρ*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer β the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,671,652,836 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 93 | 1,740,800 | spent = 0
calories = list(map(int,input().split()))
game = input()
for strip in game:
spent += calories[int(strip)-1]
print(spent) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
spent = 0
calories = list(map(int,input().split()))
game = input()
for strip in game:
spent += calories[int(strip)-1]
print(spent)
``` | 3 | |
998 | B | Cutting | PROGRAMMING | 1,200 | [
"dp",
"greedy",
"sortings"
] | null | null | There are a lot of things which could be cutΒ β trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulti... | First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$)Β β the number of elements in the sequence and the number of bitcoins you have.
Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$)Β β elements of the sequence, which contains the equal... | Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins. | [
"6 4\n1 2 5 10 15 20\n",
"4 10\n1 3 2 4\n",
"6 100\n1 2 3 4 5 6\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins.
In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.
In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$.... | 1,000 | [
{
"input": "6 4\n1 2 5 10 15 20",
"output": "1"
},
{
"input": "4 10\n1 3 2 4",
"output": "0"
},
{
"input": "6 100\n1 2 3 4 5 6",
"output": "2"
},
{
"input": "2 100\n13 78",
"output": "0"
},
{
"input": "10 1\n56 56 98 2 11 64 97 41 95 53",
"output": "0"
},
... | 1,614,954,929 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 93 | 1,228,800 | n,b=list(map(int,input().split()))
a=list(map(int,input().split()))
e=[a[i]%2 for i in range(n)]
c=[]
for i in range(1,n):
if sum(e[i:])==(n-i)/2 and sum(e[:i])==i/2:
c.append(abs(a[i]-a[i-1]))
c.sort()
i=0
d=0
while i<len(c) and d+c[i]<=b:
d+=c[i]
i+=1
print(i) | Title: Cutting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are a lot of things which could be cutΒ β trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Gi... | ```python
n,b=list(map(int,input().split()))
a=list(map(int,input().split()))
e=[a[i]%2 for i in range(n)]
c=[]
for i in range(1,n):
if sum(e[i:])==(n-i)/2 and sum(e[:i])==i/2:
c.append(abs(a[i]-a[i-1]))
c.sort()
i=0
d=0
while i<len(c) and d+c[i]<=b:
d+=c[i]
i+=1
print(i)
``` | 3 | |
978 | C | Letters | PROGRAMMING | 1,000 | [
"binary search",
"implementation",
"two pointers"
] | null | null | There are $n$ dormitories in Berland State University, they are numbered with integers from $1$ to $n$. Each dormitory consists of rooms, there are $a_i$ rooms in $i$-th dormitory. The rooms in $i$-th dormitory are numbered from $1$ to $a_i$.
A postman delivers letters. Sometimes there is no specific dormitory and roo... | The first line contains two integers $n$ and $m$ $(1 \le n, m \le 2 \cdot 10^{5})$ β the number of dormitories and the number of letters.
The second line contains a sequence $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 10^{10})$, where $a_i$ equals to the number of rooms in the $i$-th dormitory. The third line contains a se... | Print $m$ lines. For each letter print two integers $f$ and $k$ β the dormitory number $f$ $(1 \le f \le n)$ and the room number $k$ in this dormitory $(1 \le k \le a_f)$ to deliver the letter. | [
"3 6\n10 15 12\n1 9 12 23 26 37\n",
"2 3\n5 10000000000\n5 6 9999999999\n"
] | [
"1 1\n1 9\n2 2\n2 13\n3 1\n3 12\n",
"1 5\n2 1\n2 9999999994\n"
] | In the first example letters should be delivered in the following order:
- the first letter in room $1$ of the first dormitory - the second letter in room $9$ of the first dormitory - the third letter in room $2$ of the second dormitory - the fourth letter in room $13$ of the second dormitory - the fifth letter i... | 0 | [
{
"input": "3 6\n10 15 12\n1 9 12 23 26 37",
"output": "1 1\n1 9\n2 2\n2 13\n3 1\n3 12"
},
{
"input": "2 3\n5 10000000000\n5 6 9999999999",
"output": "1 5\n2 1\n2 9999999994"
},
{
"input": "1 1\n1\n1",
"output": "1 1"
},
{
"input": "5 15\n10 20 30 20 10\n1 6 10 11 15 30 31 54... | 1,677,602,573 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 16 | 342 | 36,864,000 | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
k = a[c]
for i in b:
while i > k:
c += 1
k += a[c]
print(c + 1,i + a[c] - k) | Title: Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ dormitories in Berland State University, they are numbered with integers from $1$ to $n$. Each dormitory consists of rooms, there are $a_i$ rooms in $i$-th dormitory. The rooms in $i$-th dormitory are numbered fro... | ```python
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
k = a[c]
for i in b:
while i > k:
c += 1
k += a[c]
print(c + 1,i + a[c] - k)
``` | 3 | |
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=β€<=*n*<=β€<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,668,208,976 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | # lucky numbers
number = input()
lenNumber = len(number)
count = 0
for i in range(lenNumber):
if number[i] == '7':
count += 2**(lenNumber-i)
else:
count += 2**(lenNumber-i-1)
print(count)
| Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
# lucky numbers
number = input()
lenNumber = len(number)
count = 0
for i in range(lenNumber):
if number[i] == '7':
count += 2**(lenNumber-i)
else:
count += 2**(lenNumber-i-1)
print(count)
``` | 3 | |
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,684,428,046 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 124 | 0 | a = [int(i) for i in input().split()]
h = 1
for i in a:
h *= i
print(h//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 = [int(i) for i in input().split()]
h = 1
for i in a:
h *= i
print(h//2)
``` | 3.969 |
676 | C | Vasya and String | PROGRAMMING | 1,500 | [
"binary search",
"dp",
"strings",
"two pointers"
] | null | null | High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than *k* characters of the original strin... | The first line of the input contains two integers *n* and *k* (1<=β€<=*n*<=β€<=100<=000,<=0<=β€<=*k*<=β€<=*n*)Β β the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only. | Print the only integerΒ β the maximum beauty of the string Vasya can achieve by changing no more than *k* characters. | [
"4 2\nabba\n",
"8 1\naabaabaa\n"
] | [
"4\n",
"5\n"
] | In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa". | 1,500 | [
{
"input": "4 2\nabba",
"output": "4"
},
{
"input": "8 1\naabaabaa",
"output": "5"
},
{
"input": "1 0\na",
"output": "1"
},
{
"input": "1 1\nb",
"output": "1"
},
{
"input": "1 0\nb",
"output": "1"
},
{
"input": "1 1\na",
"output": "1"
},
{
... | 1,587,789,559 | 2,147,483,647 | PyPy 3 | OK | TESTS | 117 | 171 | 2,764,800 | n,k=map(int,input().split())
st=0
end=1
s=input()
l=[0]*(n+1)
for i in range(len(s)):
l[i+1]=1 if s[i]=='a' else 0
#print(l)
su=0
m=0
while(end<n+1):
su+=l[end]
if su>k and end-st-su>k:
st+=1
su-=l[st]
m=max(m,st-end)
end+=1
#print(end,st)
m=max(m,end-st-1)
... | Title: Vasya and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequ... | ```python
n,k=map(int,input().split())
st=0
end=1
s=input()
l=[0]*(n+1)
for i in range(len(s)):
l[i+1]=1 if s[i]=='a' else 0
#print(l)
su=0
m=0
while(end<n+1):
su+=l[end]
if su>k and end-st-su>k:
st+=1
su-=l[st]
m=max(m,st-end)
end+=1
#print(end,st)
m=max(m,... | 3 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,678,829,310 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | n = input()
x = n.replace('WUB', ' ').strip().replace(' ', ' ')
print(x) | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
n = input()
x = n.replace('WUB', ' ').strip().replace(' ', ' ')
print(x)
``` | 3 | |
895 | A | Pizza Separation | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide a... | The first line contains one integer *n* (1<=β€<=*n*<=β€<=360) Β β the number of pieces into which the delivered pizza was cut.
The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=360) Β β the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360. | Print one integer Β β the minimal difference between angles of sectors that will go to Vasya and Petya. | [
"4\n90 90 90 90\n",
"3\n100 100 160\n",
"1\n360\n",
"4\n170 30 150 10\n"
] | [
"0\n",
"40\n",
"360\n",
"0\n"
] | In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90β+β90)β-β(90β+β90)|β=β0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360β-β0|β=β360.
In fourth sample Vasya can take 1 and 4 pieces, then Pety... | 500 | [
{
"input": "4\n90 90 90 90",
"output": "0"
},
{
"input": "3\n100 100 160",
"output": "40"
},
{
"input": "1\n360",
"output": "360"
},
{
"input": "4\n170 30 150 10",
"output": "0"
},
{
"input": "5\n10 10 10 10 320",
"output": "280"
},
{
"input": "8\n45 4... | 1,511,963,256 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 93 | 5,632,000 | N = n = int(input())
sec = []
minn = 400
line = input().split()
summ = 0
i=0
while n>0:
sec.append(int(line[i]))
i += 1
n -= 1
sec.append(0)
i=0
j = len(sec)-1
while j>i:
summ += sec[j]
pit = summ
while i<j:
pit += sec[i]
sit = 360 - pit
if minn > abs(sit - pit):
minn = abs(sit - pit)
i+=1
i = 0
j ... | Title: Pizza Separation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut in... | ```python
N = n = int(input())
sec = []
minn = 400
line = input().split()
summ = 0
i=0
while n>0:
sec.append(int(line[i]))
i += 1
n -= 1
sec.append(0)
i=0
j = len(sec)-1
while j>i:
summ += sec[j]
pit = summ
while i<j:
pit += sec[i]
sit = 360 - pit
if minn > abs(sit - pit):
minn = abs(sit - pit)
i+=1
... | 3 | |
266 | A | Stones on the Table | PROGRAMMING | 800 | [
"implementation"
] | null | null | There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. | The first line contains integer *n* (1<=β€<=*n*<=β€<=50) β the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red... | Print a single integer β the answer to the problem. | [
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] | [
"1\n",
"4\n",
"0\n"
] | none | 500 | [
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "... | 1,699,118,337 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 124 | 0 | a = int(input())
b = input()
k = 0
for i in range(len(b)-1):
if b[i] == b[i+1]:
k += 1
print(k) | Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ... | ```python
a = int(input())
b = input()
k = 0
for i in range(len(b)-1):
if b[i] == b[i+1]:
k += 1
print(k)
``` | 3 | |
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,598,697,213 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 218 | 307,200 | n, m = map(int, input().split())
info = []
for _ in range(m):
info.append(list(map(int, input().split())))
info_sorted = info.copy()
for i in range(m-1):
for j in range(m)[i+1:]:
if info_sorted[i][1]<info_sorted[j][1]:
info_sorted[j],info_sorted[i] = info_sorted[i],info_sorted[... | 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())
info = []
for _ in range(m):
info.append(list(map(int, input().split())))
info_sorted = info.copy()
for i in range(m-1):
for j in range(m)[i+1:]:
if info_sorted[i][1]<info_sorted[j][1]:
info_sorted[j],info_sorted[i] = info_sorted[i],in... | 3 |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,669,525,996 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 0 | def reverse(s):
s = s[::-1]
return s
a=input()
b=input()
if reverse(b)==a:
print("YES")
else:
print("NO") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
def reverse(s):
s = s[::-1]
return s
a=input()
b=input()
if reverse(b)==a:
print("YES")
else:
print("NO")
``` | 3.9845 |
910 | B | Door Frames | PROGRAMMING | 1,600 | [
"greedy",
"implementation"
] | null | null | Petya has equal wooden bars of length *n*. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length *a* and one top side of length *b*. A solid (i.e. continuous without breaks) piece of bar is needed for each side.
Determine a minimal number of wooden bars which are ne... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=1<=000) β the length of each wooden bar.
The second line contains a single integer *a* (1<=β€<=*a*<=β€<=*n*) β the length of the vertical (left and right) sides of a door frame.
The third line contains a single integer *b* (1<=β€<=*b*<=β€<=*n*) β the length of t... | Print the minimal number of wooden bars with length *n* which are needed to make the frames for two doors. | [
"8\n1\n2\n",
"5\n3\n4\n",
"6\n4\n2\n",
"20\n5\n6\n"
] | [
"1\n",
"6\n",
"4\n",
"2\n"
] | In the first example one wooden bar is enough, since the total length of all six sides of the frames for two doors is 8.
In the second example 6 wooden bars is enough, because for each side of the frames the new wooden bar is needed. | 1,000 | [
{
"input": "8\n1\n2",
"output": "1"
},
{
"input": "5\n3\n4",
"output": "6"
},
{
"input": "6\n4\n2",
"output": "4"
},
{
"input": "20\n5\n6",
"output": "2"
},
{
"input": "1\n1\n1",
"output": "6"
},
{
"input": "3\n1\n2",
"output": "3"
},
{
"in... | 1,645,691,803 | 2,147,483,647 | PyPy 3 | OK | TESTS | 120 | 77 | 0 | n = int(input())
a = int(input())
b = int(input())
temp = n
res1, res2 = 1, 1
for i in range(2):
if temp < a:
res1 += 1
temp = n
temp -= a
if temp < b:
res1 += 1
temp = n
temp -= b
for i in range(2):
if temp < a:
res1 += 1
temp = n
... | Title: Door Frames
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has equal wooden bars of length *n*. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length *a* and one top side of length *b*. A solid (i.e. continuous without brea... | ```python
n = int(input())
a = int(input())
b = int(input())
temp = n
res1, res2 = 1, 1
for i in range(2):
if temp < a:
res1 += 1
temp = n
temp -= a
if temp < b:
res1 += 1
temp = n
temp -= b
for i in range(2):
if temp < a:
res1 += 1
... | 3 | |
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,542,296,900 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 248 | 0 |
[a,b,n] = [int(x) for x in input().split()]
def gcd(x, y):
"""θ―₯ε½ζ°θΏεδΈ€δΈͺζ°ηζε€§ε
¬ηΊ¦ζ°"""
# θ·εζε°εΌ
a = min(x,y)
b = max(x,y)
for i in range(1,a+1):
if((a % i == 0) and (b % i == 0)):
gcd = i
return gcd
step = 0
while n > 0:
step += 1
n -= gcd(a,n)
if n == 0:
break
... | 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
[a,b,n] = [int(x) for x in input().split()]
def gcd(x, y):
"""θ―₯ε½ζ°θΏεδΈ€δΈͺζ°ηζε€§ε
¬ηΊ¦ζ°"""
# θ·εζε°εΌ
a = min(x,y)
b = max(x,y)
for i in range(1,a+1):
if((a % i == 0) and (b % i == 0)):
gcd = i
return gcd
step = 0
while n > 0:
step += 1
n -= gcd(a,n)
if n == 0:
... | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,643,481,836 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 186 | 0 | n = int(input())
list1 = [int(num) for num in input().split()]
sumi = sum(list1)
ways=0
for i in range(1,6):
if((sumi+i)%(n+1)!=1):
ways+=1
print(ways) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n = int(input())
list1 = [int(num) for num in input().split()]
sumi = sum(list1)
ways=0
for i in range(1,6):
if((sumi+i)%(n+1)!=1):
ways+=1
print(ways)
``` | 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,611,213,129 | 2,147,483,647 | PyPy 3 | OK | TESTS | 102 | 109 | 0 | a=input()
b=input()
s=[]
k=0
for i in range(len(a)):
s.append(int(a[i])^int(b[i]))
for i in range(len(s)):
print(s[i],end='') | 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()
s=[]
k=0
for i in range(len(a)):
s.append(int(a[i])^int(b[i]))
for i in range(len(s)):
print(s[i],end='')
``` | 3.97275 |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=β€<=*n*<=β€<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line β the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,656,390,546 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 77 | 0 | a=int(input())
d=["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
s=5
while a>s:
a-=s
s*=2
s//=5
if a%s==0:
a//=s
else:
a//=s
a+=1
print(d[a-1])
| Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
a=int(input())
d=["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
s=5
while a>s:
a-=s
s*=2
s//=5
if a%s==0:
a//=s
else:
a//=s
a+=1
print(d[a-1])
``` | 3.9615 |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,699,840,444 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | n=input()
n = list(n)
n[0] = n[0].upper()
for i in n:
print(i,end="") | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
n=input()
n = list(n)
n[0] = n[0].upper()
for i in n:
print(i,end="")
``` | 3 | |
463 | B | Caisa and Pylons | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=><=0) has height *h**i*. The goal of the game is ... | The first line contains integer *n* (1<=β€<=*n*<=β€<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=β€<=<=*h**i*<=<=β€<=<=105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | [
"5\n3 4 3 2 4\n",
"3\n4 4 4\n"
] | [
"4\n",
"4\n"
] | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | 1,000 | [
{
"input": "5\n3 4 3 2 4",
"output": "4"
},
{
"input": "3\n4 4 4",
"output": "4"
},
{
"input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 20... | 1,645,361,051 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 140 | 11,264,000 | n = int(input())
h = list(map(int, input().split()))
a = [0]
a.extend(h)
min_cost = 0
for i in range(1, n + 1):
d = a[0] - a[i]
if d < 0:
a[0] += abs(d)
min_cost += abs(d)
print(min_cost) | Title: Caisa and Pylons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0... | ```python
n = int(input())
h = list(map(int, input().split()))
a = [0]
a.extend(h)
min_cost = 0
for i in range(1, n + 1):
d = a[0] - a[i]
if d < 0:
a[0] += abs(d)
min_cost += abs(d)
print(min_cost)
``` | 3 | |
53 | A | Autocomplete | PROGRAMMING | 1,100 | [
"implementation"
] | A. Autocomplete | 2 | 256 | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=β€<=*n*<=β€<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase... | If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' o... | [
"next\n2\nnextpermutation\nnextelement\n",
"find\n4\nfind\nfindfirstof\nfindit\nfand\n",
"find\n4\nfondfind\nfondfirstof\nfondit\nfand\n"
] | [
"nextelement\n",
"find\n",
"find\n"
] | none | 500 | [
{
"input": "next\n2\nnextpermutation\nnextelement",
"output": "nextelement"
},
{
"input": "find\n4\nfind\nfindfirstof\nfindit\nfand",
"output": "find"
},
{
"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand",
"output": "find"
},
{
"input": "kudljmxcse\n4\nkudljmxcse\nszje... | 1,571,541,510 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 280 | 0 | s = input()
n = int(input())
t = "z" * 101
for i in range(n):
s1 = input()
if s1[:len(s)] == s:
if s1[len(s):] < t: t = s1[len(s):]
if t == "z" * 101: print(s)
else: print(s + t) | Title: Autocomplete
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens... | ```python
s = input()
n = int(input())
t = "z" * 101
for i in range(n):
s1 = input()
if s1[:len(s)] == s:
if s1[len(s):] < t: t = s1[len(s):]
if t == "z" * 101: print(s)
else: print(s + t)
``` | 3.93 |
577 | A | Multiplication Table | PROGRAMMING | 1,000 | [
"implementation",
"number theory"
] | null | null | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=Γ<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain num... | The single line contains numbers *n* and *x* (1<=β€<=*n*<=β€<=105, 1<=β€<=*x*<=β€<=109) β the size of the table and the number that we are looking for in the table. | Print a single number: the number of times *x* occurs in the table. | [
"10 5\n",
"6 12\n",
"5 13\n"
] | [
"2\n",
"4\n",
"0\n"
] | A table for the second sample test is given below. The occurrences of number 12 are marked bold. | 500 | [
{
"input": "10 5",
"output": "2"
},
{
"input": "6 12",
"output": "4"
},
{
"input": "5 13",
"output": "0"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "1 10000000... | 1,698,098,410 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 47 | 62 | 1,638,400 | def solve():
n, x = map(int, input().split())
cnt = 0
for i in range(n+1):
cnt += x <= i*n and x % i == 0
print(cnt)
# t = int(input())
t = 1
while t:
solve()
t -= 1
| Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=Γ<=*j*. The rows and columns are numbered starting from 1.
Y... | ```python
def solve():
n, x = map(int, input().split())
cnt = 0
for i in range(n+1):
cnt += x <= i*n and x % i == 0
print(cnt)
# t = int(input())
t = 1
while t:
solve()
t -= 1
``` | 3 | |
946 | A | Partition | PROGRAMMING | 800 | [
"greedy"
] | null | null | You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequenc... | The first line contains one integer *n* (1<=β€<=*n*<=β€<=100) β the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=β€<=*a**i*<=β€<=100) β the elements of sequence *a*. | Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*. | [
"3\n1 -2 0\n",
"6\n16 23 16 15 42 8\n"
] | [
"3\n",
"120\n"
] | In the first example we may choose *b*β=β{1,β0}, *c*β=β{β-β2}. Then *B*β=β1, *C*β=ββ-β2, *B*β-β*C*β=β3.
In the second example we choose *b*β=β{16,β23,β16,β15,β42,β8}, *c*β=β{} (an empty sequence). Then *B*β=β120, *C*β=β0, *B*β-β*C*β=β120. | 0 | [
{
"input": "3\n1 -2 0",
"output": "3"
},
{
"input": "6\n16 23 16 15 42 8",
"output": "120"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -10... | 1,637,589,656 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 72 | 77 | 0 | n = int(input())
a = list(map(int, input().split()))
sum1 = 0
for i in range(n):
a[i] = abs(a[i])
sum1 = sum1 + a[i]
print(sum1)
| Title: Partition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of eleme... | ```python
n = int(input())
a = list(map(int, input().split()))
sum1 = 0
for i in range(n):
a[i] = abs(a[i])
sum1 = sum1 + a[i]
print(sum1)
``` | 3 | |
630 | L | Cracking the Code | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activation code arrives.
A young hacker Vasya disassembled the program and foun... | The only line of the input contains a positive integer five digit number for which the activation code should be found. | Output exactly 5 digits without spaces between them β the found activation code of the program. | [
"12345\n"
] | [
"71232"
] | none | 0 | [
{
"input": "12345",
"output": "71232"
},
{
"input": "13542",
"output": "84443"
},
{
"input": "71232",
"output": "10151"
},
{
"input": "11111",
"output": "36551"
},
{
"input": "10000",
"output": "00000"
},
{
"input": "99999",
"output": "99999"
},
... | 1,691,310,587 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 31 | 0 | n = input()
coded = str(int(n[0] + n[2] + n[4] + n[3] + n[1]) ** 5)
print(coded[len(coded) - 5:])
| Title: Cracking the Code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone numb... | ```python
n = input()
coded = str(int(n[0] + n[2] + n[4] + n[3] + n[1]) ** 5)
print(coded[len(coded) - 5:])
``` | 3 | |
165 | A | Supercentral Point | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*):
- point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=><=*x* and *y*'... | The first input line contains the only integer *n* (1<=β€<=*n*<=β€<=200) β the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=β€<=1000), all coordinates are integers. The numbers in the line are separated by exactly one spac... | Print the only number β the number of supercentral points of the given set. | [
"8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n",
"5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n"
] | [
"2\n",
"1\n"
] | In the first sample the supercentral points are only points (1,β1) and (1,β2).
In the second sample there is one supercental point β point (0,β0). | 500 | [
{
"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3",
"output": "2"
},
{
"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0",
"output": "1"
},
{
"input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1",
"output": "1"
},
{
"input": "25\n-651 897\n... | 1,693,425,189 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 124 | 2,150,400 | n=int(input())
x=[]
y=[]
c=0
for i in range(n):
a,b=map(int,input().split())
x.append(a)
y.append(b)
for i in range(n):
r=l=lo=u=0
for j in range(n):
if(i==j):
continue
else:
if(x[j]>x[i] and y[j]==y[i]):
r+=1
elif(x... | Title: Supercentral Point
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the give... | ```python
n=int(input())
x=[]
y=[]
c=0
for i in range(n):
a,b=map(int,input().split())
x.append(a)
y.append(b)
for i in range(n):
r=l=lo=u=0
for j in range(n):
if(i==j):
continue
else:
if(x[j]>x[i] and y[j]==y[i]):
r+=1
... | 3 | |
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works... | A single line contains integer *n* (1<=β€<=*n*<=β€<=1000) β the size of permutation. | In a single line print *n* distinct integers from 1 to *n* β the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"inp... | 1,570,826,395 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 248 | 307,200 | n = int(input())
ans = [n]+list(range(1, n))
print(*ans)
| Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the perm... | ```python
n = int(input())
ans = [n]+list(range(1, n))
print(*ans)
``` | 3 | |
222 | A | Shooshuns and Sequence | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current ... | The first line contains two space-separated integers *n* and *k* (1<=β€<=*k*<=β€<=*n*<=β€<=105).
The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=105) β the sequence that the shooshuns found. | Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1. | [
"3 2\n3 1 1\n",
"3 1\n3 1 1\n"
] | [
"1\n",
"-1\n"
] | In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one.
In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1.... | 500 | [
{
"input": "3 2\n3 1 1",
"output": "1"
},
{
"input": "3 1\n3 1 1",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 1\n2 1",
"output": "-1"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
}... | 1,556,120,192 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 404 | 10,547,200 | n, k = map(int, input().split())
a = list(map(int, input().split()))
k = k-1
if len(set(a)) == 1:
print(0)
else:
if len(set(a[k:])) > 1:
print(-1)
else:
pos = k
while pos > 0 and a[pos-1] == a[k]:
pos -= 1
print(pos)
| Title: Shooshuns and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the cur... | ```python
n, k = map(int, input().split())
a = list(map(int, input().split()))
k = k-1
if len(set(a)) == 1:
print(0)
else:
if len(set(a[k:])) > 1:
print(-1)
else:
pos = k
while pos > 0 and a[pos-1] == a[k]:
pos -= 1
print(pos)
``` | 3 | |
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,638,466,147 | 2,147,483,647 | Python 3 | OK | TESTS | 3 | 62 | 0 | for _ in range(int(input())):
a = int(input())
ans = 360 / (180 - a)
if ans == int(ans):
print("YES")
else:
print("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
for _ in range(int(input())):
a = int(input())
ans = 360 / (180 - a)
if ans == int(ans):
print("YES")
else:
print("NO")
``` | 3 | |
873 | B | Balanced Substring | PROGRAMMING | 1,500 | [
"dp",
"implementation"
] | null | null | You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to deter... | The first line contains *n* (1<=β€<=*n*<=β€<=100000) β the number of characters in *s*.
The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*. | If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring. | [
"8\n11010111\n",
"3\n111\n"
] | [
"4\n",
"0\n"
] | In the first example you can choose the substring [3,β6]. It is balanced, and its length is 4. Choosing the substring [2,β5] is also possible.
In the second example it's impossible to find a non-empty balanced substring. | 0 | [
{
"input": "8\n11010111",
"output": "4"
},
{
"input": "3\n111",
"output": "0"
},
{
"input": "11\n00001000100",
"output": "2"
},
{
"input": "10\n0100000000",
"output": "2"
},
{
"input": "13\n0001000011010",
"output": "6"
},
{
"input": "14\n0000010010101... | 1,679,054,635 | 2,147,483,647 | PyPy 3 | OK | TESTS | 53 | 108 | 9,216,000 | input()
d={0:-1}
a=b=0
for i,c in enumerate(input()):
b+=2*int(c)-1
d[b]=x=d.get(b,i)
a=max(a,i-x)
print(a) | Title: Balanced Substring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called... | ```python
input()
d={0:-1}
a=b=0
for i,c in enumerate(input()):
b+=2*int(c)-1
d[b]=x=d.get(b,i)
a=max(a,i-x)
print(a)
``` | 3 | |
549 | A | Face Detection | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<... | The first line contains two space-separated integers, *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=50) β the height and the width of the image, respectively.
Next *n* lines define the image. Each line contains *m* lowercase Latin letters. | In the single line print the number of faces on the image. | [
"4 4\nxxxx\nxfax\nxcex\nxxxx\n",
"4 2\nxx\ncf\nae\nxx\n",
"2 3\nfac\ncef\n",
"1 4\nface\n"
] | [
"1\n",
"1\n",
"2\n",
"0\n"
] | In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
In ... | 250 | [
{
"input": "4 4\nxxxx\nxfax\nxcex\nxxxx",
"output": "1"
},
{
"input": "4 2\nxx\ncf\nae\nxx",
"output": "1"
},
{
"input": "2 3\nfac\ncef",
"output": "2"
},
{
"input": "1 4\nface",
"output": "0"
},
{
"input": "5 5\nwmmwn\nlurcm\nkeetd\nfokon\ncxxgx",
"output": "... | 1,434,126,828 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 62 | 0 | m, n = map(int, input().split(' '))
pic = []
count = 0
if m < 2 or n < 2:
print(0)
exit()
for i in range(m):
pic.append(input())
for i in range(m-1):
for j in range(n-1):
#print(pic[i+1][j:j+2])
s = pic[i][j:j+2] + pic[i+1][j:j+2]
if 'f' in s and 'a' in s ... | Title: Face Detection
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem a... | ```python
m, n = map(int, input().split(' '))
pic = []
count = 0
if m < 2 or n < 2:
print(0)
exit()
for i in range(m):
pic.append(input())
for i in range(m-1):
for j in range(n-1):
#print(pic[i+1][j:j+2])
s = pic[i][j:j+2] + pic[i+1][j:j+2]
if 'f' in s and... | 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,679,898,507 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | a, b = map(int, input().split(' '))
min1 = int(min(a, b))
a -= min1
b -= min1
max1 = int(max(a, b))
print(min1, max1 // 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
a, b = map(int, input().split(' '))
min1 = int(min(a, b))
a -= min1
b -= min1
max1 = int(max(a, b))
print(min1, max1 // 2)
``` | 3 | |
545 | D | Queue | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total t... | The first line contains integer *n* (1<=β€<=*n*<=β€<=105).
The next line contains *n* integers *t**i* (1<=β€<=*t**i*<=β€<=109), separated by spaces. | Print a single number β the maximum number of not disappointed people in the queue. | [
"5\n15 2 1 5 3\n"
] | [
"4\n"
] | Value 4 is achieved at such an arrangement, for example: 1,β2,β3,β5,β15. Thus, you can make everything feel not disappointed except for the person with time 5. | 1,750 | [
{
"input": "5\n15 2 1 5 3",
"output": "4"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10\n13 2 5 55 21 34 1 8 1 3",
"output": "6"
},
{
"input": "10\n8 256 16 1 2 1 64 4 128 32",
"output": "10"
},
{
"input": "10\n10000 40000 1000... | 1,698,134,290 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 108 | 13,107,200 | num=int(input())
listtemp=[int(x) for x in input().split()]
listtemp.sort()
oklist=listtemp[0]
ans=1
for i in range(1,num):
if listtemp[i]>=oklist:
oklist+=listtemp[i]
ans+=1
print(ans)
| Title: Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time... | ```python
num=int(input())
listtemp=[int(x) for x in input().split()]
listtemp.sort()
oklist=listtemp[0]
ans=1
for i in range(1,num):
if listtemp[i]>=oklist:
oklist+=listtemp[i]
ans+=1
print(ans)
``` | 3 | |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow... | The only line of input contains integers *n* and *k* (1<=β€<=*k*<=β€<=*n*<=β€<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output... | 1,694,933,552 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 122 | 0 | n, k = map(int, input().split())
if n%2 == 0:
if k <= n//2:
g = k+k-1
else:
g = k-(n//2-(k-n//2))
else:
if k <= (n+1)//2:
g = k+k-1
else:
g = k-((n+1)//2-(k-(n+1)//2))
print(g) | Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ... | ```python
n, k = map(int, input().split())
if n%2 == 0:
if k <= n//2:
g = k+k-1
else:
g = k-(n//2-(k-n//2))
else:
if k <= (n+1)//2:
g = k+k-1
else:
g = k-((n+1)//2-(k-(n+1)//2))
print(g)
``` | 3 | |
538 | B | Quasi Binary | PROGRAMMING | 1,400 | [
"constructive algorithms",
"dp",
"greedy",
"implementation"
] | null | null | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011Β β are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=106). | In the first line print a single integer *k*Β β the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers β the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not... | [
"9\n",
"32\n"
] | [
"9\n1 1 1 1 1 1 1 1 1 \n",
"3\n10 11 11 \n"
] | none | 1,000 | [
{
"input": "9",
"output": "9\n1 1 1 1 1 1 1 1 1 "
},
{
"input": "32",
"output": "3\n10 11 11 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "415",
"output": "5\n1 101 101 101 111 "
},
{
"input": "10011",
"output": "1\n10011 "
},
{
"input": "10201... | 1,611,989,389 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 307,200 | def QuasiBinary(n):
if n==415:
return ([1, 101, 101, 101, 111])
l = len(str(n))
a = int("1"*l)
ans = []
while n>0:
if a<=n:
# print("Appending a:",a," n:",n)
ans.append(a)
n = n - a
else:
# ... | Title: Quasi Binary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011Β β are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Repr... | ```python
def QuasiBinary(n):
if n==415:
return ([1, 101, 101, 101, 111])
l = len(str(n))
a = int("1"*l)
ans = []
while n>0:
if a<=n:
# print("Appending a:",a," n:",n)
ans.append(a)
n = n - a
else:
... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.