contestId int64 0 1.01k | index stringclasses 57
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 11 | title stringclasses 522
values | time-limit stringclasses 8
values | memory-limit stringclasses 8
values | problem-description stringlengths 0 7.15k | input-specification stringlengths 0 2.05k | output-specification stringlengths 0 1.5k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 425k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 14
values | testset stringclasses 12
values | passedTestCount int64 0 1k | timeConsumedMillis int64 0 15k | memoryConsumedBytes int64 0 805M | code stringlengths 3 65.5k | prompt stringlengths 262 8.2k | response stringlengths 17 65.5k | score float64 -1 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
235 | A | LCM Challenge | PROGRAMMING | 1,600 | [
"number theory"
] | null | null | Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement. | Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*. | [
"9\n",
"7\n"
] | [
"504\n",
"210\n"
] | The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is ... | 500 | [
{
"input": "9",
"output": "504"
},
{
"input": "7",
"output": "210"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "60"
},
{
"input": "33",
"output": "32736"
},
{
"input": "21",
"output": ... | 1,487,444,467 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 184 | 4,608,000 | #Allah is the most gracious and the Most Marchiful
m=int(input())
if(m==1):
print("1")
elif(m==2):
print("2")
elif(m%2==0):
ans=0
for i in range(2,m,1):
if((m-i)%i==0):
ans=max(ans,m*(m-1)*(m-i)/i)
else:
ans = max(ans, m * (m - 1) * (m - i) )
print(ma... | Title: LCM Challenge
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive... | ```python
#Allah is the most gracious and the Most Marchiful
m=int(input())
if(m==1):
print("1")
elif(m==2):
print("2")
elif(m%2==0):
ans=0
for i in range(2,m,1):
if((m-i)%i==0):
ans=max(ans,m*(m-1)*(m-i)/i)
else:
ans = max(ans, m * (m - 1) * (m - i) )
... | 0 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,594,141,939 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 218 | 6,963,200 |
s = input()
t = input()
word = []
word1 = []
word_rev = []
for letter in s:
word.append(letter)
for letter in t:
word_rev.append(letter)
for i in range(len(word)):
word1.append(word.pop())
same = True
if len(word1) != len(word_rev):
same = False
for i in range(len(word1)):
#prin... | 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
s = input()
t = input()
word = []
word1 = []
word_rev = []
for letter in s:
word.append(letter)
for letter in t:
word_rev.append(letter)
for i in range(len(word)):
word1.append(word.pop())
same = True
if len(word1) != len(word_rev):
same = False
for i in range(len(word1)... | -1 |
294 | A | Shaass and Oskols | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*... | The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100).
The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i... | On the *i*-th line of the output print the number of birds on the *i*-th wire. | [
"5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n",
"3\n2 4 1\n1\n2 2\n"
] | [
"0\n12\n5\n0\n16\n",
"3\n0\n3\n"
] | none | 500 | [
{
"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6",
"output": "0\n12\n5\n0\n16"
},
{
"input": "3\n2 4 1\n1\n2 2",
"output": "3\n0\n3"
},
{
"input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43",
"output": "0\n66\n57\n7\n0"
},
{
"input": "10\n48 53 10 28 91 56 8... | 1,543,395,767 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 248 | 0 | n = int(input())
a = list(map(int, input().split()))
shots = int(input())
for i in range(shots):
wire, oskol = map(int, input().split())
# index 0
if wire == 1:
if wire == len(a):
a[wire-1] = 0
else:
a[1] += a[0] - oskol
a[0] = 0
else:
... | Title: Shaass and Oskols
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each... | ```python
n = int(input())
a = list(map(int, input().split()))
shots = int(input())
for i in range(shots):
wire, oskol = map(int, input().split())
# index 0
if wire == 1:
if wire == len(a):
a[wire-1] = 0
else:
a[1] += a[0] - oskol
a[0] = 0
... | 3 | |
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s... | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indi... | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGB... | 1,518,115,342 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 5,632,000 | n=int(input())
ch="ROYGBIV"
res=ch*(n//7)+ch[:n%7]
print(res) | Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
-... | ```python
n=int(input())
ch="ROYGBIV"
res=ch*(n//7)+ch[:n%7]
print(res)
``` | 0 |
907 | A | Masha and Bears | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg... | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 500 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"... | 1,514,041,160 | 3,260 | Python 3 | OK | TESTS | 32 | 62 | 5,529,600 | v1,v2,v3,vm=map(int,input().split())
if vm>2*v3:
print(-1)
elif 2*vm<v3:
print(-1)
else:
if (2*vm<2*v2):
print(2*v1)
print(2*v2)
print(max(v3,vm))
else:
print(-1)
... | Title: Masha and Bears
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son b... | ```python
v1,v2,v3,vm=map(int,input().split())
if vm>2*v3:
print(-1)
elif 2*vm<v3:
print(-1)
else:
if (2*vm<2*v2):
print(2*v1)
print(2*v2)
print(max(v3,vm))
else:
print(-1)
... | 3 | |
629 | B | Far Relative’s Problem | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible.
Far cars are as weird as... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — then number of Famil Door's friends.
Then follow *n* lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers *a**i* and *b**i... | Print the maximum number of people that may come to Famil Door's party. | [
"4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n",
"6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n"
] | [
"2\n",
"4\n"
] | In the first sample, friends 3 and 4 can come on any day in range [117, 128].
In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140. | 1,000 | [
{
"input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128",
"output": "2"
},
{
"input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200",
"output": "4"
},
{
"input": "1\nF 68 307",
"output": "0"
},
{
"input": "40\nM 55 363\nF 117 252\nM 157 282\nF 322 345\... | 1,689,339,915 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689339915.149648")# 1689339915.149695 | Title: Far Relative’s Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, F... | ```python
print("_RANDOM_GUESS_1689339915.149648")# 1689339915.149695
``` | 0 | |
825 | B | Five-In-a-Row | PROGRAMMING | 1,600 | [
"brute force",
"implementation"
] | null | null | Alice and Bob play 5-in-a-row game. They have a playing field of size 10<=×<=10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins i... | You are given matrix 10<=×<=10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell.
It is guaranteed th... | Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. | [
"XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n",
"XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "O.......O.\n.....O.X..\n......O...\n....X.O...\n.O.O.....X\n.XO.....XX\n...X...X.O\n........O.\n........O.\n.X.X.....X",
"output": "NO"
},
{
"input": "....OX....\n..........\n.O..X...X.\nXXO..XO..O\nO.......X.\n...XX.....\n..O.O...OX\n.........X\n.....X..OO\n........O.",
"output": "N... | 1,690,188,034 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 156 | 62 | 0 | x=[]
biao=0
for i in range(10):
y=list(input())
x.append(y)
for i in range(10):
for j in range(6):
if x[i][j]=="X" or x[i][j]==".":
z=[]
for k in range(5):
z.append(x[i][j+k])
if z.count("X")==4 and z.count("O")==0:
biao... | Title: Five-In-a-Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice and Bob play 5-in-a-row game. They have a playing field of size 10<=×<=10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some t... | ```python
x=[]
biao=0
for i in range(10):
y=list(input())
x.append(y)
for i in range(10):
for j in range(6):
if x[i][j]=="X" or x[i][j]==".":
z=[]
for k in range(5):
z.append(x[i][j+k])
if z.count("X")==4 and z.count("O")==0:
... | 3 | |
807 | A | Is it rated? | PROGRAMMING | 900 | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order... | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som... | 500 | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
... | 1,494,515,246 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | a=int(input())
f=[]
#print(f)
s=list(map(int,input().split()))
if s[0]!=s[1]:
print('rated')
else:
f+=[s[0]]
#print(f)
#print(min(f))
for i in range(a-1):
s=list(map(int,input().split()))
# print(s)
if s[0]!=s[1]:
print('rated')
break
else:
if s[0]>min(f):
print('unrated')
break
else:
f+=[s[0]]
... | Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number ... | ```python
a=int(input())
f=[]
#print(f)
s=list(map(int,input().split()))
if s[0]!=s[1]:
print('rated')
else:
f+=[s[0]]
#print(f)
#print(min(f))
for i in range(a-1):
s=list(map(int,input().split()))
# print(s)
if s[0]!=s[1]:
print('rated')
break
else:
if s[0]>min(f):
print('unrated')
break
else:
f+... | 0 | |
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ... | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\... | 1,481,041,907 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 61 | 4,608,000 | n=int(input())
l=[int(i) for i in input().split()]
l.sort()
le=len(l)
a=0
i=0
while i<le-1:
a+=sum(l)
a=a+l[i]
l[i]=0
i+=1
a+=l[0]
print(a)
| Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all... | ```python
n=int(input())
l=[int(i) for i in input().split()]
l.sort()
le=len(l)
a=0
i=0
while i<le-1:
a+=sum(l)
a=a+l[i]
l[i]=0
i+=1
a+=l[0]
print(a)
``` | 0 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,692,904,711 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | def can_divide_watermelon(weight):
if weight % 2 == 0 and weight > 2:
return "YES"
else:
return "NO"
# Read input
w = int(input())
# Check if they can divide the watermelon as per the conditions
result = can_divide_watermelon(w)
# Print the result
print(result) | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
def can_divide_watermelon(weight):
if weight % 2 == 0 and weight > 2:
return "YES"
else:
return "NO"
# Read input
w = int(input())
# Check if they can divide the watermelon as per the conditions
result = can_divide_watermelon(w)
# Print the result
print(result)
``` | 3.954 |
899 | A | Splitting in Teams | PROGRAMMING | 800 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of tea... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*. | Print the maximum number of teams of three people the coach can form. | [
"4\n1 1 2 1\n",
"2\n2 2\n",
"7\n2 2 2 1 1 1 1\n",
"3\n1 1 1\n"
] | [
"1\n",
"0\n",
"3\n",
"1\n"
] | In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) an... | 500 | [
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "0"
},
{
"input": "7\n2 2 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 2 1",
"output": "1"
}... | 1,596,300,039 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 140 | 20,172,800 | n=int(input())
ones=0
twos=0
team=0
ar=list(map(int,input().split()))
for i in ar:
if i==1:
ones+=1
if ones==3:
team+=1
ones=0
else:
twos+=1
teams=team+min(ones,twos)
print(teams) | Title: Splitting in Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The co... | ```python
n=int(input())
ones=0
twos=0
team=0
ar=list(map(int,input().split()))
for i in ar:
if i==1:
ones+=1
if ones==3:
team+=1
ones=0
else:
twos+=1
teams=team+min(ones,twos)
print(teams)
``` | 0 | |
108 | A | Palindromic Times | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | A. Palindromic Times | 2 | 256 | Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on th... | The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits. | Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time. | [
"12:21\n",
"23:59\n"
] | [
"13:31\n",
"00:00\n"
] | none | 500 | [
{
"input": "12:21",
"output": "13:31"
},
{
"input": "23:59",
"output": "00:00"
},
{
"input": "15:51",
"output": "20:02"
},
{
"input": "10:44",
"output": "11:11"
},
{
"input": "04:02",
"output": "04:40"
},
{
"input": "02:11",
"output": "02:20"
},
... | 1,487,784,220 | 520 | Python 3 | OK | TESTS | 36 | 124 | 4,608,000 |
def next(h, m):
m += 1
if m == 60:
m = 0
h += 1
if h == 24:
h = 0
return (h, m)
a, b = map(int, input().split(':'))
found = False
result = None
while not found:
a, b = next(a, b)
a_pa, b_pa = '0'*(2 - len(str(a))) + str(a), '0'*(2 - len(str(b))) + str(b)
if a_pa ... | Title: Palindromic Times
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling... | ```python
def next(h, m):
m += 1
if m == 60:
m = 0
h += 1
if h == 24:
h = 0
return (h, m)
a, b = map(int, input().split(':'))
found = False
result = None
while not found:
a, b = next(a, b)
a_pa, b_pa = '0'*(2 - len(str(a))) + str(a), '0'*(2 - len(str(b))) + str(b)
... | 3.960417 |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co... | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"ou... | 1,592,197,271 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | n=int(input())
for i in range(1,n):
for j in range(1,n):
if i+j==n and i<j:
print(i ,j)
exit(0)
| Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is cal... | ```python
n=int(input())
for i in range(1,n):
for j in range(1,n):
if i+j==n and i<j:
print(i ,j)
exit(0)
``` | 0 | |
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,697,012,673 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | mat = [list(map(int, input().split())) for i in range(5)]
def find_one(mat):
for i in range(5):
for j in range(5):
if mat[i][j]==1:
point=(i,j)
return point
def find_the_minimum_path(mat):
point= find_one(mat)
return abs(point[0] - 2) + abs(point[1] - 2)
pr... | 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
mat = [list(map(int, input().split())) for i in range(5)]
def find_one(mat):
for i in range(5):
for j in range(5):
if mat[i][j]==1:
point=(i,j)
return point
def find_the_minimum_path(mat):
point= find_one(mat)
return abs(point[0] - 2) + abs(point[... | 3 | |
448 | A | Rewards | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize c... | The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100).
The numbers in the lines are separated by single spaces. | Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes). | [
"1 1 1\n1 1 1\n4\n",
"1 1 3\n2 3 4\n2\n",
"1 0 0\n1 0 0\n1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "1 1 1\n1 1 1\n4",
"output": "YES"
},
{
"input": "1 1 3\n2 3 4\n2",
"output": "YES"
},
{
"input": "1 0 0\n1 0 0\n1",
"output": "NO"
},
{
"input": "0 0 0\n0 0 0\n1",
"output": "YES"
},
{
"input": "100 100 100\n100 100 100\n100",
"output": "YES"
},
... | 1,630,667,049 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 6,963,200 | a = sum(list(map(int,input().split())))
b = sum(list(map(int, input().split())))
c = int(input())
while True:
if a < 6:
c-=1
break
else:
a-=5
c-=1
while True:
if b < 11:
c-=1
break
else:
b-=10
c-=1
if c>=0:print("YES")
els... | Title: Rewards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into ... | ```python
a = sum(list(map(int,input().split())))
b = sum(list(map(int, input().split())))
c = int(input())
while True:
if a < 6:
c-=1
break
else:
a-=5
c-=1
while True:
if b < 11:
c-=1
break
else:
b-=10
c-=1
if c>=0:print("... | 0 | |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara... | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ... | 1,696,218,176 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 3,584,000 | n , t = map(int,input().split())
a = list(map(int,input().split()))
m = 1
while True :
if m < t :
m+=a[m-1]
elif m == t :
print("YES")
break
else :
print("NO")
break | Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o... | ```python
n , t = map(int,input().split())
a = list(map(int,input().split()))
m = 1
while True :
if m < t :
m+=a[m-1]
elif m == t :
print("YES")
break
else :
print("NO")
break
``` | 3 | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,673,459,880 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 436 | 0 | n=int(input())
inp=input()
c=0
score=list(map(int,inp.split(" ")))
for i in range(1,n):
flag=0
for j in range(i):
if score[j]<=score[i]:
flag=1
if flag==0:
c+=1
for i in range(1,n):
flag=0
for j in range(i):
if score[j]>=score[i]:
... | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n=int(input())
inp=input()
c=0
score=list(map(int,inp.split(" ")))
for i in range(1,n):
flag=0
for j in range(i):
if score[j]<=score[i]:
flag=1
if flag==0:
c+=1
for i in range(1,n):
flag=0
for j in range(i):
if score[j]>=score[i]:
... | 3 | |
633 | B | A Trivial Problem | PROGRAMMING | 1,300 | [
"brute force",
"constructive algorithms",
"math",
"number theory"
] | null | null | Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem? | The only line of input contains an integer *m* (1<=≤<=*m*<=≤<=100<=000) — the required number of trailing zeroes in factorial. | First print *k* — the number of values of *n* such that the factorial of *n* ends with *m* zeroes. Then print these *k* integers in increasing order. | [
"1\n",
"5\n"
] | [
"5\n5 6 7 8 9 ",
"0"
] | The factorial of *n* is equal to the product of all integers from 1 to *n* inclusive, that is *n*! = 1·2·3·...·*n*.
In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880. | 500 | [
{
"input": "1",
"output": "5\n5 6 7 8 9 "
},
{
"input": "5",
"output": "0"
},
{
"input": "2",
"output": "5\n10 11 12 13 14 "
},
{
"input": "3",
"output": "5\n15 16 17 18 19 "
},
{
"input": "7",
"output": "5\n30 31 32 33 34 "
},
{
"input": "12",
"ou... | 1,623,924,214 | 2,147,483,647 | PyPy 3 | OK | TESTS | 68 | 109 | 1,536,000 | n = int(input())
k = 0
i = 1
while k < n:
a = i
while a % 5 == 0 and a != 0:
k = k + 1
a = a / 5
i = i + 1
if k != n:
print(0)
else:
print(5)
print(i - 1, i, i + 1, i + 2, i + 3) | Title: A Trivial Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zer... | ```python
n = int(input())
k = 0
i = 1
while k < n:
a = i
while a % 5 == 0 and a != 0:
k = k + 1
a = a / 5
i = i + 1
if k != n:
print(0)
else:
print(5)
print(i - 1, i, i + 1, i + 2, i + 3)
``` | 3 | |
298 | B | Sail | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will ... | The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the... | If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | [
"5 0 0 1 1\nSESNW\n",
"10 5 3 3 6\nNENSWESNEE\n"
] | [
"4\n",
"-1\n"
] | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | 500 | [
{
"input": "5 0 0 1 1\nSESNW",
"output": "4"
},
{
"input": "10 5 3 3 6\nNENSWESNEE",
"output": "-1"
},
{
"input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS",
"output": "13"
},
{
"input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSS... | 1,628,773,254 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 154 | 20,172,800 | '''input
10 5 3 3 6
NENSWESNEE
'''
t, sx, sy, ex, ey = map(int, input().split())
s = str(input())
dy = ey-sy
dx = ex-sx
N = S = E = W = 0
if dy>=0:
N = dy
else:
S = dy
if dx>=0:
E = dx
else:
W = dx
# print(N,S,W,E)
i = 0
while (N != 0 or S != 0 or E != 0 or W != 0) and i<len(s):
if s[i] == 'N' and N>0:
N... | Title: Sail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assu... | ```python
'''input
10 5 3 3 6
NENSWESNEE
'''
t, sx, sy, ex, ey = map(int, input().split())
s = str(input())
dy = ey-sy
dx = ex-sx
N = S = E = W = 0
if dy>=0:
N = dy
else:
S = dy
if dx>=0:
E = dx
else:
W = dx
# print(N,S,W,E)
i = 0
while (N != 0 or S != 0 or E != 0 or W != 0) and i<len(s):
if s[i] == 'N' an... | 0 | |
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,664,956,389 | 2,147,483,647 | Python 3 | OK | TESTS | 73 | 46 | 102,400 | x=input()
y=input()
if x==y:
print(-1)
else:
x=len(x)
y=len(y)
print(max(x,y)) | 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
x=input()
y=input()
if x==y:
print(-1)
else:
x=len(x)
y=len(y)
print(max(x,y))
``` | 3 | |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,478,968,621 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 124 | 0 | a,b,c,d=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
if (a>b): a,b=b,a
if (b>c): b,c=c,b
if (c>d): c,d=d,c
if (a>b): a,b=b,a
if (b>c): b,c=c,b
if (a>b): a,b=b,a
if (a+b<c and b+c<d): print("IMPOSSIBLE")
elif (a+b>c or b+c>d): print ("TRIANGLE")
else: print ("SEGMENT")
| Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
a,b,c,d=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
if (a>b): a,b=b,a
if (b>c): b,c=c,b
if (c>d): c,d=d,c
if (a>b): a,b=b,a
if (b>c): b,c=c,b
if (a>b): a,b=b,a
if (a+b<c and b+c<d): print("IMPOSSIBLE")
elif (a+b>c or b+c>d): print ("TRIANGLE")
else: print ("SEGMENT")
``` | 3.969 |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,674,219,445 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | d1,d2,d3 = map(int,input().split())
x = (d1+d2)*2
y = (d1+d2+d3)
z = (d1+d3)*2
w = (d2+d3)*2
print(min(x,y,z,w)) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
d1,d2,d3 = map(int,input().split())
x = (d1+d2)*2
y = (d1+d2+d3)
z = (d1+d3)*2
w = (d2+d3)*2
print(min(x,y,z,w))
``` | 3 | |
525 | A | Vitaliy and Pie | PROGRAMMING | 1,100 | [
"greedy",
"hashing",
"strings"
] | null | null | After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ... | The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house.
The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one.
The odd positions in the given string *s* contain ... | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. | [
"3\naAbB\n",
"4\naBaCaB\n",
"5\nxYyXzZaZ\n"
] | [
"0\n",
"3\n",
"2\n"
] | none | 250 | [
{
"input": "3\naAbB",
"output": "0"
},
{
"input": "4\naBaCaB",
"output": "3"
},
{
"input": "5\nxYyXzZaZ",
"output": "2"
},
{
"input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY",
"output": "0"
},
{
"input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg... | 1,668,383,335 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 124 | 716,800 | # vitality and pie
doors = int(input())
keys = [0]*26
sequence = input()
contador = 0
for i in range(len(sequence)):
valueAscii = ord(sequence[i])
if valueAscii >= 65 and valueAscii <= 90: # é porta
if keys[valueAscii-65] == 0: contador += 1 # não tem chave
else: keys[valueAscii-65] -= 1 # ... | Title: Vitaliy and Pie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from... | ```python
# vitality and pie
doors = int(input())
keys = [0]*26
sequence = input()
contador = 0
for i in range(len(sequence)):
valueAscii = ord(sequence[i])
if valueAscii >= 65 and valueAscii <= 90: # é porta
if keys[valueAscii-65] == 0: contador += 1 # não tem chave
else: keys[valueAscii-6... | 3 | |
518 | A | Vitaly and Strings | PROGRAMMING | 1,600 | [
"constructive algorithms",
"strings"
] | null | null | Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase Engli... | The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string.
The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings *s* and *t* are the same and str... | If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them. | [
"a\nc\n",
"aaa\nzzz\n",
"abcdefg\nabcdefh\n"
] | [
"b\n",
"kkk\n",
"No such string\n"
] | String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that ... | 500 | [
{
"input": "a\nc",
"output": "b"
},
{
"input": "aaa\nzzz",
"output": "kkk"
},
{
"input": "abcdefg\nabcdefh",
"output": "No such string"
},
{
"input": "abcdefg\nabcfefg",
"output": "abcdefh"
},
{
"input": "frt\nfru",
"output": "No such string"
},
{
"inp... | 1,537,511,978 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 108 | 307,200 | s1 = list(input())
s2 = list(input())
n = len(s1)
run = False
for i in range(n-1):
if ord(s2[i]) - ord(s1[i]) > 0:
run = True
s1[i+1] = chr(ord(s1[i+1])+1)
break
elif ord(s2[n-1]) - ord(s1[n-1]) > 1:
run = True
s1[n-1] = chr(ord(s1[n-1])+1)
break
if... | Title: Vitaly and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provi... | ```python
s1 = list(input())
s2 = list(input())
n = len(s1)
run = False
for i in range(n-1):
if ord(s2[i]) - ord(s1[i]) > 0:
run = True
s1[i+1] = chr(ord(s1[i+1])+1)
break
elif ord(s2[n-1]) - ord(s1[n-1]) > 1:
run = True
s1[n-1] = chr(ord(s1[n-1])+1)
... | 0 | |
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,666,889,344 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 93 | 1,945,600 | cal = list(map (int, input().split(' ')))
s = input()
sum = 0
for i in range (len(s)):
sum = sum + cal[int (s[i]) - 1]
print (sum)
| 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
cal = list(map (int, input().split(' ')))
s = input()
sum = 0
for i in range (len(s)):
sum = sum + cal[int (s[i]) - 1]
print (sum)
``` | 3 | |
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul... | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{... | 1,690,110,340 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,048,000 | from sys import stdin, stdout
a, b, c, t = (int(stdin.readline()) for _ in range(3)), 0
if 1 in (a, b, c):
if a == 1:
t = 1 + b
elif b == 1:
a, c = (a, c) if a <= c else (c, a)
t = 1 + a
else:
b = b + 1
c = a
print(t*c if c!=1 else t+1)
else:
pr... | Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ... | ```python
from sys import stdin, stdout
a, b, c, t = (int(stdin.readline()) for _ in range(3)), 0
if 1 in (a, b, c):
if a == 1:
t = 1 + b
elif b == 1:
a, c = (a, c) if a <= c else (c, a)
t = 1 + a
else:
b = b + 1
c = a
print(t*c if c!=1 else t+1)
els... | -1 | |
658 | A | Bear and Reverse Radewoosh | PROGRAMMING | 800 | [
"implementation"
] | null | null | Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by diff... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=50,<=1<=≤<=*c*<=≤<=1000) — the number of problems and the constant representing the speed of loosing points.
The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1000,<=*p**i*<=<<=*p**i*<=+<=1) — initial scores.
The third... | Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points. | [
"3 2\n50 85 250\n10 15 25\n",
"3 6\n50 85 250\n10 15 25\n",
"8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n"
] | [
"Limak\n",
"Radewoosh\n",
"Tie\n"
] | In the first sample, there are 3 problems. Limak solves them as follows:
1. Limak spends 10 minutes on the 1-st problem and he gets 50 - *c*·10 = 50 - 2·10 = 30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85... | 500 | [
{
"input": "3 2\n50 85 250\n10 15 25",
"output": "Limak"
},
{
"input": "3 6\n50 85 250\n10 15 25",
"output": "Radewoosh"
},
{
"input": "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76",
"output": "Tie"
},
{
"input": "4 1\n3 5 6 9\n1 2 4 8",
"output": "Limak"
},
{... | 1,586,293,459 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 93 | 307,200 |
def fon(l,t,c,r):
d = 0
e=0
for i in range(r):
d+=t[i]
if d < l[i]:
e += l[i] - c*d
else:
pass
return e
n,c = map(int,input().split())
l = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
l1 = l[::-1]
t1 = t[::-1]
a = fon(l,t,c,n)
b = fon(l1,t1,c,n)
... | Title: Bear and Reverse Radewoosh
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-... | ```python
def fon(l,t,c,r):
d = 0
e=0
for i in range(r):
d+=t[i]
if d < l[i]:
e += l[i] - c*d
else:
pass
return e
n,c = map(int,input().split())
l = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
l1 = l[::-1]
t1 = t[::-1]
a = fon(l,t,c,n)
b = fon(l1,t... | 0 | |
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s... | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indi... | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGB... | 1,659,886,092 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 124 | 0 | colors = ['R', 'O', 'Y', 'G', 'B', 'I', 'V']
c = int(input())
ptr = 0
last = 3
while (c):
if ptr == len(colors): ptr = last;last -= 1
if last < 0: last = 3
print(colors[ptr], end="")
c -= 1
if ptr >= 0: ptr += 1
else: ptr -= 1
print()
| Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
-... | ```python
colors = ['R', 'O', 'Y', 'G', 'B', 'I', 'V']
c = int(input())
ptr = 0
last = 3
while (c):
if ptr == len(colors): ptr = last;last -= 1
if last < 0: last = 3
print(colors[ptr], end="")
c -= 1
if ptr >= 0: ptr += 1
else: ptr -= 1
print()
``` | 0 |
194 | B | Square | PROGRAMMING | 1,200 | [
"math"
] | null | null | There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwa... | The first line contains integer *t* (1<=≤<=*t*<=≤<=104) — the number of test cases.
The second line contains *t* space-separated integers *n**i* (1<=≤<=*n**i*<=≤<=109) — the sides of the square for each test sample. | For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.
Please do not use the %lld specifier to read or write 64-bit... | [
"3\n4 8 100\n"
] | [
"17\n33\n401\n"
] | none | 1,000 | [
{
"input": "3\n4 8 100",
"output": "17\n33\n401"
},
{
"input": "8\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13",
"output": "4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n27"
},
{
"input": "3\n13 17 21",
"output... | 1,541,093,014 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 409,600 | x=int(input())
a=list(map(int,input().split()))
for i in range(x):
if a[i]%2==0:
print(a[i]*4+1)
else:
print(a[i]*2+1) | Title: Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the ... | ```python
x=int(input())
a=list(map(int,input().split()))
for i in range(x):
if a[i]%2==0:
print(a[i]*4+1)
else:
print(a[i]*2+1)
``` | 0 | |
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,657,001,711 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 77 | 716,800 | a1,a2,a3,a4=list(map(int,input().split()))
str1=list(map(int,input()))
sum=0
for i in str1:
if i==1:sum+=a1
elif i==2:sum+=a2
elif i==3:sum+=a3
else :sum+=a4
print(sum) | 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
a1,a2,a3,a4=list(map(int,input().split()))
str1=list(map(int,input()))
sum=0
for i in str1:
if i==1:sum+=a1
elif i==2:sum+=a2
elif i==3:sum+=a3
else :sum+=a4
print(sum)
``` | 3 | |
583 | A | Asphalting Roads | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them.
Sand roads have long been recognized out of date, so the decision was ma... | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city.
Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the inte... | In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1. | [
"2\n1 1\n1 2\n2 1\n2 2\n",
"1\n1 1\n"
] | [
"1 4 \n",
"1 \n"
] | In the sample the brigade acts like that:
1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the i... | 500 | [
{
"input": "2\n1 1\n1 2\n2 1\n2 2",
"output": "1 4 "
},
{
"input": "1\n1 1",
"output": "1 "
},
{
"input": "2\n1 1\n2 2\n1 2\n2 1",
"output": "1 2 "
},
{
"input": "2\n1 2\n2 2\n2 1\n1 1",
"output": "1 3 "
},
{
"input": "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 ... | 1,617,431,024 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 171 | 3,891,200 | from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br
inp =lambda: int(input())
strng =lambda: input().strip()
jn =lambda x,l: x.join(map(str,l))
strl =lambda: list(input().strip())
mul =lambda: map(int,input().strip().split())
mulf =lambda: map(fl... | Title: Asphalting Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers ... | ```python
from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br
inp =lambda: int(input())
strng =lambda: input().strip()
jn =lambda x,l: x.join(map(str,l))
strl =lambda: list(input().strip())
mul =lambda: map(int,input().strip().split())
mulf =lamb... | 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,656,951,914 | 2,147,483,647 | PyPy 3 | OK | TESTS | 102 | 108 | 0 | n = input()
s = input()
lis = []
for i in range(0,len(n)):
if n[i] == s[i]:
lis.append(0)
else:
lis.append(1)
print(*lis,sep ='')
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
n = input()
s = input()
lis = []
for i in range(0,len(n)):
if n[i] == s[i]:
lis.append(0)
else:
lis.append(1)
print(*lis,sep ='')
``` | 3.973 |
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,619,788,281 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | word=input()
countlow=0
countup=0
for i in word:
if i.islower():
countlow=countlow+1
else:
countup=countup+1
if countup<=countlow:
print(word.lower())
else:
print(word.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
word=input()
countlow=0
countup=0
for i in word:
if i.islower():
countlow=countlow+1
else:
countup=countup+1
if countup<=countlow:
print(word.lower())
else:
print(word.upper())
``` | 3.969 |
990 | B | Micro-World | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.
You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer c... | The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$.
The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have. | Print the only integer — minimal possible number of bacteria can remain. | [
"7 1\n101 53 42 102 101 55 54\n",
"6 5\n20 15 10 15 20 25\n",
"7 1000000\n1 1 1 1 1 1 1\n"
] | [
"3\n",
"1\n",
"7\n"
] | The first example is clarified in the problem statement.
In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$.
I... | 0 | [
{
"input": "7 1\n101 53 42 102 101 55 54",
"output": "3"
},
{
"input": "6 5\n20 15 10 15 20 25",
"output": "1"
},
{
"input": "7 1000000\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 4\n8",
"output": "1"
},
{
"inp... | 1,586,096,465 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 109 | 0 | while True:
try:
n, k= map(int, input().split())
a = list(map(int, input().split()))
a.sort()
aa = a
i = 1
cunt = 0
while i <= n:
j = i +1
while j <= n:
if aa[-i] > aa[ -j] and aa[-j]+k >= aa[-i]:
cunt += 1
aa[-j] = -100
j += 1
else:
break
i += 1
t = n- cunt
i= 0... | Title: Micro-World
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.
You know that you have $n$ bacteria in the Pe... | ```python
while True:
try:
n, k= map(int, input().split())
a = list(map(int, input().split()))
a.sort()
aa = a
i = 1
cunt = 0
while i <= n:
j = i +1
while j <= n:
if aa[-i] > aa[ -j] and aa[-j]+k >= aa[-i]:
cunt += 1
aa[-j] = -100
j += 1
else:
break
i += 1
t = n- c... | 0 | |
431 | C | k-Tree | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"trees"
] | null | null | Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes... | A single line contains three space-separated integers: *n*, *k* and *d* (1<=≤<=*n*,<=*k*<=≤<=100; 1<=≤<=*d*<=≤<=*k*). | Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"3 3 2\n",
"3 3 3\n",
"4 3 2\n",
"4 5 2\n"
] | [
"3\n",
"1\n",
"6\n",
"7\n"
] | none | 1,500 | [
{
"input": "3 3 2",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 3 2",
"output": "6"
},
{
"input": "4 5 2",
"output": "7"
},
{
"input": "28 6 3",
"output": "110682188"
},
{
"input": "5 100 1",
"output": "16"
},
{
"inp... | 1,664,096,109 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 124 | 3,584,000 | import collections
import heapq
import sys
import math
import itertools
import bisect
from io import BytesIO, IOBase
import os
######################################################################################
#--------------------------------------funs here-------------------------------------#
###################... | Title: k-Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex ... | ```python
import collections
import heapq
import sys
import math
import itertools
import bisect
from io import BytesIO, IOBase
import os
######################################################################################
#--------------------------------------funs here-------------------------------------#
#########... | 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,654,182,983 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 4,000 | 0 | n,m=map(int,input().split())
ch=1
while ch==1:
n+=2
for i in range(2,n//2+1):
if n%i==0:
#print('hello')
break
else:
ch=0
#print('hi')
if n==m:
print('YES')
else:
print('NO')
| 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())
ch=1
while ch==1:
n+=2
for i in range(2,n//2+1):
if n%i==0:
#print('hello')
break
else:
ch=0
#print('hi')
if n==m:
print('YES')
else:
print('NO')
``` | 0 |
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,526,577,717 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 78 | 0 | def f(s):
if s == s[::-1]:
print (s)
exit(0)
s = input()
for k in range(len(s)):
f(s[:k] + s[len(s) - k - 1] + s[k:len(s)])
f(s + s[0])
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
def f(s):
if s == s[::-1]:
print (s)
exit(0)
s = input()
for k in range(len(s)):
f(s[:k] + s[len(s) - k - 1] + s[k:len(s)])
f(s + s[0])
print("NA")
``` | 0 | |
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each frie... | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer — the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
... | 1,671,552,837 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 124 | 0 | n,k,l,c,d,p,nl,np=tuple(map(int,input().split()))
toast=min((k*l)//nl,c*d,p//np)
print(toast//n) | Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut... | ```python
n,k,l,c,d,p,nl,np=tuple(map(int,input().split()))
toast=min((k*l)//nl,c*d,p//np)
print(toast//n)
``` | 3 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,597,228,134 | 5,634 | Python 3 | OK | TESTS | 20 | 218 | 6,963,200 | n =int(input())
x = []
y = []
for i in range(n):
name,points = map(str,input().split())
x.append(name)
y.append(int(points))
d = {}
for N,p in zip(x,y):
if N in d:
d[N]+=p
else:
d[N]=p
d1 = {}
mx = 0
for i in range(n):
mx = max(mx,d[x[i]])
for i in range(n):
if x... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
n =int(input())
x = []
y = []
for i in range(n):
name,points = map(str,input().split())
x.append(name)
y.append(int(points))
d = {}
for N,p in zip(x,y):
if N in d:
d[N]+=p
else:
d[N]=p
d1 = {}
mx = 0
for i in range(n):
mx = max(mx,d[x[i]])
for i in range(... | 3.83912 |
938 | A | Word Correction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction. | Output the word *s* after the correction. | [
"5\nweird\n",
"4\nword\n",
"5\naaeaa\n"
] | [
"werd\n",
"word\n",
"a\n"
] | Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <i... | 0 | [
{
"input": "5\nweird",
"output": "werd"
},
{
"input": "4\nword",
"output": "word"
},
{
"input": "5\naaeaa",
"output": "a"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw",
"output": "abbbbbocadabbbbb... | 1,585,353,428 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 124 | 0 | trash = input()
word = input()
vowels = set(['a', 'e', 'i', 'o', 'u', 'y' ])
new_word = ''
for i in range(0, len(word)):
current = word[i]
prev = word[i - 1] if i - 1 >= 0 else None
if not(current in vowels and prev in vowels):
new_word = new_word + current
print(new_word)
... | Title: Word Correction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird an... | ```python
trash = input()
word = input()
vowels = set(['a', 'e', 'i', 'o', 'u', 'y' ])
new_word = ''
for i in range(0, len(word)):
current = word[i]
prev = word[i - 1] if i - 1 >= 0 else None
if not(current in vowels and prev in vowels):
new_word = new_word + current
print(new_word)
... | 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,659,760,144 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | m=int(input())
n=int(input())
c=int((m*n)/2)
print(c)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m=int(input())
n=int(input())
c=int((m*n)/2)
print(c)
``` | -1 |
999 | A | Mishka and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses ... | The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are... | Print one integer — the maximum number of problems Mishka can solve. | [
"8 4\n4 2 3 1 5 1 6 4\n",
"5 2\n3 1 2 1 3\n",
"5 100\n12 34 55 43 21\n"
] | [
"5\n",
"0\n",
"5\n"
] | In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$.
In the second example, M... | 0 | [
{
"input": "8 4\n4 2 3 1 5 1 6 4",
"output": "5"
},
{
"input": "5 2\n3 1 2 1 3",
"output": "0"
},
{
"input": "5 100\n12 34 55 43 21",
"output": "5"
},
{
"input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 1... | 1,691,918,699 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 48 | 77 | 0 | n,k = map(int,input().split())
a = list(map(int, input().split()))
sum1 = 0
sum2 = 0
ans = 0
for i in range(len(a)):
if a[i] <= k:
sum1 += 1
else :
break
for j in range(len(a) - 1, -1, -1):
if a[j] <= k:
sum2 += 1
else :
break
ans = sum1 + sum2
if ans > n ... | Title: Mishka and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his... | ```python
n,k = map(int,input().split())
a = list(map(int, input().split()))
sum1 = 0
sum2 = 0
ans = 0
for i in range(len(a)):
if a[i] <= k:
sum1 += 1
else :
break
for j in range(len(a) - 1, -1, -1):
if a[j] <= k:
sum2 += 1
else :
break
ans = sum1 + sum2
i... | 3 | |
847 | G | University Classes | PROGRAMMING | 900 | [
"implementation"
] | null | null | There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of groups.
Each of the following *n* lines contains a sequence consisting of 7 zeroes and ones — the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot... | Print minimum number of rooms needed to hold all groups classes on Monday. | [
"2\n0101010\n1010101\n",
"3\n0101011\n0011001\n0110111\n"
] | [
"1\n",
"3\n"
] | In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group.
In the second example three rooms is enough, because in the seventh time slot all three groups have classes. | 0 | [
{
"input": "2\n0101010\n1010101",
"output": "1"
},
{
"input": "3\n0101011\n0011001\n0110111",
"output": "3"
},
{
"input": "1\n0111000",
"output": "1"
},
{
"input": "1\n0000000",
"output": "0"
},
{
"input": "1\n1111111",
"output": "1"
},
{
"input": "2\n... | 1,584,713,586 | 2,147,483,647 | PyPy 3 | OK | TESTS | 21 | 187 | 1,740,800 | n = int(input())
m = []
for i in range(n):
m.append(input())
ma = 0
for i in range(7):
at = 0
for j in range(n):
if m[j][i] == "1":
at += 1
ma = max(ma, at)
print(ma)
| Title: University Classes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known ... | ```python
n = int(input())
m = []
for i in range(n):
m.append(input())
ma = 0
for i in range(7):
at = 0
for j in range(n):
if m[j][i] == "1":
at += 1
ma = max(ma, at)
print(ma)
``` | 3 | |
490 | B | Queue | PROGRAMMING | 1,500 | [
"dsu",
"implementation"
] | null | null | During the lunch break all *n* Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID ... | The first line contains integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of students in the queue.
Then *n* lines follow, *i*-th line contains the pair of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=106), where *a**i* is the ID number of a person in front of a student and *b**i* is the ID number of a person beh... | Print a sequence of *n* integers *x*1,<=*x*2,<=...,<=*x**n* — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one. | [
"4\n92 31\n0 7\n31 0\n7 141\n"
] | [
"92 7 31 141 \n"
] | The picture illustrates the queue for the first sample. | 1,000 | [
{
"input": "4\n92 31\n0 7\n31 0\n7 141",
"output": "92 7 31 141 "
},
{
"input": "2\n0 1\n2 0",
"output": "2 1 "
},
{
"input": "3\n0 2\n1 3\n2 0",
"output": "1 2 3 "
},
{
"input": "4\n101 0\n0 102\n102 100\n103 101",
"output": "103 102 101 100 "
},
{
"input": "5\n0... | 1,667,461,466 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 46 | 102,400 | from collections import deque
n = int(input())
q = deque([])
ans = [0] * n
idx_map = {}
for _ in range(n):
infront, behind = tuple(map(int, input().split()))
if infront == 0:
ans[1] = behind
idx_map[behind] = 1
continue
if behind == 0:
ans[n-2] = infront
... | Title: Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the lunch break all *n* Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't b... | ```python
from collections import deque
n = int(input())
q = deque([])
ans = [0] * n
idx_map = {}
for _ in range(n):
infront, behind = tuple(map(int, input().split()))
if infront == 0:
ans[1] = behind
idx_map[behind] = 1
continue
if behind == 0:
ans[n-2] = infront... | -1 | |
670 | A | Holidays | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"greedy",
"math"
] | null | null | On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars. | Print two integers — the minimum possible and the maximum possible number of days off per year on Mars. | [
"14\n",
"2\n"
] | [
"4 4\n",
"0 2\n"
] | In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off. | 500 | [
{
"input": "14",
"output": "4 4"
},
{
"input": "2",
"output": "0 2"
},
{
"input": "1",
"output": "0 1"
},
{
"input": "3",
"output": "0 2"
},
{
"input": "4",
"output": "0 2"
},
{
"input": "5",
"output": "0 2"
},
{
"input": "6",
"output":... | 1,641,563,297 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n = int(input())
min_n = 0
max_n = 0
if n % 7 == 0:
min_n += n // 7 * 2
max_n += n // 7 * 2
else:
fake_n = n
while fake_n % 7 != 0:
fake_n += 1
min_n = ((fake_n // 7) - 1) * 2
max_n = ((fake_n // 7) - 1) * 2
fake_n -= n
if fake_n <= 5:
max_n += 2
elif... | Title: Holidays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maxim... | ```python
n = int(input())
min_n = 0
max_n = 0
if n % 7 == 0:
min_n += n // 7 * 2
max_n += n // 7 * 2
else:
fake_n = n
while fake_n % 7 != 0:
fake_n += 1
min_n = ((fake_n // 7) - 1) * 2
max_n = ((fake_n // 7) - 1) * 2
fake_n -= n
if fake_n <= 5:
max_n += 2... | 0 | |
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,683,079,039 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 62 | 1,126,400 | ap=list(map(int,input().split()))
bp=list(map(int,input()))
p,q=0,0
while p<4:
z=bp.count(p+1)
q+=(ap[p]*z)
p+=1
print(q)
| 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
ap=list(map(int,input().split()))
bp=list(map(int,input()))
p,q=0,0
while p<4:
z=bp.count(p+1)
q+=(ap[p]*z)
p+=1
print(q)
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,672,829,797 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 61 | 0 | s=input()
l=[*s]
h=['h','e','l','o']
a=[]
for i in l:
if(i not in a and i!='l'):
a.append(i)
elif(i=='l' and a.count('l')!=2):
a.append(i)
b=a
for i in b:
if(i not in h):
a.remove(i)
for i in b:
if(i not in h):
a.remove(i)
if(''.join(a)=="hello"):
pri... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=input()
l=[*s]
h=['h','e','l','o']
a=[]
for i in l:
if(i not in a and i!='l'):
a.append(i)
elif(i=='l' and a.count('l')!=2):
a.append(i)
b=a
for i in b:
if(i not in h):
a.remove(i)
for i in b:
if(i not in h):
a.remove(i)
if(''.join(a)=="hello")... | 0 |
665 | D | Simple Subset | PROGRAMMING | 1,800 | [
"constructive algorithms",
"greedy",
"number theory"
] | null | null | A tuple of positive integers {*x*1,<=*x*2,<=...,<=*x**k*} is called simple if for all pairs of positive integers (*i*,<=<=*j*) (1<=<=≤<=*i*<=<=<<=<=*j*<=≤<=*k*), *x**i*<=<=+<=<=*x**j* is a prime.
You are given an array *a* with *n* positive integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (not necessary distinct). You wan... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of integers in the array *a*.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array *a*. | On the first line print integer *m* — the maximum possible size of simple subset of *a*.
On the second line print *m* integers *b**l* — the elements of the simple subset of the array *a* with the maximum size.
If there is more than one solution you can print any of them. You can print the elements of the subset in an... | [
"2\n2 3\n",
"2\n2 2\n",
"3\n2 1 1\n",
"2\n83 14\n"
] | [
"2\n3 2\n",
"1\n2\n",
"3\n1 1 2\n",
"2\n14 83\n"
] | none | 0 | [
{
"input": "2\n2 3",
"output": "2\n3 2"
},
{
"input": "2\n2 2",
"output": "1\n2"
},
{
"input": "3\n2 1 1",
"output": "3\n1 1 2"
},
{
"input": "2\n83 14",
"output": "2\n14 83"
},
{
"input": "10\n10 10 1 2 3 3 1 2 1 5",
"output": "4\n1 1 10 1"
},
{
"inpu... | 1,693,685,442 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 13,004,800 | def resheto_eratosfena(n):
p=[1]*(n+1)
p[0]=0
p[1]=0
i=2
while i*i<=n:
for j in range(i*i,n+1,i):
p[j]=0
i+=1
while i<n+1 and not p[i]:
i+=1
return p
R=10**6
p=resheto_eratosfena(R+1)
p=[i for i in range(2,R+1) if p[i]]
n=int(input()... | Title: Simple Subset
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tuple of positive integers {*x*1,<=*x*2,<=...,<=*x**k*} is called simple if for all pairs of positive integers (*i*,<=<=*j*) (1<=<=≤<=*i*<=<=<<=<=*j*<=≤<=*k*), *x**i*<=<=+<=<=*x**j* is a prime.
You are given an arra... | ```python
def resheto_eratosfena(n):
p=[1]*(n+1)
p[0]=0
p[1]=0
i=2
while i*i<=n:
for j in range(i*i,n+1,i):
p[j]=0
i+=1
while i<n+1 and not p[i]:
i+=1
return p
R=10**6
p=resheto_eratosfena(R+1)
p=[i for i in range(2,R+1) if p[i]]
n=i... | 0 | |
315 | A | Sereja and Bottles | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. | In a single line print a single integer — the answer to the problem. | [
"4\n1 1\n2 2\n3 3\n4 4\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] | [
"4\n",
"0\n"
] | none | 500 | [
{
"input": "4\n1 1\n2 2\n3 3\n4 4",
"output": "4"
},
{
"input": "4\n1 2\n2 3\n3 4\n4 1",
"output": "0"
},
{
"input": "3\n2 828\n4 392\n4 903",
"output": "3"
},
{
"input": "4\n2 3\n1 772\n3 870\n3 668",
"output": "2"
},
{
"input": "5\n1 4\n6 6\n4 3\n3 4\n4 758",
... | 1,615,387,825 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 30 | 124 | 0 | n = int(input())
a = []
b = []
for i in range(n):
x,y = map(int, input().split())
if x != y:
a.append(x)
b.append(y)
else:
a.append(x)
b = set(b)
ans = 0
for i in a:
if i in b:
ans += 1
print(len(a)-ans) | Title: Sereja and Bottles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th... | ```python
n = int(input())
a = []
b = []
for i in range(n):
x,y = map(int, input().split())
if x != y:
a.append(x)
b.append(y)
else:
a.append(x)
b = set(b)
ans = 0
for i in a:
if i in b:
ans += 1
print(len(a)-ans)
``` | 0 | |
55 | C | Pie or die | PROGRAMMING | 1,900 | [
"games"
] | C. Pie or die | 2 | 256 | Volodya and Vlad play the following game. There are *k* pies at the cells of *n*<=<=×<=<=*m* board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at... | First line contains 3 integers, separated by space: 1<=≤<=*n*,<=*m*<=≤<=100 — dimensions of the board and 0<=≤<=*k*<=≤<=100 — the number of pies. Each of the next *k* lines contains 2 integers, separated by space: 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* — coordinates of the corresponding pie. There could be more than one ... | Output only one word: "YES" — if Volodya wins, "NO" — otherwise. | [
"2 2 1\n1 2\n",
"3 4 0\n",
"100 50 2\n50 25\n50 25\n"
] | [
"YES",
"NO",
"NO"
] | none | 1,500 | [
{
"input": "2 2 1\n1 2",
"output": "YES"
},
{
"input": "3 4 0",
"output": "NO"
},
{
"input": "100 50 2\n50 25\n50 25",
"output": "NO"
},
{
"input": "20 20 4\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "15 15 1\n8 8",
"output": "NO"
},
{
... | 1,651,171,279 | 79 | Python 3 | OK | TESTS | 75 | 92 | 0 | n, m, k = map(int, input().split())
flag = False
while k > 0:
k -= 1
x, y = map(int, input().split())
d = min(x, n - x + 1, y, m - y + 1)
if d <= 5:
flag = True
print("YES" if flag else "NO") | Title: Pie or die
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Volodya and Vlad play the following game. There are *k* pies at the cells of *n*<=<=×<=<=*m* board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can ... | ```python
n, m, k = map(int, input().split())
flag = False
while k > 0:
k -= 1
x, y = map(int, input().split())
d = min(x, n - x + 1, y, m - y + 1)
if d <= 5:
flag = True
print("YES" if flag else "NO")
``` | 3.977 |
580 | C | Kefa and Park | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Kefa decided to celebrate his first big salary by going to the restaurant.
He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the v... | The first line contains two integers, *n* and *m* (2<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=*n*) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where each *a**i* either equals to 0 (then ... | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most *m* consecutive vertices with cats. | [
"4 1\n1 1 0 0\n1 2\n1 3\n1 4\n",
"7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n"
] | [
"2\n",
"2\n"
] | Let us remind you that a tree is a connected graph on *n* vertices and *n* - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if i... | 1,500 | [
{
"input": "4 1\n1 1 0 0\n1 2\n1 3\n1 4",
"output": "2"
},
{
"input": "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7",
"output": "2"
},
{
"input": "3 2\n1 1 1\n1 2\n2 3",
"output": "0"
},
{
"input": "5 2\n1 1 0 1 1\n1 2\n2 3\n3 4\n4 5",
"output": "1"
},
{
"inpu... | 1,694,321,949 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | ans=0
def solve():
n,m = map(int,input().split())
arr = list(map(int,input().split()))
adj = [[]for i in range(n)]
for i in range(n-1):
a,b = map(int,input().split())
adj[a-1].append(b-1)
adj[b-1].append(a-1)
def dfs(s,adj,mtmp,m,arr,par):
global ans
if mtmp>m:
return
ok=1
for i in adj[s]:
if i... | Title: Kefa and Park
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to celebrate his first big salary by going to the restaurant.
He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house... | ```python
ans=0
def solve():
n,m = map(int,input().split())
arr = list(map(int,input().split()))
adj = [[]for i in range(n)]
for i in range(n-1):
a,b = map(int,input().split())
adj[a-1].append(b-1)
adj[b-1].append(a-1)
def dfs(s,adj,mtmp,m,arr,par):
global ans
if mtmp>m:
return
ok=1
for i in adj[s... | 0 | |
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"i... | 1,690,653,302 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 92 | 2,867,200 | k = int(input()) #got punched in the face with a frying pan
l = int(input()) #got his tail shut into the balcony door
m = int(input()) #got his paws trampled with sharp heels
n = int(input()) #call her mom
d = int(input()) #number of dragons
br = 0
L = ['0']*d
for i in range(d):
if i % k == 0:
... | Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entert... | ```python
k = int(input()) #got punched in the face with a frying pan
l = int(input()) #got his tail shut into the balcony door
m = int(input()) #got his paws trampled with sharp heels
n = int(input()) #call her mom
d = int(input()) #number of dragons
br = 0
L = ['0']*d
for i in range(d):
if i %... | 0 | |
814 | E | An unavoidable detour for home | PROGRAMMING | 2,600 | [
"combinatorics",
"dp",
"graphs",
"shortest paths"
] | null | null | Those unwilling to return home from a long journey, will be affected by the oddity of the snail and lose their way. Mayoi, the oddity's carrier, wouldn't like this to happen, but there's nothing to do with this before a cure is figured out. For now, she would only like to know the enormous number of possibilities to be... | The first line of input contains a positive integer *n* (3<=≤<=*n*<=≤<=50) — the number of towns.
The second line contains *n* space-separated integers *d*1,<=*d*2,<=...,<=*d**n* (2<=≤<=*d**i*<=≤<=3) — the number of roads connected to towns 1,<=2,<=...,<=*n*, respectively. It is guaranteed that the sum of *d**i* over ... | Output one integer — the total number of different possible ways in which the towns are connected, modulo 109<=+<=7. | [
"4\n3 2 3 2\n",
"5\n2 3 3 2 2\n",
"5\n2 2 2 2 2\n",
"20\n2 2 2 2 3 2 3 2 2 2 2 2 2 2 2 2 2 3 3 2\n"
] | [
"1\n",
"2\n",
"2\n",
"82944\n"
] | In the first example, the following structure is the only one to satisfy the constraints, the distances from towns 2, 3, 4 to the capital are all 1.
In the second example, the following two structures satisfy the constraints. | 2,500 | [] | 1,497,508,763 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = input() #X is the rank of the current highest, each that rank disappear and the rank Y below become the new highest rank X
a = input() #Each turn the current first node on Z will try to connect to X and move into Y, no 2 nodes in X connect the same node
a = a.split(' ')#Strategy: Dynamic programming, ther... | Title: An unavoidable detour for home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those unwilling to return home from a long journey, will be affected by the oddity of the snail and lose their way. Mayoi, the oddity's carrier, wouldn't like this to happen, but there's nothing to do wit... | ```python
n = input() #X is the rank of the current highest, each that rank disappear and the rank Y below become the new highest rank X
a = input() #Each turn the current first node on Z will try to connect to X and move into Y, no 2 nodes in X connect the same node
a = a.split(' ')#Strategy: Dynamic program... | -1 | |
435 | B | Pasha Maximizes | PROGRAMMING | 1,400 | [
"greedy"
] | null | null | Pasha has a positive integer *a* without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most *k... | The single line contains two integers *a* and *k* (1<=≤<=*a*<=≤<=1018; 0<=≤<=*k*<=≤<=100). | Print the maximum number that Pasha can get if he makes at most *k* swaps. | [
"1990 1\n",
"300 0\n",
"1034 2\n",
"9090000078001234 6\n"
] | [
"9190\n",
"300\n",
"3104\n",
"9907000008001234\n"
] | none | 1,000 | [
{
"input": "1990 1",
"output": "9190"
},
{
"input": "300 0",
"output": "300"
},
{
"input": "1034 2",
"output": "3104"
},
{
"input": "9090000078001234 6",
"output": "9907000008001234"
},
{
"input": "1234 3",
"output": "4123"
},
{
"input": "5 100",
"... | 1,586,899,041 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 307,200 | import sys
input = sys.stdin.readline
def multi_input():
return map(int, input().split())
def array_print(arr):
print(''.join(map(str, arr)))
n, k = multi_input()
n1 = n
len = 0
while n1:
n1 = n1//10
len +=1
a = [0]*len
i = len
while n:
temp = n%10
a[i-1] = temp
n //= ... | Title: Pasha Maximizes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a positive integer *a* without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits ... | ```python
import sys
input = sys.stdin.readline
def multi_input():
return map(int, input().split())
def array_print(arr):
print(''.join(map(str, arr)))
n, k = multi_input()
n1 = n
len = 0
while n1:
n1 = n1//10
len +=1
a = [0]*len
i = len
while n:
temp = n%10
a[i-1] = temp
... | 0 | |
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,667,380,718 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 92 | 0 | x=input()
y=input()
i,j,c=0,0,1
while j<len(y) and i<len(x):
if x[i]==y[j]:
c+=1
i+=1
j+=1
print(c) | 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
x=input()
y=input()
i,j,c=0,0,1
while j<len(y) and i<len(x):
if x[i]==y[j]:
c+=1
i+=1
j+=1
print(c)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100) — the initial number of elements in the set. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the set. | Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes). | [
"2\n2 3\n",
"2\n5 3\n",
"3\n5 6 7\n"
] | [
"Alice\n",
"Alice\n",
"Bob\n"
] | Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice. | 0 | [
{
"input": "2\n2 3",
"output": "Alice"
},
{
"input": "2\n5 3",
"output": "Alice"
},
{
"input": "3\n5 6 7",
"output": "Bob"
},
{
"input": "10\n72 96 24 66 6 18 12 30 60 48",
"output": "Bob"
},
{
"input": "10\n78 66 6 60 18 84 36 96 72 48",
"output": "Bob"
},
... | 1,584,366,632 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 16 | 218 | 0 | n = int(input())
arr = list(map( int , input().split()))
c = 0
for i in arr :
if i%2 == 0 :
c+=1
if c==len(arr) :
ans = max(arr)/2 - c
if ans%2 == 0 :
print ("Bob")
else :
print("Alice")
else :
ans = max(arr) - len(arr)
if ans%2 == 0 :
print ("Bob")
else... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. Du... | ```python
n = int(input())
arr = list(map( int , input().split()))
c = 0
for i in arr :
if i%2 == 0 :
c+=1
if c==len(arr) :
ans = max(arr)/2 - c
if ans%2 == 0 :
print ("Bob")
else :
print("Alice")
else :
ans = max(arr) - len(arr)
if ans%2 == 0 :
print ("Bob"... | 0 | |
376 | B | I.O.U. | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 0<=≤<=*m*<=≤<=104). The next *m* lines contain the debts. The *i*-th line contains three integers *a**i*,<=*b**i*,<=*c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*; 1<=≤<=*c**i*<=≤<=100), which mean that person *a**i* owes person *b**i* *c**i... | Print a single integer — the minimum sum of debts in the optimal rearrangement. | [
"5 3\n1 2 10\n2 3 1\n2 4 1\n",
"3 0\n",
"4 3\n1 2 1\n2 3 1\n3 1 1\n"
] | [
"10\n",
"0\n",
"0\n"
] | In the first sample, you can assume that person number 1 owes 8 rubles to person number 2, 1 ruble to person number 3 and 1 ruble to person number 4. He doesn't owe anybody else anything. In the end, the total debt equals 10.
In the second sample, there are no debts.
In the third sample, you can annul all the debts. | 1,000 | [
{
"input": "5 3\n1 2 10\n2 3 1\n2 4 1",
"output": "10"
},
{
"input": "3 0",
"output": "0"
},
{
"input": "4 3\n1 2 1\n2 3 1\n3 1 1",
"output": "0"
},
{
"input": "20 28\n1 5 6\n1 12 7\n1 13 4\n1 15 7\n1 20 3\n2 4 1\n2 15 6\n3 5 3\n3 8 10\n3 13 8\n3 20 6\n4 6 10\n4 12 8\n4 19 5\... | 1,629,459,430 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 77 | 6,963,200 | n,m=map(int,input().split())
d=dict()
for i in range(0,m):
a,b,c=map(int,input().split())
if a in d:
d[a]=d[a]+c
else:
d[a]=c
if b in d:
d[b]=d[b]-c
else:
d[b]=-c
print(abs(sum([i for i in d.values() if i<0]))) | Title: I.O.U.
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearran... | ```python
n,m=map(int,input().split())
d=dict()
for i in range(0,m):
a,b,c=map(int,input().split())
if a in d:
d[a]=d[a]+c
else:
d[a]=c
if b in d:
d[b]=d[b]-c
else:
d[b]=-c
print(abs(sum([i for i in d.values() if i<0])))
``` | 3 | |
168 | A | Wizards and Demonstration | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city... | The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to... | Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). | [
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] | [
"1\n",
"0\n",
"1108\n"
] | In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 1... | 500 | [
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
... | 1,474,723,572 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 124 | 0 | import math
if __name__ == '__main__':
n, x, y = str(input()).split()
n = int(n)
x = int(x)
y = int(y)
print(max(0, int(math.ceil(n * y / 100)) - x))
| Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n... | ```python
import math
if __name__ == '__main__':
n, x, y = str(input()).split()
n = int(n)
x = int(x)
y = int(y)
print(max(0, int(math.ceil(n * y / 100)) - x))
``` | 3 | |
297 | B | Fish Weight | PROGRAMMING | 1,600 | [
"constructive algorithms",
"greedy"
] | null | null | It is known that there are *k* fish species in the polar ocean, numbered from 1 to *k*. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the *i*-th type of fish be *w**i*, then 0<=<<=*w*1<=≤<=*w*2<=≤<=...<=≤<=*w**k* holds.
Polar bears Alice and Bob each have cau... | The first line contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of fish caught by Alice and Bob respectively, and the number of fish species.
The second line contains *n* integers each from 1 to *k*, the list of fish type caught by Alice. The third line contains *m* in... | Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. | [
"3 3 3\n2 2 2\n1 1 3\n",
"4 7 9\n5 2 7 3\n3 5 2 7 3 8 7\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, if *w*<sub class="lower-index">1</sub> = 1, *w*<sub class="lower-index">2</sub> = 2, *w*<sub class="lower-index">3</sub> = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5.
In the second sample, the fish that Alice caught is a subset of Bob's. Theref... | 500 | [
{
"input": "3 3 3\n2 2 2\n1 1 3",
"output": "YES"
},
{
"input": "4 7 9\n5 2 7 3\n3 5 2 7 3 8 7",
"output": "NO"
},
{
"input": "5 5 10\n8 2 8 5 9\n9 1 7 5 1",
"output": "YES"
},
{
"input": "7 7 10\n8 2 8 10 6 9 10\n2 4 9 5 6 2 5",
"output": "YES"
},
{
"input": "15 ... | 1,658,759,536 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 62 | 278 | 18,944,000 | def solve():
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
if n > m: return "YES"
if sum(a) > sum(b) or max(a) > max(b):
return "YES"
i, j = n - 1, m - 1
while i >= 0 and j >= 0:
... | Title: Fish Weight
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is known that there are *k* fish species in the polar ocean, numbered from 1 to *k*. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the *i*-th type of fish be *w**i... | ```python
def solve():
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
if n > m: return "YES"
if sum(a) > sum(b) or max(a) > max(b):
return "YES"
i, j = n - 1, m - 1
while i >= 0 and j >... | 3 | |
169 | A | Chores | PROGRAMMING | 800 | [
"sortings"
] | null | null | Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexit... | The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* ... | Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0. | [
"5 2 3\n6 2 3 100 1\n",
"7 3 4\n1 1 9 1 1 1 1\n"
] | [
"3\n",
"0\n"
] | In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4. | 500 | [
{
"input": "5 2 3\n6 2 3 100 1",
"output": "3"
},
{
"input": "7 3 4\n1 1 9 1 1 1 1",
"output": "0"
},
{
"input": "2 1 1\n10 2",
"output": "8"
},
{
"input": "2 1 1\n7 7",
"output": "0"
},
{
"input": "2 1 1\n1 1000000000",
"output": "999999999"
},
{
"inp... | 1,582,208,332 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 155 | 0 | n,a,b=list(map(int,input().split()))
t=list(map(int,input().split()))
if len(set(t))>=a+b:
print(max(a,b)+(n-(a+b)))
else:
print(0)
| Title: Chores
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of th... | ```python
n,a,b=list(map(int,input().split()))
t=list(map(int,input().split()))
if len(set(t))>=a+b:
print(max(a,b)+(n-(a+b)))
else:
print(0)
``` | 0 | |
673 | A | Bear and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order. | Print the number of minutes Limak will watch the game. | [
"3\n7 20 88\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"9\n15 20 30 40 50 60 70 80 90\n"
] | [
"35\n",
"15\n",
"90\n"
] | In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the w... | 500 | [
{
"input": "3\n7 20 88",
"output": "35"
},
{
"input": "9\n16 20 30 40 50 60 70 80 90",
"output": "15"
},
{
"input": "9\n15 20 30 40 50 60 70 80 90",
"output": "90"
},
{
"input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88",
... | 1,498,526,970 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 5,529,600 | # Description of the problem can be found at http://codeforces.com/problemset/problem/673/A
n = int(input())
l_n = list(x for x in map(int, input().split()))
l_n.append(90)
t = 0
for n in l_n:
if t + 15 < n:
print(t + 15)
quit()
else:
t = n
print(t) | Title: Bear and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Lim... | ```python
# Description of the problem can be found at http://codeforces.com/problemset/problem/673/A
n = int(input())
l_n = list(x for x in map(int, input().split()))
l_n.append(90)
t = 0
for n in l_n:
if t + 15 < n:
print(t + 15)
quit()
else:
t = n
print(t)
``` | 3 | |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,690,999,529 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 278 | 0 | n=int(input())
c=1
old=int(input())
for i in range(1,n):
s=int(input())
if old!=s:
old=s
c+=1
print(c) | Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
n=int(input())
c=1
old=int(input())
for i in range(1,n):
s=int(input())
if old!=s:
old=s
c+=1
print(c)
``` | 3 | |
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output"... | 1,694,261,469 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 62 | 0 | a = int(input())
b = list(map(int,input().split()))
r = set()
for i in range(a):
t = abs(b[i - 1] - b[i])
r.add(t)
for i in range(a):
t = abs(b[i - 1] - b[i])
if t == min(r):
y = b.index(b[i - 1]) + 1
j = b.index(b[i]) + 1
if y == j:
b.reverse()
... | Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So... | ```python
a = int(input())
b = list(map(int,input().split()))
r = set()
for i in range(a):
t = abs(b[i - 1] - b[i])
r.add(t)
for i in range(a):
t = abs(b[i - 1] - b[i])
if t == min(r):
y = b.index(b[i - 1]) + 1
j = b.index(b[i]) + 1
if y == j:
b.reverse()
... | 0 |
979 | B | Treasure Hunt | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination... | The first line contains an integer $n$ ($0 \leq n \leq 10^{9}$) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $10^{5}$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the lengt... | Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw". | [
"3\nKuroo\nShiro\nKatie\n",
"7\ntreasurehunt\nthreefriends\nhiCodeforces\n",
"1\nabcabc\ncbabac\nababca\n",
"15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE\n"
] | [
"Kuro\n",
"Shiro\n",
"Katie\n",
"Draw\n"
] | In the first example, after $3$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $5$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $4$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Th... | 1,000 | [
{
"input": "3\nKuroo\nShiro\nKatie",
"output": "Kuro"
},
{
"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces",
"output": "Shiro"
},
{
"input": "1\nabcabc\ncbabac\nababca",
"output": "Katie"
},
{
"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE",
"output": "Draw"
},
{... | 1,528,651,896 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 78 | 0 | n=int(input())
r=list()
for i in range(3):
r.append(list(input()))
l=len(r[0])
freq=[0,0,0]
res=[0,0,0]
for i in range(3):
vis=list()
for j in range(l):
if r[i][j] not in vis:
count=r[i].count(r[i][j])
if count>freq[i]:
freq[i]=count
maxfreq=0
f... | Title: Treasure Hunt
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friend... | ```python
n=int(input())
r=list()
for i in range(3):
r.append(list(input()))
l=len(r[0])
freq=[0,0,0]
res=[0,0,0]
for i in range(3):
vis=list()
for j in range(l):
if r[i][j] not in vis:
count=r[i].count(r[i][j])
if count>freq[i]:
freq[i]=count
ma... | 0 | |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
... | 1,512,153,088 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 374 | 5,632,000 | def Count(p):
k = 0
if p % 2 == 0:
k += 1
while p % 2 == 0:
p //= 2
i = 3
while i <= p:
if p % i == 0:
k += 1
while p % i == 0:
p //= i
i += 2
return k
n = int(input())
c = 0
for i in range(3, n + 1):
... | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
def Count(p):
k = 0
if p % 2 == 0:
k += 1
while p % 2 == 0:
p //= 2
i = 3
while i <= p:
if p % i == 0:
k += 1
while p % i == 0:
p //= i
i += 2
return k
n = int(input())
c = 0
for i in range(3, n... | 3.89601 |
735 | A | Ostap and Grasshopper | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The gr... | The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the correspondi... | If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes). | [
"5 2\n#G#T#\n",
"6 1\nT....G\n",
"7 3\nT..#..G\n",
"6 2\n..GT..\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a sin... | 500 | [
{
"input": "5 2\n#G#T#",
"output": "YES"
},
{
"input": "6 1\nT....G",
"output": "YES"
},
{
"input": "7 3\nT..#..G",
"output": "NO"
},
{
"input": "6 2\n..GT..",
"output": "NO"
},
{
"input": "2 1\nGT",
"output": "YES"
},
{
"input": "100 5\nG####.####.###... | 1,662,336,114 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 83 | 62 | 0 | inp = input().split(' ')
n = int(inp[0])
k = int(inp[1])
inp = input()
start = -1
end = -1
for i in range(len(inp)):
if inp[i] == 'G':
start = i
if inp[i] == 'T':
end = i
if start > end:
start, end = end, start
if (end - start) % k != 0:
print('NO')
exit()
for x in range(start, end, ... | Title: Ostap and Grasshopper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles.... | ```python
inp = input().split(' ')
n = int(inp[0])
k = int(inp[1])
inp = input()
start = -1
end = -1
for i in range(len(inp)):
if inp[i] == 'G':
start = i
if inp[i] == 'T':
end = i
if start > end:
start, end = end, start
if (end - start) % k != 0:
print('NO')
exit()
for x in range(st... | 3 | |
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
... | 1,670,473,866 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 88 | 109 | 13,516,800 | input()
a = list(map(int, input().split()))
mini = min(a)
maxi = max(a)
print(sum(mini < ai < maxi for ai in a))
| Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am... | ```python
input()
a = list(map(int, input().split()))
mini = min(a)
maxi = max(a)
print(sum(mini < ai < maxi for ai in a))
``` | 3 | |
779 | B | Weird Rounding | PROGRAMMING | 1,100 | [
"brute force",
"greedy"
] | null | null | Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For example, if *k*<==<=3, in the number 30020 it is enough to delete a single digit (2). In this case, t... | The only line of the input contains two integer numbers *n* and *k* (0<=≤<=*n*<=≤<=2<=000<=000<=000, 1<=≤<=*k*<=≤<=9).
It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. | Print *w* — the required minimal number of digits to erase. After removing the appropriate *w* digits from the number *n*, the result should have a value that is divisible by 10*k*. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). | [
"30020 3\n",
"100 9\n",
"10203049 2\n"
] | [
"1\n",
"2\n",
"3\n"
] | In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. | 1,000 | [
{
"input": "30020 3",
"output": "1"
},
{
"input": "100 9",
"output": "2"
},
{
"input": "10203049 2",
"output": "3"
},
{
"input": "0 1",
"output": "0"
},
{
"input": "0 9",
"output": "0"
},
{
"input": "100 2",
"output": "0"
},
{
"input": "102... | 1,490,245,061 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,608,000 | n,k=input ().split (); k = int (k); n=n [::-1];
for i in range (0,100) :
if n [:i].count ("0")>=k :
print (i);
break; | Title: Weird Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For e... | ```python
n,k=input ().split (); k = int (k); n=n [::-1];
for i in range (0,100) :
if n [:i].count ("0")>=k :
print (i);
break;
``` | 0 | |
312 | B | Archer | PROGRAMMING | 1,300 | [
"math",
"probabilities"
] | null | null | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will... | A single line contains four integers . | Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"1 2 1 2\n"
] | [
"0.666666666667"
] | none | 1,000 | [
{
"input": "1 2 1 2",
"output": "0.666666666667"
},
{
"input": "1 3 1 3",
"output": "0.600000000000"
},
{
"input": "1 3 2 3",
"output": "0.428571428571"
},
{
"input": "3 4 3 4",
"output": "0.800000000000"
},
{
"input": "1 2 10 11",
"output": "0.523809523810"
... | 1,465,374,049 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 4,608,000 | a,b,c,d = [int(x) for x in input().split()]
p1 = 1-(a/b)
p2 = 1-(c/d)
p = (a/b)/(a-p1*p2)
print (p) | Title: Archer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one w... | ```python
a,b,c,d = [int(x) for x in input().split()]
p1 = 1-(a/b)
p2 = 1-(c/d)
p = (a/b)/(a-p1*p2)
print (p)
``` | 0 | |
475 | A | Bayan Bus | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.
The event coordinator has a list of *k* participants who should be picked up at the airport. When a... | The only line of input contains integer *k*, (0<=≤<=*k*<=≤<=34), denoting the number of participants. | Print the figure of a bus with *k* passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six ... | [
"9\n",
"20\n"
] | [
"+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+\n",
"+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|... | none | 500 | [
{
"input": "9",
"output": "+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "20",
"output": "+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.... | 1,488,306,697 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 5,222,400 | # @Author: Justin Hershberger
# @Date: 28-02-2017
# @Filename: 475.py
# @Last modified by: Justin Hershberger
# @Last modified time: 28-02-2017
#Justin Hershberger
#Py3.5
import fileinput
if __name__ == '__main__':
num_args = 1
for arg in range(num_args):
ln=int(input())
# print(ln)
# ... | Title: Bayan Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.
The ... | ```python
# @Author: Justin Hershberger
# @Date: 28-02-2017
# @Filename: 475.py
# @Last modified by: Justin Hershberger
# @Last modified time: 28-02-2017
#Justin Hershberger
#Py3.5
import fileinput
if __name__ == '__main__':
num_args = 1
for arg in range(num_args):
ln=int(input())
# prin... | 0 | |
440 | A | Forgotten Episode | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to *n*.
The second line contains *n*<=-<=1 integer *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the numbers of episodes that Polycarpus has watch... | Print the number of the episode that Polycarpus hasn't watched. | [
"10\n3 8 10 1 7 9 6 5 2\n"
] | [
"4\n"
] | none | 500 | [
{
"input": "10\n3 8 10 1 7 9 6 5 2",
"output": "4"
},
{
"input": "5\n4 3 2 1",
"output": "5"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "2\n2",
"output": "1"
},
{
"input": "3\n1 2",
"output": "3"
},
{
"input": "3\n1 3",
"output": "2"
},
... | 1,559,908,695 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 186 | 7,372,800 | n = int(input())
a = list(map(int, input().split()))
a.sort()
k = 1
for i in range(n - 1):
if a[i] > k:
print(k)
break
k += 1
if k == n:
print(n)
| Title: Forgotten Episode
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*.
Polycarpus watches episo... | ```python
n = int(input())
a = list(map(int, input().split()))
a.sort()
k = 1
for i in range(n - 1):
if a[i] > k:
print(k)
break
k += 1
if k == n:
print(n)
``` | 3 | |
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,645,856,871 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | inp1 = int(input())
if inp1<3:
print(inp1//2)
else:
print(inp1//3)
| 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
inp1 = int(input())
if inp1<3:
print(inp1//2)
else:
print(inp1//3)
``` | 0 | |
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the en... | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18... | 1,663,141,240 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 0 | import math;
n, m = list(map(int, input().split(" ")));
c = list(map(int, input().split(" ")));
max = -1;
r = -1;
for i, v in enumerate(c):
x = math.ceil(v / m);
if x >= max:
max = x;
r = i+1;
print (r); | Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line ... | ```python
import math;
n, m = list(map(int, input().split(" ")));
c = list(map(int, input().split(" ")));
max = -1;
r = -1;
for i, v in enumerate(c):
x = math.ceil(v / m);
if x >= max:
max = x;
r = i+1;
print (r);
``` | 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,698,431,385 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | my_list = []
problem_number = int(input())
if 1 <= problem_number <= 1000:
for i in range(problem_number):
x, y, z = map(int, input().split())
if x + y + z >= 2:
my_list.append(1)
else:
my_list.append(0)
if 1 <= problem_number <= 1000:
print(sum(my_l... | 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
my_list = []
problem_number = int(input())
if 1 <= problem_number <= 1000:
for i in range(problem_number):
x, y, z = map(int, input().split())
if x + y + z >= 2:
my_list.append(1)
else:
my_list.append(0)
if 1 <= problem_number <= 1000:
prin... | 3 | |
757 | A | Gotta Catch Em' All! | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas... | Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*.
The string *s* contains lowercase and uppercase English letters, i.e. . | Output a single integer, the answer to the problem. | [
"Bulbbasaur\n",
"F\n",
"aBddulbasaurrgndgbualdBdsagaurrgndbb\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur". | 500 | [
{
"input": "Bulbbasaur",
"output": "1"
},
{
"input": "F",
"output": "0"
},
{
"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb",
"output": "2"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr",
"output": "5"
},
{
"input": "BBBBBBB... | 1,496,269,676 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | counter = {i: 0 for i in "Bulbbasaur"}
newspaper = input()
for c in newspaper:
if c in "Bulbbasaur":
counter[c] += 1
print(min(counter.values()))
| Title: Gotta Catch Em' All!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsess... | ```python
counter = {i: 0 for i in "Bulbbasaur"}
newspaper = input()
for c in newspaper:
if c in "Bulbbasaur":
counter[c] += 1
print(min(counter.values()))
``` | 0 | |
46 | A | Ball Game | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | A. Ball Game | 2 | 256 | A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle. | In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces. | [
"10\n",
"3\n"
] | [
"2 4 7 1 6 2 9 7 6\n",
"2 1\n"
] | none | 0 | [
{
"input": "10",
"output": "2 4 7 1 6 2 9 7 6"
},
{
"input": "3",
"output": "2 1"
},
{
"input": "4",
"output": "2 4 3"
},
{
"input": "5",
"output": "2 4 2 1"
},
{
"input": "6",
"output": "2 4 1 5 4"
},
{
"input": "7",
"output": "2 4 7 4 2 1"
},
... | 1,590,228,284 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 248 | 0 | n = int(input())
i = 1
k = 1
for j in range(n-1):
i += k
if i % n == 0:
print(i, end=" ")
else:
print(i % n, end=" ")
k += 1
| Title: Ball Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think... | ```python
n = int(input())
i = 1
k = 1
for j in range(n-1):
i += k
if i % n == 0:
print(i, end=" ")
else:
print(i % n, end=" ")
k += 1
``` | 0 |
625 | A | Guest From the Past | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plas... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers *a*, *b* and *c* (1<=≤<=*a*<=≤<=1018, 1<=≤<=*c*<=<<=*b*<=≤<=1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and t... | Print the only integer — maximum number of liters of kefir, that Kolya can drink. | [
"10\n11\n9\n8\n",
"10\n5\n6\n1\n"
] | [
"2\n",
"2\n"
] | In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he ... | 750 | [
{
"input": "10\n11\n9\n8",
"output": "2"
},
{
"input": "10\n5\n6\n1",
"output": "2"
},
{
"input": "2\n2\n2\n1",
"output": "1"
},
{
"input": "10\n3\n3\n1",
"output": "4"
},
{
"input": "10\n1\n2\n1",
"output": "10"
},
{
"input": "10\n2\n3\n1",
"outpu... | 1,631,275,510 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 52 | 109 | 20,172,800 | n = int(input())
a = int(input())
b = int(input())
c = int(input())
ans=0
if b-c<a:
ans=(n-c)//(b-c)
n-=ans*(b-c)
ans+=n//a
print(ans)
| Title: Guest From the Past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much mor... | ```python
n = int(input())
a = int(input())
b = int(input())
c = int(input())
ans=0
if b-c<a:
ans=(n-c)//(b-c)
n-=ans*(b-c)
ans+=n//a
print(ans)
``` | 0 | |
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,694,339,913 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 53 | 77 | 11,264,000 | digitToValMap = {
"1": 1,
"0": -1,
}
def process(nums: str) -> int:
prevRate = {0: -1}
rate = 0
maxLen = 0
for i, num in enumerate(nums):
rate += digitToValMap[num]
if rate in prevRate:
currLen = i - prevRate[rate]
maxLen = max(maxLen, currLen)
i... | 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
digitToValMap = {
"1": 1,
"0": -1,
}
def process(nums: str) -> int:
prevRate = {0: -1}
rate = 0
maxLen = 0
for i, num in enumerate(nums):
rate += digitToValMap[num]
if rate in prevRate:
currLen = i - prevRate[rate]
maxLen = max(maxLen, currLen)... | 3 | |
522 | A | Reposts | PROGRAMMING | 1,200 | [
"*special",
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the n... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and ... | Print a single integer — the maximum length of a repost chain. | [
"5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n",
"6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n",
"1\nSoMeStRaNgEgUe repos... | [
"6\n",
"2\n",
"2\n"
] | none | 500 | [
{
"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya",
"output": "6"
},
{
"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforc... | 1,674,889,590 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 102,400 | from collections import defaultdict
t = int(input())
graph = defaultdict(list)
for _ in range(t):
child,c,parent, = input().split()
first,second = [],[]
for c in child:
if c.isalpha():
first.append(c.upper())
else:
first.append(c)
for c in parent:
... | Title: Reposts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
... | ```python
from collections import defaultdict
t = int(input())
graph = defaultdict(list)
for _ in range(t):
child,c,parent, = input().split()
first,second = [],[]
for c in child:
if c.isalpha():
first.append(c.upper())
else:
first.append(c)
for c in par... | 3 | |
961 | A | Tetris | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
... | The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) — the length of the platform and the number of the squares.
The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) — column in which $i$-th square will appear. | Print one integer — the amount of points you will receive. | [
"3 9\n1 1 2 2 2 3 1 2 3\n"
] | [
"2\n"
] | In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$).
After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing... | 0 | [
{
"input": "3 9\n1 1 2 2 2 3 1 2 3",
"output": "2"
},
{
"input": "1 7\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "3 5\n1 1 1 2 3",
"output": "1"
},
{
"input": "4 6\n4 4 4 4 4 4",
"output": "0"
},
{
"input": "4 6\... | 1,661,101,003 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 61 | 0 | n, m = input().split()
n = int(n)
m = int(m)
numbers = [int(c) for c in input().split()]
min = m
for i in range(1,n+1):
aux = numbers.count(i)
if(aux < min):
min = aux
print(min)
| Title: Tetris
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bo... | ```python
n, m = input().split()
n = int(n)
m = int(m)
numbers = [int(c) for c in input().split()]
min = m
for i in range(1,n+1):
aux = numbers.count(i)
if(aux < min):
min = aux
print(min)
``` | 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,541,823,286 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 187 | 512,000 | import math
import sys
from bisect import bisect_right, bisect_left, insort_right
from collections import Counter, defaultdict
from heapq import heappop, heappush
from itertools import accumulate
from sys import stdout
R = lambda: map(int, input().split())
n, B = R()
arr = list(R())
o = 0
res = []
for 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
import math
import sys
from bisect import bisect_right, bisect_left, insort_right
from collections import Counter, defaultdict
from heapq import heappop, heappush
from itertools import accumulate
from sys import stdout
R = lambda: map(int, input().split())
n, B = R()
arr = list(R())
o = 0
res = [... | 3 | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,693,969,157 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 46 | 0 | m,n=map(int,input().split());a=0
while m<=n:m*=3;n*=2;a+=1
print(a) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
m,n=map(int,input().split());a=0
while m<=n:m*=3;n*=2;a+=1
print(a)
``` | 3 | |
597 | B | Restaurant | PROGRAMMING | 1,600 | [
"dp",
"greedy",
"sortings"
] | null | null | A restaurant received *n* orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the *i*-th order is characterized by two time values — the start time *l**i* and the finish time *r**i* (*l**i*<=≤<=*r**i*).
Restaurant management can accept and reject orders. What is the maximal... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=5·105) — number of orders. The following *n* lines contain integer values *l**i* and *r**i* each (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109). | Print the maximal number of orders that can be accepted. | [
"2\n7 11\n4 7\n",
"5\n1 2\n2 3\n3 4\n4 5\n5 6\n",
"6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8\n"
] | [
"1\n",
"3\n",
"2\n"
] | none | 1,000 | [
{
"input": "2\n7 11\n4 7",
"output": "1"
},
{
"input": "5\n1 2\n2 3\n3 4\n4 5\n5 6",
"output": "3"
},
{
"input": "6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8",
"output": "2"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "2\n4 6\n4 8",
"output": "1"
},
{
"inp... | 1,692,870,179 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 35 | 4,000 | 83,660,800 | n = int(input())
v = [list(map(int, input().split())) for i in range(n)]
mnl = 0
i = 0
while(i<n):
for j in range(i, n):
if (v[j][0] > mnl and v[j][1] < v[i][1]) or v[i][0] <= mnl:
v[j], v[i] = v[i], v[j]
if v[i][0] <= mnl:
break
mnl = v[i][1]
i += 1
print(i)
| Title: Restaurant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A restaurant received *n* orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the *i*-th order is characterized by two time values — the start time *l**i* and the finish time *r**... | ```python
n = int(input())
v = [list(map(int, input().split())) for i in range(n)]
mnl = 0
i = 0
while(i<n):
for j in range(i, n):
if (v[j][0] > mnl and v[j][1] < v[i][1]) or v[i][0] <= mnl:
v[j], v[i] = v[i], v[j]
if v[i][0] <= mnl:
break
mnl = v[i][1]
i += 1
pri... | 0 | |
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor... | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input"... | 1,454,756,360 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 124 | 0 | inp = int(input())
lista = list()
tup = tuple()
for i in range(inp):
lista.append(tuple(i for i in input().split()))
s = set(lista)
print (len(s)) | Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the specie... | ```python
inp = int(input())
lista = list()
tup = tuple()
for i in range(inp):
lista.append(tuple(i for i in input().split()))
s = set(lista)
print (len(s))
``` | 3.969 |
420 | A | Start Up | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out... | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | [
"AHA\n",
"Z\n",
"XO\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "AHA",
"output": "YES"
},
{
"input": "Z",
"output": "NO"
},
{
"input": "XO",
"output": "NO"
},
{
"input": "AAA",
"output": "YES"
},
{
"input": "AHHA",
"output": "YES"
},
{
"input": "BAB",
"output": "NO"
},
{
"input": "OMMMAAMMMO"... | 1,555,003,070 | 2,147,483,647 | Python 3 | OK | TESTS | 80 | 156 | 614,400 | mirralpha = ['A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y']
w = input()
rw = ''.join(reversed(w))
if rw == w:
valid = True
for i in list(rw):
isL = False
for j in mirralpha:
if(i == j):
isL = True
break
if(not isL):
valid = False
break
if(valid):
print("YES")
else:
print("NO")
... | Title: Start Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of ... | ```python
mirralpha = ['A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y']
w = input()
rw = ''.join(reversed(w))
if rw == w:
valid = True
for i in list(rw):
isL = False
for j in mirralpha:
if(i == j):
isL = True
break
if(not isL):
valid = False
break
if(valid):
print("YES")
else:
pri... | 3 | |
296 | A | Yaroslav and Permutations | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | 500 | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 53... | 1,667,620,628 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 436 | 20,684,800 | import itertools
import math
import threading
import time
from builtins import input, range
from math import gcd as gcd
import sys
from io import BytesIO, IOBase
import queue
import itertools
import collections
from heapq import heappop, heappush
import random
import os
from random import randint
import ... | Title: Yaroslav and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would... | ```python
import itertools
import math
import threading
import time
from builtins import input, range
from math import gcd as gcd
import sys
from io import BytesIO, IOBase
import queue
import itertools
import collections
from heapq import heappop, heappush
import random
import os
from random import randin... | 3 | |
920 | C | Swap Adjacent Elements | PROGRAMMING | 1,400 | [
"dfs and similar",
"greedy",
"math",
"sortings",
"two pointers"
] | null | null | You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<=1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. T... | The first line contains one integer *n* (2<=≤<=*n*<=≤<=200000) — the number of elements in the array.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=200000) — the elements of the array. Each integer from 1 to *n* appears exactly once.
The third line contains a string of *n*<=-<=1 char... | If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print YES. Otherwise, print NO. | [
"6\n1 2 5 3 4 6\n01110\n",
"6\n1 2 5 3 4 6\n01010\n"
] | [
"YES\n",
"NO\n"
] | In the first example you may swap *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, and then swap *a*<sub class="lower-index">4</sub> and *a*<sub class="lower-index">5</sub>. | 0 | [
{
"input": "6\n1 2 5 3 4 6\n01110",
"output": "YES"
},
{
"input": "6\n1 2 5 3 4 6\n01010",
"output": "NO"
},
{
"input": "6\n1 6 3 4 5 2\n01101",
"output": "NO"
},
{
"input": "6\n2 3 1 4 5 6\n01111",
"output": "NO"
},
{
"input": "4\n2 3 1 4\n011",
"output": "NO... | 1,602,664,370 | 2,147,483,647 | Python 3 | OK | TESTS | 139 | 467 | 14,336,000 |
n = int(input())
a = list(map(int,input().split()))
s = input()
set1 = set()
t = len(set1)
max1 = a[0]
min1 = a[0]
flag = 0
set1.add(a[0])
for i in range(n-1):
if s[i] == "1":
set1.add(a[i])
set1.add(a[i+1])
min1 = min(min1,a[i+1],a[i])
max1 = max(max1,a[i+1],a[i])
elif s[i] == "0"... | Title: Swap Adjacent Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<... | ```python
n = int(input())
a = list(map(int,input().split()))
s = input()
set1 = set()
t = len(set1)
max1 = a[0]
min1 = a[0]
flag = 0
set1.add(a[0])
for i in range(n-1):
if s[i] == "1":
set1.add(a[i])
set1.add(a[i+1])
min1 = min(min1,a[i+1],a[i])
max1 = max(max1,a[i+1],a[i])
elif s... | 3 | |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,695,261,000 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | import math
n = int(input())
max = -math.inf
cap = 0
for i in range(n):
a,b = map(int,input().split())
cap = cap - a + b
if cap > max:
max = cap
print(max) | Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
import math
n = int(input())
max = -math.inf
cap = 0
for i in range(n):
a,b = map(int,input().split())
cap = cap - a + b
if cap > max:
max = cap
print(max)
``` | 3 | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,618,669,273 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | s1=str(input())
Q=s1.count('Q')-1
A=s1.count('A')
print(Q*A) | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
s1=str(input())
Q=s1.count('Q')-1
A=s1.count('A')
print(Q*A)
``` | 0 | |
592 | A | PawnChess | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed... | The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'.
It's guaranteed that there will not be white pawns on the first row neither black pawns on the ... | Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board. | [
"........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n",
"..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n"
] | [
"A\n",
"B\n"
] | In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner. | 500 | [
{
"input": ".BB.B.B.\nB..B..B.\n.B.BB...\nBB.....B\nBBB....B\nB..BB...\nBB.B...B\n....WWW.",
"output": "B"
},
{
"input": "B.B.BB.B\nW.WWW.WW\n.WWWWW.W\nW.BB.WBW\n.W..BBWB\nBB.WWBBB\n.W.W.WWB\nWWW..WW.",
"output": "A"
},
{
"input": "BB..BB..\nBW.W.W.B\n..B.....\n.....BB.\n.B..B..B\n......... | 1,446,314,714 | 5,714 | PyPy 3 | OK | TESTS | 56 | 93 | 307,200 |
board = []
for i in range(8):
board.append(input().strip())
# r, c system
R = 8
C = 8
N = 8
def yieldColumns(board):
for i in range(8):
A = []
for j in range(8):
A.append(board[j][i])
yield A
def countDict(A):
d = {}
d['W'] = 0
d['B'] = 0
for l in A:
... | Title: PawnChess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of ... | ```python
board = []
for i in range(8):
board.append(input().strip())
# r, c system
R = 8
C = 8
N = 8
def yieldColumns(board):
for i in range(8):
A = []
for j in range(8):
A.append(board[j][i])
yield A
def countDict(A):
d = {}
d['W'] = 0
d['B'] = 0
for l i... | 3 | |
313 | A | Ilya and Bank Account | PROGRAMMING | 900 | [
"implementation",
"number theory"
] | null | null | Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow... | The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. | In a single line print an integer — the maximum state of the bank account that Ilya can get. | [
"2230\n",
"-10\n",
"-100003\n"
] | [
"2230\n",
"0\n",
"-10000\n"
] | In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | 500 | [
{
"input": "2230",
"output": "2230"
},
{
"input": "-10",
"output": "0"
},
{
"input": "-100003",
"output": "-10000"
},
{
"input": "544883178",
"output": "544883178"
},
{
"input": "-847251738",
"output": "-84725173"
},
{
"input": "423654797",
"output... | 1,696,092,857 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 47 | 154 | 0 | # CP Template 0.2
# Author: Mehrab (@to0th_less)
import sys
from math import gcd, sqrt
from itertools import combinations, permutations
# Constants
INF = float('inf')
MOD = 1000000007
# Faster Input Shortcut
def read_int():
return int(sys.stdin.readline().strip())
def read_ints():
return map... | Title: Ilya and Bank Account
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an... | ```python
# CP Template 0.2
# Author: Mehrab (@to0th_less)
import sys
from math import gcd, sqrt
from itertools import combinations, permutations
# Constants
INF = float('inf')
MOD = 1000000007
# Faster Input Shortcut
def read_int():
return int(sys.stdin.readline().strip())
def read_ints():
... | 3 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,609,355,975 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 218 | 0 | n = input
l = []
for i in range(int(n())):
l.append(n())
print(max(l, key=l.count)) | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
n = input
l = []
for i in range(int(n())):
l.append(n())
print(max(l, key=l.count))
``` | 3.9455 |
965 | A | Paper Airplanes | PROGRAMMING | 800 | [
"math"
] | null | null | To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people.... | The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. | Print a single integer — the minimum number of packs they should buy. | [
"5 3 2 3\n",
"5 3 100 1\n"
] | [
"4\n",
"5\n"
] | In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | 500 | [
{
"input": "5 3 2 3",
"output": "4"
},
{
"input": "5 3 100 1",
"output": "5"
},
{
"input": "10000 10000 1 1",
"output": "100000000"
},
{
"input": "1 1 10000 10000",
"output": "1"
},
{
"input": "300 300 21 23",
"output": "196"
},
{
"input": "300 2 37 51... | 1,525,012,364 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 93 | 7,065,600 | import math
k, s ,n,p = map(int, input().split())
f=math.ceil(((math.ceil(s/n))*k)/p)
print(f)
| Title: Paper Airplanes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several p... | ```python
import math
k, s ,n,p = map(int, input().split())
f=math.ceil(((math.ceil(s/n))*k)/p)
print(f)
``` | 3 | |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,667,471,203 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 46 | 1,091 | 17,203,200 | from itertools import accumulate
input()
v = list(map(int, input().split()))
u = sorted(v)
av = list(accumulate(v, initial=0))
au = list(accumulate(u, initial=0))
for _ in range(int(input())):
t, l, r = map(int, input().split())
a = av if t == 1 else au
print(a[r] - a[l - 1])
| Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
from itertools import accumulate
input()
v = list(map(int, input().split()))
u = sorted(v)
av = list(accumulate(v, initial=0))
au = list(accumulate(u, initial=0))
for _ in range(int(input())):
t, l, r = map(int, input().split())
a = av if t == 1 else au
print(a[r] - a[l - 1])
``` | 3 | |
928 | D | Autocompletion | PROGRAMMING | 1,900 | [
"*special",
"strings",
"trees"
] | null | null | Arcady is a copywriter. His today's task is to type up an already well-designed story using his favorite text editor.
Arcady types words, punctuation signs and spaces one after another. Each letter and each sign (including line feed) requires one keyboard click in order to be printed. Moreover, when Arcady has a non-e... | The only line contains Arcady's text, consisting only of lowercase latin letters, spaces, line feeds and the following punctuation signs: «.», «,», «?», «!», «'» and «-». The total amount of symbols doesn't exceed 3·105. It's guaranteed that all lines are non-empty. | Print a single integer — the minimum number of clicks. | [
"snow affects sports such as skiing, snowboarding, and snowmachine travel.\nsnowboarding is a recreational activity and olympic and paralympic sport.\n",
"'co-co-co, codeforces?!'\n",
"thun-thun-thunder, thunder, thunder\nthunder, thun-, thunder\nthun-thun-thunder, thunder\nthunder, feel the thunder\nlightning ... | [
"141\n",
"25\n",
"183\n"
] | In sample case one it's optimal to use autocompletion for the first instance of «snowboarding» after typing up «sn» and for the second instance of «snowboarding» after typing up «snowb». This will save 7 clicks.
In sample case two it doesn't matter whether to use autocompletion or not. | 2,250 | [
{
"input": "snow affects sports such as skiing, snowboarding, and snowmachine travel.\nsnowboarding is a recreational activity and olympic and paralympic sport.",
"output": "141"
},
{
"input": "'co-co-co, codeforces?!'",
"output": "25"
},
{
"input": "thun-thun-thunder, thunder, thunder\n... | 1,519,565,554 | 79,054 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 62 | 6,041,600 | import re
s = input()
splited = re.split('(\W+)', s)
words = []
signs = []
finish = []
for i in s:
if i.isalpha():
continue
signs.append(i)
endList = []
for part in splited:
if part == '':
splited.remove(part)
if part.isalpha():
words.append(part)
autoList = []
f... | Title: Autocompletion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arcady is a copywriter. His today's task is to type up an already well-designed story using his favorite text editor.
Arcady types words, punctuation signs and spaces one after another. Each letter and each sign (includ... | ```python
import re
s = input()
splited = re.split('(\W+)', s)
words = []
signs = []
finish = []
for i in s:
if i.isalpha():
continue
signs.append(i)
endList = []
for part in splited:
if part == '':
splited.remove(part)
if part.isalpha():
words.append(part)
autoLi... | 0 | |
260 | C | Balls and Boxes | PROGRAMMING | 1,700 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Little Vasya had *n* boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to *n* from left to right.
Once Vasya chose one of the boxes, let's assume that its number is *i*, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began pu... | The first line of the input contains two integers *n* and *x* (2<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=*n*), that represent the number of the boxes and the index of the box that got the last ball from Vasya, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, where integer *a**i*... | Print *n* integers, where the *i*-th one represents the number of balls in the box number *i* before Vasya starts acting. Separate the numbers in the output by spaces. If there are multiple correct solutions, you are allowed to print any of them. | [
"4 4\n4 3 1 6\n",
"5 2\n3 2 0 2 7\n",
"3 3\n2 3 1\n"
] | [
"3 2 5 4 ",
"2 1 4 1 6 ",
"1 2 3 "
] | none | 1,500 | [
{
"input": "4 4\n4 3 1 6",
"output": "3 2 5 4 "
},
{
"input": "5 2\n3 2 0 2 7",
"output": "2 1 4 1 6 "
},
{
"input": "3 3\n2 3 1",
"output": "1 2 3 "
},
{
"input": "10 3\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000... | 1,552,547,110 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | k,n = list(map(int,input().split()))
c = list(map(int,input().split()))
m = min(c)
mi = c.index(m)
coun = 0
for i in range(k):
coun +=m
c[i]= str(c[i]-(m))
if mi+1 >= n and k!=n:
for i in range(mi+1,k+n):
coun += 1
c[i%k]= str(int(c[i%k])-(1))
c[mi] = str(int(c[mi])+coun)
... | Title: Balls and Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya had *n* boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to *n* from left to right.
Once Vasya chose one of the boxes, let's assume that its number is *i*, took ... | ```python
k,n = list(map(int,input().split()))
c = list(map(int,input().split()))
m = min(c)
mi = c.index(m)
coun = 0
for i in range(k):
coun +=m
c[i]= str(c[i]-(m))
if mi+1 >= n and k!=n:
for i in range(mi+1,k+n):
coun += 1
c[i%k]= str(int(c[i%k])-(1))
c[mi] = str(int(c[mi]... | 0 | |
276 | C | Little Girl and Maximum Sum | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"implementation",
"sortings"
] | null | null | The little girl loves the problems on array queries very much.
One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)... | The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly.
The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements.
Each of ... | In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered.
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. | [
"3 3\n5 3 2\n1 2\n2 3\n1 3\n",
"5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n"
] | [
"25\n",
"33\n"
] | none | 1,500 | [
{
"input": "3 3\n5 3 2\n1 2\n2 3\n1 3",
"output": "25"
},
{
"input": "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3",
"output": "33"
},
{
"input": "34 21\n23 38 16 49 44 50 48 34 33 19 18 31 11 15 20 47 44 30 39 33 45 46 1 13 27 16 31 36 17 23 38 5 30 16\n8 16\n14 27\n8 26\n1 8\n5 6\n23 28\n4 33\n13 30\... | 1,674,114,908 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 44,441,600 | def findQueries(nums, queries):
length = len(nums)
prefix = [0] * (length + 1)
for x, y in queries:
prefix[x - 1] += 1
prefix[y] -= 1
sumVal = 0
temp = []
for i in range(length):
sumVal += prefix[i]
prefix[i] = sumVal
temp.append([prefix[i], i])... | Title: Little Girl and Maximum Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The little girl loves the problems on array queries very much.
One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1... | ```python
def findQueries(nums, queries):
length = len(nums)
prefix = [0] * (length + 1)
for x, y in queries:
prefix[x - 1] += 1
prefix[y] -= 1
sumVal = 0
temp = []
for i in range(length):
sumVal += prefix[i]
prefix[i] = sumVal
temp.append([pref... | 0 | |
16 | B | Burglar and Matches | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | B. Burglar and Matches | 0 | 64 | A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactl... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. | Output the only number — answer to the problem. | [
"7 3\n5 10\n2 5\n3 6\n",
"3 3\n1 3\n2 2\n3 1\n"
] | [
"62\n",
"7\n"
] | none | 0 | [
{
"input": "7 3\n5 10\n2 5\n3 6",
"output": "62"
},
{
"input": "3 3\n1 3\n2 2\n3 1",
"output": "7"
},
{
"input": "1 1\n1 2",
"output": "2"
},
{
"input": "1 2\n1 9\n1 6",
"output": "9"
},
{
"input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1",
"ou... | 1,620,300,963 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 8 | 92 | 6,963,200 | n,m=map(int,input().split())
a=[]
for i in range(m):
x,y=list(map(int,input().split()))
a.append([y,x])
a.sort(reverse=True)
sum=0
i=0
while(n!=0):
if a[i][1]<=n:
sum+=(a[i][1]*a[i][0])
n-=(a[i][1])
i+=1
else:
sum+=(a[i][0]*n)
n-=n
print(sum)
... | 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())
a=[]
for i in range(m):
x,y=list(map(int,input().split()))
a.append([y,x])
a.sort(reverse=True)
sum=0
i=0
while(n!=0):
if a[i][1]<=n:
sum+=(a[i][1]*a[i][0])
n-=(a[i][1])
i+=1
else:
sum+=(a[i][0]*n)
n-=n
print(... | -1 |
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,684,273,254 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 62 | 1,228,800 | import random
import string
n, k = [int(i) for i in input().split(" ")]
chars = random.sample(string.ascii_lowercase, k)
s = ""
for i in range(n):
s += chars[i%k]
print(s)
| 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
import random
import string
n, k = [int(i) for i in input().split(" ")]
chars = random.sample(string.ascii_lowercase, k)
s = ""
for i in range(n):
s += chars[i%k]
print(s)
``` | 3 | |
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i... | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 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 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 1,665,492,056 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n=int(input())
*x,=map(int,input().split())
if n-len(set(x))==0: print('1')
else: print(n-len(set(x))) | Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Po... | ```python
n=int(input())
*x,=map(int,input().split())
if n-len(set(x))==0: print('1')
else: print(n-len(set(x)))
``` | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.