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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
987 | B | High School: Become Human | PROGRAMMING | 1,100 | [
"math"
] | null | null | Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-cl... | On the only line of input there are two integers $x$ and $y$ ($1 \le x, y \le 10^{9}$). | If $x^y < y^x$, then print '<' (without quotes). If $x^y > y^x$, then print '>' (without quotes). If $x^y = y^x$, then print '=' (without quotes). | [
"5 8\n",
"10 3\n",
"6 6\n"
] | [
">\n",
"<\n",
"=\n"
] | In the first example $5^8 = 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 = 390625$, and $8^5 = 8 \cdot 8 \cdot 8 \cdot 8 \cdot 8 = 32768$. So you should print '>'.
In the second example $10^3 = 1000 < 3^{10} = 59049$.
In the third example $6^6 = 46656 = 6^6$. | 1,000 | [
{
"input": "5 8",
"output": ">"
},
{
"input": "10 3",
"output": "<"
},
{
"input": "6 6",
"output": "="
},
{
"input": "14 1",
"output": ">"
},
{
"input": "2 4",
"output": "="
},
{
"input": "987654321 123456987",
"output": "<"
},
{
"input": "... | 1,670,319,545 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 62 | 2,764,800 | x = int(input())
y = int(input())
xy = x**y
yx = y**x
if(xy==yx):
print("=")
elif(xy>yx):
print(">")
else:
print("<") | Title: High School: Become Human
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out tha... | ```python
x = int(input())
y = int(input())
xy = x**y
yx = y**x
if(xy==yx):
print("=")
elif(xy>yx):
print(">")
else:
print("<")
``` | -1 | |
471 | D | MUH and Cube Walls | PROGRAMMING | 1,800 | [
"string suffix structures",
"strings"
] | null | null | Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got hold of lots of wooden cubes somewhere. They started making cube towers by placing the cubes one on top of the other. They defined multiple towers standing in a line as a wall. A wall can consist of towers of di... | The first line contains two integers *n* and *w* (1<=≤<=*n*,<=*w*<=≤<=2·105) — the number of towers in the bears' and the elephant's walls correspondingly. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the heights of the towers in the bears' wall. The third line contains *w* integers *b**i* (1<=... | Print the number of segments in the bears' wall where Horace can "see an elephant". | [
"13 5\n2 4 5 5 4 3 2 2 2 3 3 2 1\n3 4 4 3 2\n"
] | [
"2"
] | The picture to the left shows Horace's wall from the sample, the picture to the right shows the bears' wall. The segments where Horace can "see an elephant" are in gray. | 2,000 | [
{
"input": "13 5\n2 4 5 5 4 3 2 2 2 3 3 2 1\n3 4 4 3 2",
"output": "2"
},
{
"input": "5 1\n8 71 1 24 2\n31",
"output": "5"
},
{
"input": "6 3\n2 2 2 2 2 2\n5 5 5",
"output": "4"
},
{
"input": "1 1\n576560149\n691846236",
"output": "1"
},
{
"input": "10 5\n5 10 8 1... | 1,417,301,039 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | n, w = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
for i in range(w-1):
b[i] = b[i] - b[i+1]
b = b[:-1]
for j in range(n-1):
a[j] = a[j]-a[j+1]
if j >= w-2:
if a[(j+2)-w:j+1] == b:
res += 1
print(res)
| Title: MUH and Cube Walls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got hold of lots of wooden cubes somewhere. They started making cube towers by placing the cubes one on top of ... | ```python
n, w = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
for i in range(w-1):
b[i] = b[i] - b[i+1]
b = b[:-1]
for j in range(n-1):
a[j] = a[j]-a[j+1]
if j >= w-2:
if a[(j+2)-w:j+1] == b:
res += 1
print(res)
`... | 0 | |
697 | B | Barnicle | PROGRAMMING | 1,400 | [
"brute force",
"implementation",
"math",
"strings"
] | null | null | Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.
Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance ... | The first and only line of input contains a single string of form *a*.*deb* where *a*, *d* and *b* are integers and *e* is usual character 'e' (0<=≤<=*a*<=≤<=9,<=0<=≤<=*d*<=<<=10100,<=0<=≤<=*b*<=≤<=100) — the scientific notation of the desired distance value.
*a* and *b* contain no leading zeros and *d* contains no... | Print the only real number *x* (the desired distance value) in the only line in its decimal notation.
Thus if *x* is an integer, print it's integer value without decimal part and decimal point and without leading zeroes.
Otherwise print *x* in a form of *p*.*q* such that *p* is an integer that have no leading zeroe... | [
"8.549e2\n",
"8.549e3\n",
"0.33e0\n"
] | [
"854.9\n",
"8549\n",
"0.33\n"
] | none | 1,000 | [
{
"input": "8.549e2",
"output": "854.9"
},
{
"input": "8.549e3",
"output": "8549"
},
{
"input": "0.33e0",
"output": "0.33"
},
{
"input": "1.31e1",
"output": "13.1"
},
{
"input": "1.038e0",
"output": "1.038"
},
{
"input": "8.25983e5",
"output": "825... | 1,611,725,066 | 2,366 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 307,200 | import math
a=input()
a=str(a)
b=0
for i in range(len(a)):
if a[i]=='e' :
b=i
break
s=''
for i in range(b):
s=s+a[i]
xiaoshu=float(s)
#print(xiaoshu)
zhishu=0
for i in range(b+1,len(a)):
zhishu=zhishu*10+int(a[i])
#print(zhishu)
for i in range(zhishu):
xiaoshu=xiaoshu*1... | Title: Barnicle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.
Barney asked the bar tender Carl abou... | ```python
import math
a=input()
a=str(a)
b=0
for i in range(len(a)):
if a[i]=='e' :
b=i
break
s=''
for i in range(b):
s=s+a[i]
xiaoshu=float(s)
#print(xiaoshu)
zhishu=0
for i in range(b+1,len(a)):
zhishu=zhishu*10+int(a[i])
#print(zhishu)
for i in range(zhishu):
xiaoshu... | 0 | |
293 | A | Weird Game | PROGRAMMING | 1,500 | [
"games",
"greedy"
] | null | null | Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game.
Roman leaves a word for each of them. Each word consists of 2·*n* binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves f... | The first line contains integer *n* (1<=≤<=*n*<=≤<=106). The second line contains string *s* — Yaroslav's word. The third line contains string *t* — Andrey's word.
It is guaranteed that both words consist of 2·*n* characters "0" and "1". | Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes. | [
"2\n0111\n0001\n",
"3\n110110\n001001\n",
"3\n111000\n000111\n",
"4\n01010110\n00101101\n",
"4\n01100000\n10010011\n"
] | [
"First\n",
"First\n",
"Draw\n",
"First\n",
"Second\n"
] | none | 500 | [
{
"input": "2\n0111\n0001",
"output": "First"
},
{
"input": "3\n110110\n001001",
"output": "First"
},
{
"input": "3\n111000\n000111",
"output": "Draw"
},
{
"input": "4\n01010110\n00101101",
"output": "First"
},
{
"input": "4\n01100000\n10010011",
"output": "Se... | 1,601,134,943 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 278 | 0 | import sys
import bisect
try:
fin = open('in')
except:
fin = sys.stdin
input = lambda: fin.readline().strip()
n=int(input())
a=list(map(int,input()))
b=list(map(int,input()))
r=[(b[i],a[i],i)for i in range(2*n)]
r.sort(reverse=True)
x=sum(r[i][1] for i in range(0,2*n,2))
y=sum(r[i][1] for i in range(1,2*n,2))
if x>y... | Title: Weird Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game.
Roman leaves a word for each of them. Each word consists of 2·... | ```python
import sys
import bisect
try:
fin = open('in')
except:
fin = sys.stdin
input = lambda: fin.readline().strip()
n=int(input())
a=list(map(int,input()))
b=list(map(int,input()))
r=[(b[i],a[i],i)for i in range(2*n)]
r.sort(reverse=True)
x=sum(r[i][1] for i in range(0,2*n,2))
y=sum(r[i][1] for i in range(1,2*n,... | 0 | |
52 | A | 123-sequence | PROGRAMMING | 900 | [
"implementation"
] | A. 123-sequence | 2 | 256 | There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3). | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | [
"9\n1 3 2 2 2 1 1 2 3\n"
] | [
"5\n"
] | In the example all the numbers equal to 1 and 3 should be replaced by 2. | 500 | [
{
"input": "9\n1 3 2 2 2 1 1 2 3",
"output": "5"
},
{
"input": "6\n3 3 2 2 1 3",
"output": "3"
},
{
"input": "12\n3 1 3 1 2 1 3 2 2 1 2 1",
"output": "7"
},
{
"input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2",
"output": "10"
},
{
"input": "2\n2 1",
"output": "1"
... | 1,660,611,025 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | #!/usr/bin/env/python
# -*- coding: utf-8 -*-
m = int(input())
n = list(map(int, input().split()))
cnt = [0] * 4
for c in n:
cnt[c] += 1
for k in [1,2,3]:
if cnt[k] >= m // 2:
print(m - cnt[k])
break
| Title: 123-sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each... | ```python
#!/usr/bin/env/python
# -*- coding: utf-8 -*-
m = int(input())
n = list(map(int, input().split()))
cnt = [0] * 4
for c in n:
cnt[c] += 1
for k in [1,2,3]:
if cnt[k] >= m // 2:
print(m - cnt[k])
break
``` | 0 |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,685,372,203 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 77 | 1,740,800 | n,d = map(int , input().split())
kid = 0
for _ in range(n):
a,b = input().split()
b = int(b)
if a =='+':
d+= b
else:
if d-b<0:
kid+=1
else:
d-=b
print(d,kid) | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
n,d = map(int , input().split())
kid = 0
for _ in range(n):
a,b = input().split()
b = int(b)
if a =='+':
d+= b
else:
if d-b<0:
kid+=1
else:
d-=b
print(d,kid)
``` | 3 | |
189 | A | Cut Ribbon | PROGRAMMING | 1,300 | [
"brute force",
"dp"
] | null | null | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon piece... | The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. | Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. | [
"5 5 3 2\n",
"7 5 5 2\n"
] | [
"2\n",
"2\n"
] | In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | 500 | [
{
"input": "5 5 3 2",
"output": "2"
},
{
"input": "7 5 5 2",
"output": "2"
},
{
"input": "4 4 4 4",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "4000 1 2 3",
"output": "4000"
},
{
"input": "4000 3 4 5",
"output": "1333"
},
... | 1,699,207,061 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | L=list(map(int,input().split()))
L1=[L[1],L[2],L[3]]
L2=[0]*(L[0]+1)
L1.sort()
if(L[0]<L1[0]):
print("0")
elif(L[0]>=L1[0] and L[0]<L1[1]):
if(L[0]%L1[0]==0):
print(L[0]//L1[0])
else:
print("0")
elif(L[0]>=L1[1] and L[0]<L1[2]):
for i in range(L1[0],L1[1])... | Title: Cut Ribbon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the... | ```python
L=list(map(int,input().split()))
L1=[L[1],L[2],L[3]]
L2=[0]*(L[0]+1)
L1.sort()
if(L[0]<L1[0]):
print("0")
elif(L[0]>=L1[0] and L[0]<L1[1]):
if(L[0]%L1[0]==0):
print(L[0]//L1[0])
else:
print("0")
elif(L[0]>=L1[1] and L[0]<L1[2]):
for i in range(L1... | 0 | |
733 | A | Grasshopper And the String | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ... | The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100. | Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels. | [
"ABABBBACFEYUKOTT\n",
"AAA\n"
] | [
"4",
"1"
] | none | 500 | [
{
"input": "ABABBBACFEYUKOTT",
"output": "4"
},
{
"input": "AAA",
"output": "1"
},
{
"input": "A",
"output": "1"
},
{
"input": "B",
"output": "2"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU",
... | 1,655,362,916 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 70 | 62 | 0 | string = list(input())
v = {"A", "E", "I", "O", "U", "Y"}
string.append("A")
answers = []
count = 0
for i in string:
if i in v:
count += 1
answers.append(count)
count = 0
else:
count += 1
print(max(answers))
| Title: Grasshopper And the String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far en... | ```python
string = list(input())
v = {"A", "E", "I", "O", "U", "Y"}
string.append("A")
answers = []
count = 0
for i in string:
if i in v:
count += 1
answers.append(count)
count = 0
else:
count += 1
print(max(answers))
``` | 3 | |
253 | A | Boys and Girls | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such th... | The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. | Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multi... | [
"3 3\n",
"4 2\n"
] | [
"GBGBGB\n",
"BGBGBB\n"
] | In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | 500 | [
{
"input": "3 3",
"output": "GBGBGB"
},
{
"input": "4 2",
"output": "BGBGBB"
},
{
"input": "5 5",
"output": "GBGBGBGBGB"
},
{
"input": "6 4",
"output": "BGBGBGBGBB"
},
{
"input": "100 1",
"output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB... | 1,613,551,956 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | boys,girls=list(map(int,input().split(" ")))
print("GB"*3) | Title: Boys and Girls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by n... | ```python
boys,girls=list(map(int,input().split(" ")))
print("GB"*3)
``` | -1 | |
474 | B | Worms | PROGRAMMING | 1,200 | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (... | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the f... | 1,000 | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,690,088,911 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 15 | 204,800 | c=int(input())
b=list(map(int,input().split()))
d=int(input())
a=list(map(int,input().split()))
for i in range(1,len(b)):
b[i]+=b[i-1]
def worm(a,b):
l=0
h=len(b)-1
while l<=h:
mid=(l+h)//2
if a==b[mid]:
break
elif a>b[mid]:
l=mid+1
... | Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers:... | ```python
c=int(input())
b=list(map(int,input().split()))
d=int(input())
a=list(map(int,input().split()))
for i in range(1,len(b)):
b[i]+=b[i-1]
def worm(a,b):
l=0
h=len(b)-1
while l<=h:
mid=(l+h)//2
if a==b[mid]:
break
elif a>b[mid]:
l=mid+1... | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,693,335,766 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 0 | def main():
from sys import stdin, stdout
n = int(stdin.readline())
even = 0
lodd=0
leven =0
s = map(int, stdin.readline().split())
i=0
for v in s:
if v % 2 == 0:
even = even + 1
leven=i
i=i+1
else:
even = even... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
def main():
from sys import stdin, stdout
n = int(stdin.readline())
even = 0
lodd=0
leven =0
s = map(int, stdin.readline().split())
i=0
for v in s:
if v % 2 == 0:
even = even + 1
leven=i
i=i+1
else:
e... | 3.977 |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,693,975,185 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | prev_year = int(input())
year = prev_year
while True:
l = []
year += 1
for i in str(year):
l.append(i)
if len(set(l)) == len(str(year)):
break
print(int(year)) | Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
prev_year = int(input())
year = prev_year
while True:
l = []
year += 1
for i in str(year):
l.append(i)
if len(set(l)) == len(str(year)):
break
print(int(year))
``` | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,588,802,837 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 310 | 20,172,800 | num = int(input())
fingers = list(map(int,input().split()))
ans = 0
options = [1, 2, 3, 4, 5]
back = num + 1
count = sum(fingers) - 1
for i in options:
if (count + i) % back != 0:
ans += 1
print(ans)
| Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
num = int(input())
fingers = list(map(int,input().split()))
ans = 0
options = [1, 2, 3, 4, 5]
back = num + 1
count = sum(fingers) - 1
for i in options:
if (count + i) % back != 0:
ans += 1
print(ans)
``` | 3 | |
157 | A | Game Outcome | PROGRAMMING | 800 | [
"brute force"
] | null | null | Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=30). Each of the following *n* lines contain *n* space-separated integers. The *j*-th number on the *i*-th line represents the number on the square that belongs to the *j*-th column and the *i*-th row on the board. All number on the board are integers from 1 to 100. | Print the single number — the number of the winning squares. | [
"1\n1\n",
"2\n1 2\n3 4\n",
"4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3\n"
] | [
"0\n",
"2\n",
"6\n"
] | In the first example two upper squares are winning.
In the third example three left squares in the both middle rows are winning: | 500 | [
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 2\n3 4",
"output": "2"
},
{
"input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3",
"output": "6"
},
{
"input": "2\n1 1\n1 1",
"output": "0"
},
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "4"
},
{
"inpu... | 1,592,977,044 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 218 | 6,963,200 | n = int(input())
l = []
for i in range(n):
m = list(map(int, input().split()))
l.append(m)
row = []
for i in range(n):
row.append(sum(l[i]))
col = []
for i in range(n):
a = 0
for j in range(n):
a += l[j][i]
col.append(a)
i, j = 0, 0
ans = 0
while i < n:
if j != n... | Title: Game Outcome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each s... | ```python
n = int(input())
l = []
for i in range(n):
m = list(map(int, input().split()))
l.append(m)
row = []
for i in range(n):
row.append(sum(l[i]))
col = []
for i in range(n):
a = 0
for j in range(n):
a += l[j][i]
col.append(a)
i, j = 0, 0
ans = 0
while i < n:
... | 3 | |
893 | C | Rumor | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Ove... | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
... | Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example ... | 0 | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n10000000... | 1,625,916,654 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 389 | 14,336,000 | # _
#####################################################################################################################
def createMutualFriendsGroups(pairs):
mutualFriendsGroups = []
for pair in pairs:
addPairToAGroup(mutualFriendsGroups, pair)
return mutualFriendsGroups
def addPair... | Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte... | ```python
# _
#####################################################################################################################
def createMutualFriendsGroups(pairs):
mutualFriendsGroups = []
for pair in pairs:
addPairToAGroup(mutualFriendsGroups, pair)
return mutualFriendsGroups
d... | -1 | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,596,709,598 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 108 | 6,656,000 | values = list(map(int,(input()).split()))
distance = (((values[1]-values[3])**2)+((values[2]-values[4])**2))**0.5
if distance%(2*values[0])==0:
print(int(distance/(2*values[0])))
else:
print(int(distance/(2*values[0]))+1) | Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
values = list(map(int,(input()).split()))
distance = (((values[1]-values[3])**2)+((values[2]-values[4])**2))**0.5
if distance%(2*values[0])==0:
print(int(distance/(2*values[0])))
else:
print(int(distance/(2*values[0]))+1)
``` | 3 | |
776 | A | A Serial Killer | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and t... | Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. | [
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"icm codeforces\n1\ncodeforces technex\n"
] | [
"ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n",
"icm codeforces\nicm technex\n"
] | In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears. | 500 | [
{
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"
},
{
"input": "icm codeforces\n1\ncodeforces technex",
"output": "icm codeforces\nicm technex"
},
{
"input": "a b\n3\na c\n... | 1,529,520,794 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 0 | name1, name2 = input().split()
n = int(input())
print(s)
for i in range(n):
print(name1, name2)
s1, s2 = input().split()
if name1 == s1:
name1 = s2
elif name1 == s2:
name1 = s1
elif name2 == s1:
name2 = s2
elif name2 == s2:
name2 = s1 | Title: A Serial Killer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The... | ```python
name1, name2 = input().split()
n = int(input())
print(s)
for i in range(n):
print(name1, name2)
s1, s2 = input().split()
if name1 == s1:
name1 = s2
elif name1 == s2:
name1 = s1
elif name2 == s1:
name2 = s2
elif name2 == s2:
name2 = s1
``` | -1 | |
716 | A | Crazy Computer | PROGRAMMING | 800 | [
"implementation"
] | null | null | ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denote... | Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. | [
"6 5\n1 3 8 14 19 20\n",
"6 1\n1 3 5 7 9 10\n"
] | [
"3",
"2"
] | The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be... | 500 | [
{
"input": "6 5\n1 3 8 14 19 20",
"output": "3"
},
{
"input": "6 1\n1 3 5 7 9 10",
"output": "2"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 7 12 13 14",
"output": "4"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "2"
},
{
... | 1,586,197,706 | 2,147,483,647 | PyPy 3 | OK | TESTS | 81 | 249 | 12,083,200 | n,c=map(int,input().split())
l=list(map(int,input().split()))
k=[]
for i in range(1,len(l)):
if l[i]-l[i-1]<=c:
k.append(l[i])
else:
k=[]
print(len(k)+1) | Title: Crazy Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *... | ```python
n,c=map(int,input().split())
l=list(map(int,input().split()))
k=[]
for i in range(1,len(l)):
if l[i]-l[i-1]<=c:
k.append(l[i])
else:
k=[]
print(len(k)+1)
``` | 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,616,069,398 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 154 | 0 | m,n=map(int,input().split())
d=(m*n)//2
print(d) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m,n=map(int,input().split())
d=(m*n)//2
print(d)
``` | 3.9615 |
918 | B | Radio Station | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name o... | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase... | Print *m* lines, the commands in the configuration file after Dustin did his task. | [
"2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n"
] | [
"block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n"
] | none | 1,000 | [
{
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main"
},
{
"input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.3... | 1,684,516,587 | 2,147,483,647 | PyPy 3 | OK | TESTS | 28 | 170 | 4,403,200 | # Write Python code in this online editor and run it.
i=input
n,m=map(int,i().split())
d=dict([i().split()[::-1] for _ in[0]*n])
for _ in[0]*m:a=i();print(a,'#'+d[a.split()[1][:-1]])
| Title: Radio Station
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server ... | ```python
# Write Python code in this online editor and run it.
i=input
n,m=map(int,i().split())
d=dict([i().split()[::-1] for _ in[0]*n])
for _ in[0]*m:a=i();print(a,'#'+d[a.split()[1][:-1]])
``` | 3 | |
189 | A | Cut Ribbon | PROGRAMMING | 1,300 | [
"brute force",
"dp"
] | null | null | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon piece... | The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. | Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. | [
"5 5 3 2\n",
"7 5 5 2\n"
] | [
"2\n",
"2\n"
] | In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | 500 | [
{
"input": "5 5 3 2",
"output": "2"
},
{
"input": "7 5 5 2",
"output": "2"
},
{
"input": "4 4 4 4",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "4000 1 2 3",
"output": "4000"
},
{
"input": "4000 3 4 5",
"output": "1333"
},
... | 1,675,157,252 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | x=str(input()).split()
b=[eval(i) for i in x]
if b[1] + b[2] + b[3]==b[0]:
print("3")
elif b[1]+b[2]==b[0]:
print("2")
elif b[2]+b[3]==b[0]:
print("2")
elif b[1]+b[3]==b[0]:
print("2")
else:
print("1") | Title: Cut Ribbon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the... | ```python
x=str(input()).split()
b=[eval(i) for i in x]
if b[1] + b[2] + b[3]==b[0]:
print("3")
elif b[1]+b[2]==b[0]:
print("2")
elif b[2]+b[3]==b[0]:
print("2")
elif b[1]+b[3]==b[0]:
print("2")
else:
print("1")
``` | 0 | |
515 | A | Drazil and Date | PROGRAMMING | 1,000 | [
"math"
] | null | null | Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to ... | You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line. | If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes).
Otherwise, print "Yes". | [
"5 5 11\n",
"10 15 25\n",
"0 5 1\n",
"0 0 2\n"
] | [
"No\n",
"Yes\n",
"No\n",
"Yes\n"
] | In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "5 5 11",
"output": "No"
},
{
"input": "10 15 25",
"output": "Yes"
},
{
"input": "0 5 1",
"output": "No"
},
{
"input": "0 0 2",
"output": "Yes"
},
{
"input": "999999999 999999999 2000000000",
"output": "Yes"
},
{
"input": "-606037695 9983201... | 1,592,206,579 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 | a, b, s = map(int, input().split())
c = abs(a) + abs(b)
if a == 0 and b == 0 and s % 2 == 0:
print("Yes")
elif c == s:
print("Yes")
elif c > s:
print("No")
elif (c % 2 == 0 and s % 2 == 0) or (c % 2 != 0 and s % 2 != 0) :
print("Yes")
else:
print("No") | Title: Drazil and Date
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit ... | ```python
a, b, s = map(int, input().split())
c = abs(a) + abs(b)
if a == 0 and b == 0 and s % 2 == 0:
print("Yes")
elif c == s:
print("Yes")
elif c > s:
print("No")
elif (c % 2 == 0 and s % 2 == 0) or (c % 2 != 0 and s % 2 != 0) :
print("Yes")
else:
print("No")
``` | 3 | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,694,344,406 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | n = int(input())
c = 0
l = list(map(int,input().split()))
def boredom(l):
L = l
if len(l)!=0:
zz = []
z = max(l)
y = L.remove(z)
x = z-1
for i in L:
if i !=x:
zz.append(i)
global c
c = c+z
return boredom(... | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
n = int(input())
c = 0
l = list(map(int,input().split()))
def boredom(l):
L = l
if len(l)!=0:
zz = []
z = max(l)
y = L.remove(z)
x = z-1
for i in L:
if i !=x:
zz.append(i)
global c
c = c+z
retur... | 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,660,379,320 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | s = input()
t = input()
u = t[::-1]
if s == u:
print("YES")
else:
print("NO") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
s = input()
t = input()
u = t[::-1]
if s == u:
print("YES")
else:
print("NO")
``` | 3.977 |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,559,412,974 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | num=int(input())
a=[]
even=[]
odd=[]
a=input().split()
for i in range(num):
if int(a[i])%2==0:
even.append(int(a[i]))
else:
odd.append(int(a[i]))
if len(odd)>len(even):
for i in even:
print(i)
else:
for i in odd:
print(i)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
num=int(input())
a=[]
even=[]
odd=[]
a=input().split()
for i in range(num):
if int(a[i])%2==0:
even.append(int(a[i]))
else:
odd.append(int(a[i]))
if len(odd)>len(even):
for i in even:
print(i)
else:
for i in odd:
print(i)
``` | 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,688,340,631 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 184 | 0 | a = input()
b = input()
d = 0
for j in range(len(b)):
if b[j] == a[d]:
d += 1
print(d + 1) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
a = input()
b = input()
d = 0
for j in range(len(b)):
if b[j] == a[d]:
d += 1
print(d + 1)
``` | 3 | |
161 | A | Dress'em in Vests! | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"greedy",
"two pointers"
] | null | null | The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line.
The Two-dimensional kingdom has a regular army of *n* people. Each soldier registered him... | The first input line contains four integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*<=≤<=105, 0<=≤<=*x*,<=*y*<=≤<=109) — the number of soldiers, the number of vests and two numbers that specify the soldiers' unpretentiousness, correspondingly.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i... | In the first line print a single integer *k* — the maximum number of soldiers equipped with bulletproof vests.
In the next *k* lines print *k* pairs, one pair per line, as "*u**i* *v**i*" (without the quotes). Pair (*u**i*, *v**i*) means that soldier number *u**i* must wear vest number *v**i*. Soldiers and vests are ... | [
"5 3 0 0\n1 2 3 3 4\n1 3 5\n",
"3 3 2 2\n1 5 9\n3 5 7\n"
] | [
"2\n1 1\n3 2\n",
"3\n1 1\n2 2\n3 3\n"
] | In the first sample you need the vests' sizes to match perfectly: the first soldier gets the first vest (size 1), the third soldier gets the second vest (size 3). This sample allows another answer, which gives the second vest to the fourth soldier instead of the third one.
In the second sample the vest size can differ... | 1,000 | [
{
"input": "5 3 0 0\n1 2 3 3 4\n1 3 5",
"output": "2\n1 1\n3 2"
},
{
"input": "3 3 2 2\n1 5 9\n3 5 7",
"output": "3\n1 1\n2 2\n3 3"
},
{
"input": "1 1 0 0\n1\n1",
"output": "1\n1 1"
},
{
"input": "1 1 0 0\n1\n2",
"output": "0"
},
{
"input": "2 3 1 4\n1 5\n1 2 2",
... | 1,540,916,001 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | n, m, x, y = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = j = 0
p = []
while i < n and j < m:
if (b[j] - x) <= a[i] <= (b[j] + y):
i += 1
j += 1
else:
i += 1
p.append([i, j])
print(j)
for a in p:
print(a[0], a[1]) | Title: Dress'em in Vests!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the s... | ```python
n, m, x, y = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = j = 0
p = []
while i < n and j < m:
if (b[j] - x) <= a[i] <= (b[j] + y):
i += 1
j += 1
else:
i += 1
p.append([i, j])
print(j)
for a in p:
print(a[0], a[1])
``` | 0 | |
592 | C | The Big Race | PROGRAMMING | 1,800 | [
"math"
] | null | null | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While ... | The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. | Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*. | [
"10 3 2\n",
"7 1 2\n"
] | [
"3/10\n",
"3/7\n"
] | In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. | 1,500 | [
{
"input": "10 3 2",
"output": "3/10"
},
{
"input": "7 1 2",
"output": "3/7"
},
{
"input": "1 1 1",
"output": "1/1"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 813 766",
"output": "765/94268"
},
{
"input": "262610 5583 4717",
... | 1,446,326,272 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 77 | 1,228,800 | '''input
10 3 2
'''
import fractions
import math
t,a,b=map(int,input().split())
if a==1 or b==1:
if a==1 and b==1:
print('1/1')
else:
print(str(t//max(a,b))+'/'+str(t))
else:
lcm=(a*b)//fractions.gcd(a,b)
num=t-(t//a+t//b-t//lcm)
print(str(num)+'/'+str(t)) | Title: The Big Race
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the... | ```python
'''input
10 3 2
'''
import fractions
import math
t,a,b=map(int,input().split())
if a==1 or b==1:
if a==1 and b==1:
print('1/1')
else:
print(str(t//max(a,b))+'/'+str(t))
else:
lcm=(a*b)//fractions.gcd(a,b)
num=t-(t//a+t//b-t//lcm)
print(str(num)+'/'+str(t))
``` | 0 | |
274 | A | k-Multiple Free Set | PROGRAMMING | 1,500 | [
"binary search",
"greedy",
"sortings"
] | null | null | A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<==<=*x*·*k*.
You're given a set of *n* distinct positive integers. Your task is to find th... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
All the numbers in the lines are separated by single spaces. | On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}. | [
"6 2\n2 3 6 5 4 10\n"
] | [
"3\n"
] | In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | 500 | [
{
"input": "6 2\n2 3 6 5 4 10",
"output": "3"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "6"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 1... | 1,603,190,474 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 0 | n,k=[int(x) for x in input().split()]
arr=[int(x) for x in input().split()]
arr.sort()
s=set()
for i in arr:
if i%k==0 and i//k in s:
s.remove(i//k)
s.add(i)
else:
s.add(i)
print(len(s))
| Title: k-Multiple Free Set
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, ... | ```python
n,k=[int(x) for x in input().split()]
arr=[int(x) for x in input().split()]
arr.sort()
s=set()
for i in arr:
if i%k==0 and i//k in s:
s.remove(i//k)
s.add(i)
else:
s.add(i)
print(len(s))
``` | 0 | |
429 | D | Tricky Function | PROGRAMMING | 2,200 | [
"data structures",
"divide and conquer",
"geometry"
] | null | null | Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the problem before the contest. Because he wants to make sure Iahub will be t... | The first line of input contains a single integer *n* (2<=≤<=*n*<=≤<=100000). Next line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (<=-<=104<=≤<=*a*[*i*]<=≤<=104). | Output a single integer — the value of *min**i*<=≠<=*j* *f*(*i*,<=*j*). | [
"4\n1 0 0 -1\n",
"2\n1 -1\n"
] | [
"1\n",
"2\n"
] | none | 2,000 | [
{
"input": "4\n1 0 0 -1",
"output": "1"
},
{
"input": "2\n1 -1",
"output": "2"
},
{
"input": "100\n-57 -64 83 76 80 27 60 76 -80 -56 52 72 -17 92 -96 87 41 -88 94 89 12 42 36 34 -100 -43 -42 62 3 87 -69 -6 -27 -59 -7 5 -90 -23 63 -87 -60 -92 -40 54 -16 -47 67 -64 10 33 -19 53 -7 -62 16 -... | 1,696,672,720 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 93 | 5,324,800 | import sys
import math
input = sys.stdin.readline
def dis(a, b):
return (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2
def solve(l, r):
if l == r:
return math.inf
if l + 1 == r:
return dis(points[l], points[r])
mid = (l + r) // 2
ans = min(solve(l, mid), solve(mid + 1, ... | Title: Tricky Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub,... | ```python
import sys
import math
input = sys.stdin.readline
def dis(a, b):
return (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2
def solve(l, r):
if l == r:
return math.inf
if l + 1 == r:
return dis(points[l], points[r])
mid = (l + r) // 2
ans = min(solve(l, mid), solve... | 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,629,219,408 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 109 | 20,172,800 | n = int(input())
arr = list(map(int, input().split()))
ans = 90
if arr[0] > 15:
ans = 15
elif arr[0] <= 15:
for i in range(len(arr) - 1):
diff = abs(arr[i] - arr[i+1])
if diff > 15:
ans = arr[i] + 15
break
print(ans)
| 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
n = int(input())
arr = list(map(int, input().split()))
ans = 90
if arr[0] > 15:
ans = 15
elif arr[0] <= 15:
for i in range(len(arr) - 1):
diff = abs(arr[i] - arr[i+1])
if diff > 15:
ans = arr[i] + 15
break
print(ans)
``` | 0 | |
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water... | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the f... | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 ... | 1,684,328,525 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | k = int(input())
l = list(map(int,input().split()))
l.sort(reverse = True)
c = 0
i = -1
for j in l:
if(k >= j):
i = j
j = 0
f(i>=0):
i = 0
while(c < k):
c+=l[j]
i+=1
print(i)
| Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya open... | ```python
k = int(input())
l = list(map(int,input().split()))
l.sort(reverse = True)
c = 0
i = -1
for j in l:
if(k >= j):
i = j
j = 0
f(i>=0):
i = 0
while(c < k):
c+=l[j]
i+=1
print(i)
``` | -1 | |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,618,853,641 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n=int(input())
x=list(map(int,input().split()))
for i in range(n):
if i==0 or i==n-1:
maxi=max(abs(x[i]-x[i+1]) ,abs(x[i]-x[i-1]))
mini=min(abs(x[i]-x[i+1]) ,abs(x[i]-x[i-1]))
else:
maxi=max(abs(x[i]-x[0]),abs(x[i]-x[n-1]))
mini=min(abs(x[i]-x[i-1]),abs(x[i]-x[i+1]))
... | Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
n=int(input())
x=list(map(int,input().split()))
for i in range(n):
if i==0 or i==n-1:
maxi=max(abs(x[i]-x[i+1]) ,abs(x[i]-x[i-1]))
mini=min(abs(x[i]-x[i+1]) ,abs(x[i]-x[i-1]))
else:
maxi=max(abs(x[i]-x[0]),abs(x[i]-x[n-1]))
mini=min(abs(x[i]-x[i-1]),abs(x[i]-x[i... | -1 | |
0 | none | none | none | 0 | [
"none"
] | null | null | The Little Elephant loves playing with arrays. He has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*.
Additionally the Little Elephant has *m* queries to the array, each query is characterised by a pair of integers *l**j* and *r**j* (1<=≤<=*l**j... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the size of array *a* and the number of queries to it. The next line contains *n* space-separated positive integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109). Next *m* lines contain descriptions of queries, one per line. T... | In *m* lines print *m* integers — the answers to the queries. The *j*-th line should contain the answer to the *j*-th query. | [
"7 2\n3 1 2 2 3 3 7\n1 7\n3 4\n"
] | [
"3\n1\n"
] | none | 0 | [
{
"input": "7 2\n3 1 2 2 3 3 7\n1 7\n3 4",
"output": "3\n1"
},
{
"input": "6 6\n1 2 2 3 3 3\n1 2\n2 2\n1 3\n2 4\n4 6\n1 6",
"output": "1\n0\n2\n1\n1\n3"
},
{
"input": "1 2\n1\n1 1\n1 1",
"output": "1\n1"
},
{
"input": "1 1\n1000000000\n1 1",
"output": "0"
}
] | 1,645,269,107 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 4,000 | 8,089,600 | max_number = 100001
ne, nq = [int(x) for x in input().split()]
count = [0] * (max_number+1)
array = [0]
array.extend([int(x) for x in input().split()])
for i in range(1, ne+1):
index = array[i]
if index < max_number:
count[index] += 1
left = [0]
right = [0]
for i in range(nq):
x, y = [int(x) for... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves playing with arrays. He has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*.
Additionally the Little Elephant has *m* queries to t... | ```python
max_number = 100001
ne, nq = [int(x) for x in input().split()]
count = [0] * (max_number+1)
array = [0]
array.extend([int(x) for x in input().split()])
for i in range(1, ne+1):
index = array[i]
if index < max_number:
count[index] += 1
left = [0]
right = [0]
for i in range(nq):
x, y = [... | 0 | |
772 | A | Voltage Keepsake | PROGRAMMING | 1,800 | [
"binary search",
"math"
] | null | null | You have *n* devices that you want to use simultaneously.
The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-th device currently has *b**i* units of power stored. All devices can store an arbitrary amount of pow... | The first line contains two integers, *n* and *p* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*p*<=≤<=109) — the number of devices and the power of the charger.
This is followed by *n* lines which contain two integers each. Line *i* contains the integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100<=000) — the power of the dev... | If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4.
Namely, let's assume that your answer is *a* and the answer of the jury is *b*. The chec... | [
"2 1\n2 2\n2 1000\n",
"1 100\n1 1\n",
"3 5\n4 3\n5 2\n6 1\n"
] | [
"2.0000000000",
"-1\n",
"0.5000000000"
] | In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to char... | 500 | [
{
"input": "2 1\n2 2\n2 1000",
"output": "2.0000000000"
},
{
"input": "1 100\n1 1",
"output": "-1"
},
{
"input": "3 5\n4 3\n5 2\n6 1",
"output": "0.5000000000"
},
{
"input": "1 1\n1 87",
"output": "-1"
},
{
"input": "1 1\n100 77",
"output": "0.7777777778"
},... | 1,492,362,966 | 6,066 | Python 3 | OK | TESTS | 94 | 576 | 16,281,600 | from math import inf
n, p = [int(x) for x in input().split()]
l = []
for i in range(n):
a, b = [int(x) for x in input().split()]
l.append((a, b, b/a))
l.sort(key=lambda x: x[2])
asum = 0
bsum = 0
sumt = 0
for i in range(n):
a0, b0, _ = l[i]
c1 = inf if i == n-1 else l[i+1][2]
asum += a0... | Title: Voltage Keepsake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *n* devices that you want to use simultaneously.
The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-... | ```python
from math import inf
n, p = [int(x) for x in input().split()]
l = []
for i in range(n):
a, b = [int(x) for x in input().split()]
l.append((a, b, b/a))
l.sort(key=lambda x: x[2])
asum = 0
bsum = 0
sumt = 0
for i in range(n):
a0, b0, _ = l[i]
c1 = inf if i == n-1 else l[i+1][2]
... | 3 | |
245 | A | System Administrator | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x... | In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format. | [
"2\n1 5 5\n2 6 4\n",
"3\n1 0 10\n2 0 10\n1 10 0\n"
] | [
"LIVE\nLIVE\n",
"LIVE\nDEAD\n"
] | Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to t... | 0 | [
{
"input": "2\n1 5 5\n2 6 4",
"output": "LIVE\nLIVE"
},
{
"input": "3\n1 0 10\n2 0 10\n1 10 0",
"output": "LIVE\nDEAD"
},
{
"input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9",
"output": "DEAD\nLIVE"
},
{
"input": "11\n1 8 2\n1 6 4\n1 9 1\n1... | 1,586,684,239 | 2,147,483,647 | PyPy 3 | OK | TESTS | 13 | 342 | 1,433,600 | t = int(input())
a, b, am, bm = 0, 0, 0, 0
for i in range(t):
ti, x, y = [int(x) for x in input().split(' ')]
if ti == 1:
am += 10
a += x
else:
bm += 10
b += x
if a / am >= 0.5: print('LIVE')
else: print('DEAD')
if b / bm >= 0.5: print('LIVE')
else: print('DEAD')
| Title: System Administrator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping co... | ```python
t = int(input())
a, b, am, bm = 0, 0, 0, 0
for i in range(t):
ti, x, y = [int(x) for x in input().split(' ')]
if ti == 1:
am += 10
a += x
else:
bm += 10
b += x
if a / am >= 0.5: print('LIVE')
else: print('DEAD')
if b / bm >= 0.5: print('LIVE')
else: print('DEAD')
``` | 3 | |
79 | B | Colorful Field | PROGRAMMING | 1,400 | [
"implementation",
"sortings"
] | B. Colorful Field | 2 | 256 | Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in f... | In the first line there are four positive integers *n*,<=*m*,<=*k*,<=*t* (1<=≤<=*n*<=≤<=4·104,<=1<=≤<=*m*<=≤<=4·104,<=1<=≤<=*k*<=≤<=103,<=1<=≤<=*t*<=≤<=103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in ... | For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. | [
"4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1\n"
] | [
"Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots\n"
] | The sample corresponds to the figure in the statement. | 1,000 | [
{
"input": "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1",
"output": "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots"
},
{
"input": "2 3 2 2\n1 1\n2 2\n2 1\n2 2",
"output": "Grapes\nWaste"
},
{
"input": "31 31 31 4\n4 9\n16 27\n11 29\n8 28\n11 2\n10 7\n22 6\n1 25\n14 8... | 1,628,611,297 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 154 | 6,963,200 | n,m,k,t=map(int,input().split())
plant=['Grapes','Carrots','Kiwis']
waste=[0]*(n*m)
for i in range(0,k):
x,y=map(int,input().split())
waste[(x-1)*m+(y-1)]=1
for i in range(0,t):
x,y=map(int,input().split())
index=(x-1)*m+(y-1)
if waste[index]==1 :
print("Waste")
... | Title: Colorful Field
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
... | ```python
n,m,k,t=map(int,input().split())
plant=['Grapes','Carrots','Kiwis']
waste=[0]*(n*m)
for i in range(0,k):
x,y=map(int,input().split())
waste[(x-1)*m+(y-1)]=1
for i in range(0,t):
x,y=map(int,input().split())
index=(x-1)*m+(y-1)
if waste[index]==1 :
print("W... | -1 |
11 | A | Increasing Sequence | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least... | The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | 0 | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
... | 1,696,832,723 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 184 | 2,867,200 | t = int(input())
for ___ in range(t):
n = int(input())
a = list(map(int, input().split()))
m = max(a)
ans = []
j = 1
i = 0
while len(ans) < n and i < n:
if j == a[i]:
j += 1
else:
ans.append(j)
i += 1
j += 1
w... | Title: Increasing Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*... | ```python
t = int(input())
for ___ in range(t):
n = int(input())
a = list(map(int, input().split()))
m = max(a)
ans = []
j = 1
i = 0
while len(ans) < n and i < n:
if j == a[i]:
j += 1
else:
ans.append(j)
i += 1
j +... | -1 |
548 | A | Mike and Fax | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages ... | The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000).
The second line contains integer *k* (1<=≤<=*k*<=≤<=1000). | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | [
"saba\n2\n",
"saddastavvat\n2\n"
] | [
"NO\n",
"YES\n"
] | Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | 500 | [
{
"input": "saba\n2",
"output": "NO"
},
{
"input": "saddastavvat\n2",
"output": "YES"
},
{
"input": "aaaaaaaaaa\n3",
"output": "NO"
},
{
"input": "aaaaaa\n3",
"output": "YES"
},
{
"input": "abaacca\n2",
"output": "NO"
},
{
"input": "a\n1",
"output"... | 1,672,270,070 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 46 | 0 | s = input()
n = int(input())
if len(s)%n != 0:
print("NO")
exit()
c = len(s)//n
for i in range(0, len(s), c):
if s[i:i+c] != s[i:i+c][::-1]:
print("NO")
exit()
print("YES")
| Title: Mike and Fax
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure ... | ```python
s = input()
n = int(input())
if len(s)%n != 0:
print("NO")
exit()
c = len(s)//n
for i in range(0, len(s), c):
if s[i:i+c] != s[i:i+c][::-1]:
print("NO")
exit()
print("YES")
``` | 3 | |
710 | D | Two Arithmetic Progressions | PROGRAMMING | 2,500 | [
"math",
"number theory"
] | null | null | You are given two arithmetic progressions: *a*1*k*<=+<=*b*1 and *a*2*l*<=+<=*b*2. Find the number of integers *x* such that *L*<=≤<=*x*<=≤<=*R* and *x*<==<=*a*1*k*'<=+<=*b*1<==<=*a*2*l*'<=+<=*b*2, for some integers *k*',<=*l*'<=≥<=0. | The only line contains six integers *a*1,<=*b*1,<=*a*2,<=*b*2,<=*L*,<=*R* (0<=<<=*a*1,<=*a*2<=≤<=2·109,<=<=-<=2·109<=≤<=*b*1,<=*b*2,<=*L*,<=*R*<=≤<=2·109,<=*L*<=≤<=*R*). | Print the desired number of integers *x*. | [
"2 0 3 3 5 21\n",
"2 4 3 0 6 17\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "2 0 3 3 5 21",
"output": "3"
},
{
"input": "2 4 3 0 6 17",
"output": "2"
},
{
"input": "2 0 4 2 -39 -37",
"output": "0"
},
{
"input": "1 9 3 11 49 109",
"output": "20"
},
{
"input": "3 81 5 72 -1761 501",
"output": "28"
},
{
"input": "8 -89... | 1,622,052,449 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vl vector<ll>
#define vi vector<int>
#define pb push_back
#define loop(i,a,b) for(ll i =a; i<b; ++i)
#define loop1(i,a,b) for(ll i=a; i>b; --i)
#define ff first
#define ss second
const ll mod = 1e9 + 7;
int dx[]={1,0,-1,0};
in... | Title: Two Arithmetic Progressions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arithmetic progressions: *a*1*k*<=+<=*b*1 and *a*2*l*<=+<=*b*2. Find the number of integers *x* such that *L*<=≤<=*x*<=≤<=*R* and *x*<==<=*a*1*k*'<=+<=*b*1<==<=*a*2*l*'<=+<=*b*2, for some i... | ```python
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vl vector<ll>
#define vi vector<int>
#define pb push_back
#define loop(i,a,b) for(ll i =a; i<b; ++i)
#define loop1(i,a,b) for(ll i=a; i>b; --i)
#define ff first
#define ss second
const ll mod = 1e9 + 7;
int dx[]={1,0,... | -1 | |
447 | B | DZY Loves Strings | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to in... | The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. | Print a single integer — the largest possible value of the resulting string DZY could get. | [
"abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
] | [
"41\n"
] | In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | 1,000 | [
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "41"
},
{
"input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453",
"output": "29978"
},
{
"input": "ajeeseerqnpaujubmajpibxrccazaawetyw... | 1,531,338,827 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 109 | 0 | s = input()
k = int(input())
w = list(map(int, input().split()))
idx = w.index(max(w))
s += chr(ord('a')+idx)*k
res = 0
for i in range(len(s)):
idx = ord(s[i])-ord('a')
res += (i+1)*w[idx]
print(res)
| Title: DZY Loves Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the str... | ```python
s = input()
k = int(input())
w = list(map(int, input().split()))
idx = w.index(max(w))
s += chr(ord('a')+idx)*k
res = 0
for i in range(len(s)):
idx = ord(s[i])-ord('a')
res += (i+1)*w[idx]
print(res)
``` | 3 | |
302 | A | Eugeny and Array | PROGRAMMING | 800 | [
"implementation"
] | null | null | Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of a... | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print *m* integers — the responses to Eugene's queries in the order they occur in the input. | [
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n"
] | [
"0\n1\n0\n",
"0\n1\n0\n1\n0\n"
] | none | 500 | [
{
"input": "2 3\n1 -1\n1 1\n1 2\n2 2",
"output": "0\n1\n0"
},
{
"input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5",
"output": "0\n1\n0\n1\n0"
},
{
"input": "3 3\n1 1 1\n2 2\n1 1\n1 1",
"output": "0\n0\n0"
},
{
"input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1",
"output": "... | 1,633,833,180 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 733 | 17,920,000 | I = lambda: map(int, input().split())
_, m = I()
A = list(I())
x, y = 2*A.count(-1), 2*A.count(1)
B = []
for _ in range(m):
L, R = I()
k = R-L+1
B.append(1 - (k%2 or x<k or y<k))
print(*B) | Title: Eugeny and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (... | ```python
I = lambda: map(int, input().split())
_, m = I()
A = list(I())
x, y = 2*A.count(-1), 2*A.count(1)
B = []
for _ in range(m):
L, R = I()
k = R-L+1
B.append(1 - (k%2 or x<k or y<k))
print(*B)
``` | 3 | |
508 | A | Pasha and Pixels | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choos... | The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i*... | If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0. | [
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n",
"5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n"
] | [
"4\n",
"5\n",
"0\n"
] | none | 500 | [
{
"input": "2 2 4\n1 1\n1 2\n2 1\n2 2",
"output": "4"
},
{
"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1",
"output": "5"
},
{
"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2",
"output": "0"
},
{
"input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3",
... | 1,697,636,391 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n,m,k=map(int,input().split())
field=[(m+2)*[0] for _ in range(n+2)]
def check(a,b):
if field[a][b+1] and field[a+1][b] and field[a+1][b+1]:
return True
if field[a][b-1] and field[a+1][b-1] and field[a+1][b]:
return True
if field[a-1][b] and field[a-1][b+1] and field[a][b+1]:
... | Title: Pasha and Pixels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row ... | ```python
n,m,k=map(int,input().split())
field=[(m+2)*[0] for _ in range(n+2)]
def check(a,b):
if field[a][b+1] and field[a+1][b] and field[a+1][b+1]:
return True
if field[a][b-1] and field[a+1][b-1] and field[a+1][b]:
return True
if field[a-1][b] and field[a-1][b+1] and field[a][b+... | -1 | |
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number ... | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25"... | 1,488,478,819 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 62 | 4,608,000 | a,b = map(int,input().split(' '))
if a == b or abs(a-b) == 1:
print ('YES')
else:
print ('NO') | Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has so... | ```python
a,b = map(int,input().split(' '))
if a == b or abs(a-b) == 1:
print ('YES')
else:
print ('NO')
``` | 0 | |
405 | A | Gravity Flip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is... | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. | Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. | [
"4\n3 2 1 2\n",
"3\n2 3 8\n"
] | [
"1 2 2 3 \n",
"2 3 8 \n"
] | The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not ... | 500 | [
{
"input": "4\n3 2 1 2",
"output": "1 2 2 3 "
},
{
"input": "3\n2 3 8",
"output": "2 3 8 "
},
{
"input": "5\n2 1 2 1 2",
"output": "1 1 2 2 2 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n4 3",
"output": "3 4 "
},
{
"input": "6\n100 40 60 20... | 1,695,115,399 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 62 | 0 | import math
import sys
input=sys.stdin.readline
def main():
n=int(input())
a=list(map(int,input().split()))
a.sort()
print(*a)
# for _ in range(int(input())):
main() | Title: Gravity Flip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the bo... | ```python
import math
import sys
input=sys.stdin.readline
def main():
n=int(input())
a=list(map(int,input().split()))
a.sort()
print(*a)
# for _ in range(int(input())):
main()
``` | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,638,102,088 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | t=input()
a=[x for x in t if x>='A' and x<='Z']
b=[x for x in t if x>='a'and x<='z']
if len(a)>len(b):
t=t.upper()
else:
t=t.lower()
print(t) | 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
t=input()
a=[x for x in t if x>='A' and x<='Z']
b=[x for x in t if x>='a'and x<='z']
if len(a)>len(b):
t=t.upper()
else:
t=t.lower()
print(t)
``` | 3.969 |
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmos... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where ... | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You... | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7... | 1,659,973,878 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 10,342,400 | s = input()
n = int(s[:s.find(" ")])
m = int(s[s.find(" ")+1:])
a = []
b = []
for i in range(n):
s = input()
a.append(int(s[:s.find(" ")]))
b.append(int(s[s.find(" ") + 1:]))
for i in range(n-1):
for j in range(n-1, i+1, -1):
if a[j] < a[j-1]:
a[j], a[j-1] = a[j-1], a[j]
... | Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain ... | ```python
s = input()
n = int(s[:s.find(" ")])
m = int(s[s.find(" ")+1:])
a = []
b = []
for i in range(n):
s = input()
a.append(int(s[:s.find(" ")]))
b.append(int(s[s.find(" ") + 1:]))
for i in range(n-1):
for j in range(n-1, i+1, -1):
if a[j] < a[j-1]:
a[j], a[j-1] = a[j... | 0 | |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line co... | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,693,408,200 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 58 | 93 | 13,516,800 | n, b, d = map(int, input().split())
A = list(map(int,input().split()))
summ = 0
answer = 0
for i in A:
if i<=b:
summ+=i
if summ>d:
summ = 0
answer +=1
print (answer)
| Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
n, b, d = map(int, input().split())
A = list(map(int,input().split()))
summ = 0
answer = 0
for i in A:
if i<=b:
summ+=i
if summ>d:
summ = 0
answer +=1
print (answer)
``` | 3 | |
431 | B | Shower Line | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks.
There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory... | The input consists of five lines, each line contains five space-separated integers: the *j*-th number in the *i*-th line shows *g**ij* (0<=≤<=*g**ij*<=≤<=105). It is guaranteed that *g**ii*<==<=0 for all *i*.
Assume that the students are numbered from 1 to 5. | Print a single integer — the maximum possible total happiness of the students. | [
"0 0 0 0 9\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n7 0 0 0 0\n",
"0 43 21 18 2\n3 0 21 11 65\n5 2 0 1 4\n54 62 12 0 99\n87 64 81 33 0\n"
] | [
"32\n",
"620\n"
] | In the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals: | 1,500 | [
{
"input": "0 0 0 0 9\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n7 0 0 0 0",
"output": "32"
},
{
"input": "0 43 21 18 2\n3 0 21 11 65\n5 2 0 1 4\n54 62 12 0 99\n87 64 81 33 0",
"output": "620"
},
{
"input": "0 4 2 4 9\n6 0 2 5 0\n2 5 0 6 3\n6 3 3 0 10\n0 3 1 3 0",
"output": "63"
},
{
... | 1,666,963,629 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 62 | 0 | from itertools import permutations
from sys import stdin,stdout
input=stdin.readline
def print(*args, end='\n', sep=' ') -> None:
stdout.write(sep.join(map(str, args)) + end)
a=[1,2,3,4,5] ; arr=[] ; ans=0 ; pet=list(permutations(a,5))
for i in range(5):
arr.append(list(map(int,input().split())))
for ... | Title: Shower Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks.
There is only one shower and there are multiple students who wish to have a shower ... | ```python
from itertools import permutations
from sys import stdin,stdout
input=stdin.readline
def print(*args, end='\n', sep=' ') -> None:
stdout.write(sep.join(map(str, args)) + end)
a=[1,2,3,4,5] ; arr=[] ; ans=0 ; pet=list(permutations(a,5))
for i in range(5):
arr.append(list(map(int,input().split())... | 3 | |
978 | B | File Name | PROGRAMMING | 800 | [
"greedy",
"strings"
] | null | null | You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia... | The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name.
The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name. | Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. | [
"6\nxxxiii\n",
"5\nxxoxx\n",
"10\nxxxxxxxxxx\n"
] | [
"1\n",
"0\n",
"8\n"
] | In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters. | 0 | [
{
"input": "6\nxxxiii",
"output": "1"
},
{
"input": "5\nxxoxx",
"output": "0"
},
{
"input": "10\nxxxxxxxxxx",
"output": "8"
},
{
"input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "98"
},
{
... | 1,655,615,063 | 2,147,483,647 | Python 3 | OK | TESTS | 13 | 31 | 0 | THRESHOLD = 3
def solve():
n = int(input())
s = input().strip()
x_num = 0
total_del_num = 0
for c in s:
if c == 'x':
x_num += 1
if x_num >= THRESHOLD:
total_del_num += 1
else:
x_num = 0
print(total_del_num)
solve()
... | Title: File Name
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin let... | ```python
THRESHOLD = 3
def solve():
n = int(input())
s = input().strip()
x_num = 0
total_del_num = 0
for c in s:
if c == 'x':
x_num += 1
if x_num >= THRESHOLD:
total_del_num += 1
else:
x_num = 0
print(total_del_num)
solve(... | 3 | |
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,511,492,206 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 5,632,000 | n=int(input())
q=[int(i) for i in input().split()]
num=sorted(q)
result=[]
b=int(len(num))
for i in range(b):
t=num[0]*(i+2)
result.append(t)
num.remove(num[0])
print(int(sum(result)-max(q))) | 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())
q=[int(i) for i in input().split()]
num=sorted(q)
result=[]
b=int(len(num))
for i in range(b):
t=num[0]*(i+2)
result.append(t)
num.remove(num[0])
print(int(sum(result)-max(q)))
``` | 0 | |
911 | A | Nearest Minimums | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. | The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times. | Print the only number — distance between two nearest minimums in the array. | [
"2\n3 3\n",
"3\n5 6 5\n",
"9\n2 1 3 5 4 1 2 3 1\n"
] | [
"1\n",
"2\n",
"3\n"
] | none | 0 | [
{
"input": "2\n3 3",
"output": "1"
},
{
"input": "3\n5 6 5",
"output": "2"
},
{
"input": "9\n2 1 3 5 4 1 2 3 1",
"output": "3"
},
{
"input": "6\n4 6 7 8 6 4",
"output": "5"
},
{
"input": "2\n1000000000 1000000000",
"output": "1"
},
{
"input": "42\n1 1 ... | 1,555,595,061 | 2,147,483,647 | Python 3 | OK | TESTS | 140 | 217 | 8,908,800 | N = int(input())
a= []
line = input().strip().split()
for j in range(N):
a.append(int(line[j]))
m = min(a)
ml = N
isFirst = True
first, sec = 0,0
for i in range(N):
if m == a[i]:
if isFirst:
first = i
sec = i
isFirst = False
else:
... | Title: Nearest Minimums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
I... | ```python
N = int(input())
a= []
line = input().strip().split()
for j in range(N):
a.append(int(line[j]))
m = min(a)
ml = N
isFirst = True
first, sec = 0,0
for i in range(N):
if m == a[i]:
if isFirst:
first = i
sec = i
isFirst = False
else:
... | 3 | |
195 | B | After Training | PROGRAMMING | 1,300 | [
"data structures",
"implementation",
"math"
] | null | null | After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to *m*, correspondingly... | The first line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of balls and baskets, correspondingly. | Print *n* numbers, one per line. The *i*-th line must contain the number of the basket for the *i*-th ball. | [
"4 3\n",
"3 1\n"
] | [
"2\n1\n3\n2\n",
"1\n1\n1\n"
] | none | 1,000 | [
{
"input": "4 3",
"output": "2\n1\n3\n2"
},
{
"input": "3 1",
"output": "1\n1\n1"
},
{
"input": "10 3",
"output": "2\n1\n3\n2\n1\n3\n2\n1\n3\n2"
},
{
"input": "6 5",
"output": "3\n2\n4\n1\n5\n3"
},
{
"input": "2 6",
"output": "3\n4"
},
{
"input": "5 2"... | 1,649,265,352 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 342 | 11,161,600 | n,m=map(int,input().split())
if m==1:
for i in range(n):
print(1)
else:
i=m//2 if m%2==0 else m//2+1
j=i+1
start=1
flag=False
first=True
while start<=n:
if first and m%2:
print(i)
i-=1
first=False
start+=1
... | Title: After Training
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are posi... | ```python
n,m=map(int,input().split())
if m==1:
for i in range(n):
print(1)
else:
i=m//2 if m%2==0 else m//2+1
j=i+1
start=1
flag=False
first=True
while start<=n:
if first and m%2:
print(i)
i-=1
first=False
start+... | 3 | |
92 | B | Binary Number | PROGRAMMING | 1,300 | [
"greedy"
] | B. Binary Number | 1 | 256 | Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divide... | The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106. | Print the required number of actions. | [
"1\n",
"1001001\n",
"101110\n"
] | [
"0\n",
"12\n",
"8\n"
] | Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide... | 1,000 | [
{
"input": "1",
"output": "0"
},
{
"input": "1001001",
"output": "12"
},
{
"input": "101110",
"output": "8"
},
{
"input": "11",
"output": "3"
},
{
"input": "11110001101",
"output": "16"
},
{
"input": "101010100100111100011111001111100001010101111110101... | 1,684,332,030 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 9,932,800 | def pw(x, n):
ret = 1
while n > 0:
if n & 1:
ret *= x
x *= x
n >>= 1
return ret
def solve():
s = input()
p, base = 0, 1
for i in range(len(s)-1, -1, -1):
if s[i] == '1':
p += base
base *= 2
cn = 0
while p !... | Title: Binary Number
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to ... | ```python
def pw(x, n):
ret = 1
while n > 0:
if n & 1:
ret *= x
x *= x
n >>= 1
return ret
def solve():
s = input()
p, base = 0, 1
for i in range(len(s)-1, -1, -1):
if s[i] == '1':
p += base
base *= 2
cn = 0
... | 0 |
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,591,116,986 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 248 | 0 | import sys
input = lambda: sys.stdin.readline().strip("\r\n")
d = {"N": (0, 1),
"S": (0, -1),
"E": (1, 0),
"W": (-1, 0)
}
t, sx, sy, ex, ey = map(int, input().split())
directions = list(input())
x_diff = ex - sx
y_diff = ey - sy
req_x = "E"
req_y = "N"
if x_diff < 0:
req_x = "W... | 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
import sys
input = lambda: sys.stdin.readline().strip("\r\n")
d = {"N": (0, 1),
"S": (0, -1),
"E": (1, 0),
"W": (-1, 0)
}
t, sx, sy, ex, ey = map(int, input().split())
directions = list(input())
x_diff = ex - sx
y_diff = ey - sy
req_x = "E"
req_y = "N"
if x_diff < 0:
... | 0 | |
352 | B | Jeff and Periods | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces. | In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in th... | [
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] | [
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] | In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | 1,000 | [
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"outpu... | 1,652,645,845 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 808 | 39,628,800 | import sys
import os
from collections import Counter, defaultdict, deque
from heapq import heapify, heappush, heappop
from functools import lru_cache
from math import floor, ceil, sqrt, gcd
from string import ascii_lowercase
from math import gcd
from bisect import bisect_left, bisect, bisect_right
def __pe... | Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
-... | ```python
import sys
import os
from collections import Counter, defaultdict, deque
from heapq import heapify, heappush, heappop
from functools import lru_cache
from math import floor, ceil, sqrt, gcd
from string import ascii_lowercase
from math import gcd
from bisect import bisect_left, bisect, bisect_right
... | 3 | |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,643,637,234 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | import math
a = int(input())
b = int(input())
n = int(input())
c = 0
while True:
if (c%2 == 0):
if n < math.gcd(a,n):
print(1)
break
n -= math.gcd(a,n)
elif (c%2 != 0):
if n < math.gcd(b,n):
print(0)
break
n -= math.g... | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
import math
a = int(input())
b = int(input())
n = int(input())
c = 0
while True:
if (c%2 == 0):
if n < math.gcd(a,n):
print(1)
break
n -= math.gcd(a,n)
elif (c%2 != 0):
if n < math.gcd(b,n):
print(0)
break
n... | -1 | |
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,378,231,103 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | import sys
f = sys.stdin
# f = open("input.txt", "r")
f.readline()
a = [i.strip() for i in f.read().split("\n")]
g = list(dict.fromkeys(a))
if a.count(g[0]) > a.count(g[1]):
print(g[0])
else:
print(g[1]) | 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
import sys
f = sys.stdin
# f = open("input.txt", "r")
f.readline()
a = [i.strip() for i in f.read().split("\n")]
g = list(dict.fromkeys(a))
if a.count(g[0]) > a.count(g[1]):
print(g[0])
else:
print(g[1])
``` | 0 |
569 | B | Inventory | PROGRAMMING | 1,200 | [
"greedy",
"math"
] | null | null | Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything.
During an audit, you were surprised to find out that the... | The first line contains a single integer *n* — the number of items (1<=≤<=*n*<=≤<=105).
The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the initial inventory numbers of the items. | Print *n* numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them. | [
"3\n1 3 2\n",
"4\n2 2 3 3\n",
"1\n2\n"
] | [
"1 3 2 \n",
"2 1 3 4 \n",
"1 \n"
] | In the first test the numeration is already a permutation, so there is no need to change anything.
In the second test there are two pairs of equal numbers, in each pair you need to replace one number.
In the third test you need to replace 2 by 1, as the numbering should start from one. | 1,000 | [
{
"input": "3\n1 3 2",
"output": "1 3 2 "
},
{
"input": "4\n2 2 3 3",
"output": "2 1 3 4 "
},
{
"input": "1\n2",
"output": "1 "
},
{
"input": "3\n3 3 1",
"output": "3 2 1 "
},
{
"input": "5\n1 1 1 1 1",
"output": "1 2 3 4 5 "
},
{
"input": "5\n5 3 4 4 ... | 1,572,669,806 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 358 | 7,680,000 | n=int(input())
a=list(map(int,input().split()))
s=set(a)
l=list(filter(lambda x: x not in s,[i for i in range(1,n+1)]))
j=0
for i in range(n):
if 1<=a[i]<=n and a[i] in s:
s.remove(a[i])
else:
a[i]=l[j]
j+=1
print(*a) | Title: Inventory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numb... | ```python
n=int(input())
a=list(map(int,input().split()))
s=set(a)
l=list(filter(lambda x: x not in s,[i for i in range(1,n+1)]))
j=0
for i in range(n):
if 1<=a[i]<=n and a[i] in s:
s.remove(a[i])
else:
a[i]=l[j]
j+=1
print(*a)
``` | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,684,594,034 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | # 71A
n = int(input())
for i in range(n):
word = str(input())
length = len(word)
if length > 10:
word = word[0] + str(length-2) + word[-1]
print(word) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
# 71A
n = int(input())
for i in range(n):
word = str(input())
length = len(word)
if length > 10:
word = word[0] + str(length-2) + word[-1]
print(word)
``` | 3.977 |
350 | A | TL | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running ... | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1... | If there is a valid TL value, print it. Otherwise, print -1. | [
"3 6\n4 5 2\n8 9 6 10 7 11\n",
"3 1\n3 4 5\n6\n"
] | [
"5",
"-1\n"
] | none | 500 | [
{
"input": "3 6\n4 5 2\n8 9 6 10 7 11",
"output": "5"
},
{
"input": "3 1\n3 4 5\n6",
"output": "-1"
},
{
"input": "2 5\n45 99\n49 41 77 83 45",
"output": "-1"
},
{
"input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43... | 1,602,140,343 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 22 | 280 | 0 | n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
if max(a)<min(b):
if min(a)*2<max(a) and min(a)*2<min(b):
print(max(a))
elif min(a)*2>max(a) and min(a)*2<min(b):
print(min(a)*2)
else:
print(-1)
else:
print... | Title: TL
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Val... | ```python
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
if max(a)<min(b):
if min(a)*2<max(a) and min(a)*2<min(b):
print(max(a))
elif min(a)*2>max(a) and min(a)*2<min(b):
print(min(a)*2)
else:
print(-1)
else:
... | 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,691,532,454 | 2,147,483,647 | Python 3 | OK | TESTS | 8 | 46 | 1,126,400 | from math import gcd
t = int(input())
sides = list(map(int, input().split()))
for n in sides:
lcm = (4 * n * (n + 1)) // gcd(4 * n, n + 1)
print(lcm // (n + 1) + 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
from math import gcd
t = int(input())
sides = list(map(int, input().split()))
for n in sides:
lcm = (4 * n * (n + 1)) // gcd(4 * n, n + 1)
print(lcm // (n + 1) + 1)
``` | 3 | |
609 | A | USB Flash Drives | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. | The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabyt... | Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. | [
"3\n5\n2\n1\n3\n",
"3\n6\n2\n3\n2\n",
"2\n5\n5\n10\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | 0 | [
{
"input": "3\n5\n2\n1\n3",
"output": "2"
},
{
"input": "3\n6\n2\n3\n2",
"output": "3"
},
{
"input": "2\n5\n5\n10",
"output": "1"
},
{
"input": "5\n16\n8\n1\n3\n4\n9",
"output": "2"
},
{
"input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100",
"output": "2"
... | 1,620,635,721 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 77 | 6,963,200 | n = int(input())
m = int(input())
a = []
for i in range(n):
a.append(int(input()))
a.sort(reverse=True)
sum = [0]
for i in range(0,n):
sum.append(sum[i] + a[i])
#print(sum)
for i in range(1,n+1):
if sum[i] >= m:
print(i)
exit()
1
| Title: USB Flash Drives
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of... | ```python
n = int(input())
m = int(input())
a = []
for i in range(n):
a.append(int(input()))
a.sort(reverse=True)
sum = [0]
for i in range(0,n):
sum.append(sum[i] + a[i])
#print(sum)
for i in range(1,n+1):
if sum[i] >= m:
print(i)
exit()
1
``` | 3 | |
552 | A | Vanya and Table | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.
In this table, Vanya chose *n* rectangles with sides that go along borders of squares (some rectangles probably occur mu... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of rectangles.
Each of the following *n* lines contains four integers *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1<=≤<=*x*2<=≤<=100, 1<=≤<=*y*1<=≤<=*y*2<=≤<=100), where *x*1 and *y*1 are the number of the column and row of the lower left cell and *x*2 and *... | In a single line print the sum of all values in the cells of the table. | [
"2\n1 1 2 3\n2 2 3 3\n",
"2\n1 1 3 3\n1 1 3 3\n"
] | [
"10\n",
"18\n"
] | Note to the first sample test:
Values of the table in the first three rows and columns will be as follows:
121
121
110
So, the sum of values will be equal to 10.
Note to the second sample test:
Values of the table in the first three rows and columns will be as follows:
222
222
222
So, the sum of values will ... | 500 | [
{
"input": "2\n1 1 2 3\n2 2 3 3",
"output": "10"
},
{
"input": "2\n1 1 3 3\n1 1 3 3",
"output": "18"
},
{
"input": "5\n4 11 20 15\n7 5 12 20\n10 8 16 12\n7 5 12 15\n2 2 20 13",
"output": "510"
},
{
"input": "5\n4 11 20 20\n6 11 20 16\n5 2 19 15\n11 3 18 15\n3 2 14 11",
"o... | 1,527,169,065 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 93 | 0 | n, s = int(input()), 0
for i in range(n):
x1, y1, x2, y2 = [int(x) for x in input().split()]
s += (abs(x1 - x2) + 1) * (abs(y1 - y2) + 1)
print(s)
| Title: Vanya and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.
In this table, Vany... | ```python
n, s = int(input()), 0
for i in range(n):
x1, y1, x2, y2 = [int(x) for x in input().split()]
s += (abs(x1 - x2) + 1) * (abs(y1 - y2) + 1)
print(s)
``` | 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,658,076,110 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 102 | 62 | 0 | a=input()
b=input()
for i in range(len(a)):
print(int((bin(int(a[i])+int(b[i]))[2:]))%10,end="") | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
a=input()
b=input()
for i in range(len(a)):
print(int((bin(int(a[i])+int(b[i]))[2:]))%10,end="")
``` | 3.9845 |
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th... | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"inp... | 1,697,511,372 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 30 | 0 | n,k=map(int,input().split())
h=list(map(int,input().split()))
height=[]
for i in range(n-2):
height.append(h[i]+h[i+1]+h[i+2])
a=height.index(min(height))
print(a+1) | Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ... | ```python
n,k=map(int,input().split())
h=list(map(int,input().split()))
height=[]
for i in range(n-2):
height.append(h[i]+h[i+1]+h[i+2])
a=height.index(min(height))
print(a+1)
``` | -1 | |
29 | D | Ant on the Tree | PROGRAMMING | 2,000 | [
"constructive algorithms",
"dfs and similar",
"trees"
] | D. Ant on the Tree | 2 | 256 | Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too.
An ant stands at the root of some tree. He sees that there are *n* vertexes in the tree, and they are connected by *n*<=-<=1 edges so that there is a path between any pair ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=300) — amount of vertexes in the tree. Next *n*<=-<=1 lines describe edges. Each edge is described with two integers — indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has numbe... | If the required route doesn't exist, output -1. Otherwise, output 2*n*<=-<=1 numbers, describing the route. Every time the ant comes to a vertex, output it's index. | [
"3\n1 2\n2 3\n3\n",
"6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3\n",
"6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6\n"
] | [
"1 2 3 2 1 ",
"1 2 4 5 4 6 4 2 1 3 1 ",
"-1\n"
] | none | 2,000 | [
{
"input": "3\n1 2\n2 3\n3",
"output": "1 2 3 2 1 "
},
{
"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3",
"output": "1 2 4 5 4 6 4 2 1 3 1 "
},
{
"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6",
"output": "-1"
},
{
"input": "10\n8 10\n2 1\n7 5\n5 4\n6 10\n2 3\n3 10\n2 9\n7 2\n6 9 4... | 1,570,648,959 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 248 | 512,000 | #TO MAKE THE PROGRAM FAST
''' ---------------------------------------------------------------------------------------------------- '''
import sys
from collections import *
input = sys.stdin.readline
sys.setrecursionlimit(100000)
''' -------------------------------------------------------------------------------------... | Title: Ant on the Tree
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too.
An ant stands at the root of some tree. He sees that there are *n* vertexes... | ```python
#TO MAKE THE PROGRAM FAST
''' ---------------------------------------------------------------------------------------------------- '''
import sys
from collections import *
input = sys.stdin.readline
sys.setrecursionlimit(100000)
''' ---------------------------------------------------------------------------... | 0 |
814 | A | An abandoned sentiment from past | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"implementation",
"sortings"
] | null | null | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t... | The first line of input contains two space-separated positive integers *n* (2<=≤<=*n*<=≤<=100) and *k* (1<=≤<=*k*<=≤<=*n*) — the lengths of sequence *a* and *b* respectively.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=200) — Hitagi's broken sequence with exactly ... | Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise. | [
"4 2\n11 0 0 14\n5 4\n",
"6 1\n2 3 0 8 9 10\n5\n",
"4 1\n8 94 0 4\n89\n",
"7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n"
] | In the first sample:
- Sequence *a* is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulti... | 500 | [
{
"input": "4 2\n11 0 0 14\n5 4",
"output": "Yes"
},
{
"input": "6 1\n2 3 0 8 9 10\n5",
"output": "No"
},
{
"input": "4 1\n8 94 0 4\n89",
"output": "Yes"
},
{
"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7",
"output": "Yes"
},
{
"input": "40 1\n23 26 27 28 31 35 38 4... | 1,500,705,991 | 2,147,483,647 | Python 3 | OK | TESTS | 96 | 62 | 4,608,000 | input()
seq1=input().split(" ")
seq2=input().split(" ")
success=False
if len(seq2)==1:
for i in range(len(seq1)):
if seq1[i]=="0":
seq1[i]=seq2[0]
for i in range(len(seq1)-1):
if int(seq1[i])>int(seq1[i+1]):
success=True
else:
success=True
if success:... | Title: An abandoned sentiment from past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of t... | ```python
input()
seq1=input().split(" ")
seq2=input().split(" ")
success=False
if len(seq2)==1:
for i in range(len(seq1)):
if seq1[i]=="0":
seq1[i]=seq2[0]
for i in range(len(seq1)-1):
if int(seq1[i])>int(seq1[i+1]):
success=True
else:
success=True
i... | 3 | |
349 | A | Cinema Line | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. | Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". | [
"4\n25 25 50 50\n",
"2\n25 100\n",
"4\n50 50 25 25\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "4\n25 25 50 50",
"output": "YES"
},
{
"input": "2\n25 100",
"output": "NO"
},
{
"input": "4\n50 50 25 25",
"output": "NO"
},
{
"input": "3\n25 50 100",
"output": "NO"
},
{
"input": "10\n25 25 25 25 25 25 25 25 25 25",
"output": "YES"
},
{
"... | 1,641,237,251 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | import numpy as np
n = int(input())
a = np.array([int(x) for x in input().split()])
a = a//25
count = 1
change = 0
i = 0
flag = 0
while(i < n):
if a[i] <= count:
change += 1
count = change
flag = 1
i += 1
else:
flag = 0
break
if flag:
print("YES")
else:
print("NO")
| Title: Cinema Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the bookin... | ```python
import numpy as np
n = int(input())
a = np.array([int(x) for x in input().split()])
a = a//25
count = 1
change = 0
i = 0
flag = 0
while(i < n):
if a[i] <= count:
change += 1
count = change
flag = 1
i += 1
else:
flag = 0
break
if flag:
print("YES")
else:
print("N... | -1 | |
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi... | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel... | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input"... | 1,622,287,302 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 202 | 6,348,800 | from sys import stdin, stdout
def istr(): return input()
def inum(): return int(stdin.readline())
def imul(): return map(int, stdin.readline().split())
def ilst(): return list(map(int, stdin.readline().split()))
def splt(): return list(stdin.readline().strip())
max_itr = 100000000
# Code
n,m = imul()
... | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first ... | ```python
from sys import stdin, stdout
def istr(): return input()
def inum(): return int(stdin.readline())
def imul(): return map(int, stdin.readline().split())
def ilst(): return list(map(int, stdin.readline().split()))
def splt(): return list(stdin.readline().strip())
max_itr = 100000000
# Code
n,m... | 3 | |
610 | B | Vika and Squares | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | null | null | Vika has *n* jars with paints of distinct colors. All the jars are numbered from 1 to *n* and the *i*-th jar contains *a**i* liters of paint of color *i*.
Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1<=×<=1. Squares are numbered 1, 2, 3 and so on. Vika decided ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of jars with colors Vika has.
The second line of the input contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is equal to the number of liters of paint in the *i*-th jar, i.e. th... | The only line of the output should contain a single integer — the maximum number of squares that Vika can paint if she follows the rules described above. | [
"5\n2 4 2 3 3\n",
"3\n5 5 5\n",
"6\n10 10 10 1 10 10\n"
] | [
"12\n",
"15\n",
"11\n"
] | In the first sample the best strategy is to start painting using color 4. Then the squares will be painted in the following colors (from left to right): 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5.
In the second sample Vika can start to paint using any color.
In the third sample Vika should start painting using color number 5... | 1,000 | [
{
"input": "5\n2 4 2 3 3",
"output": "12"
},
{
"input": "3\n5 5 5",
"output": "15"
},
{
"input": "6\n10 10 10 1 10 10",
"output": "11"
},
{
"input": "1\n167959139",
"output": "167959139"
},
{
"input": "10\n896619242 805194919 844752453 848347723 816995848 85681361... | 1,520,081,899 | 799 | Python 3 | OK | TESTS | 66 | 311 | 31,641,600 | n = int(input())
R = lambda : map(int, input().split())
v = list(R())
m = min(v)
v = v+v
vi = [i for i in range(len(v)) if v[i]==m]
di = max([vi[i]-vi[i-1] for i in range(1,len(vi))])
print(n*m+di-1)
| Title: Vika and Squares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vika has *n* jars with paints of distinct colors. All the jars are numbered from 1 to *n* and the *i*-th jar contains *a**i* liters of paint of color *i*.
Vika also has an infinitely long rectangular piece of paper of... | ```python
n = int(input())
R = lambda : map(int, input().split())
v = list(R())
m = min(v)
v = v+v
vi = [i for i in range(len(v)) if v[i]==m]
di = max([vi[i]-vi[i-1] for i in range(1,len(vi))])
print(n*m+di-1)
``` | 3 | |
157 | A | Game Outcome | PROGRAMMING | 800 | [
"brute force"
] | null | null | Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=30). Each of the following *n* lines contain *n* space-separated integers. The *j*-th number on the *i*-th line represents the number on the square that belongs to the *j*-th column and the *i*-th row on the board. All number on the board are integers from 1 to 100. | Print the single number — the number of the winning squares. | [
"1\n1\n",
"2\n1 2\n3 4\n",
"4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3\n"
] | [
"0\n",
"2\n",
"6\n"
] | In the first example two upper squares are winning.
In the third example three left squares in the both middle rows are winning: | 500 | [
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 2\n3 4",
"output": "2"
},
{
"input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3",
"output": "6"
},
{
"input": "2\n1 1\n1 1",
"output": "0"
},
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "4"
},
{
"inpu... | 1,590,497,404 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 310 | 1,433,600 | n = int(input())
v =[]
for _ in range(n):
a = list(map(int,input().split()))
v.append(a)
k = [[v[j][i] for j in range(n)] for i in range(n)]
c =0
for i in k:
for j in v:
if sum(i)>sum(j):
c+=1
print(c) | Title: Game Outcome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each s... | ```python
n = int(input())
v =[]
for _ in range(n):
a = list(map(int,input().split()))
v.append(a)
k = [[v[j][i] for j in range(n)] for i in range(n)]
c =0
for i in k:
for j in v:
if sum(i)>sum(j):
c+=1
print(c)
``` | 3 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,651,793,695 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 62 | 2,457,600 | n,k = map(int, input().split())
s = list(map(int,input().split()))
count = 0
for i in range(len(s)):
if s[i] + k > 5:
s[i] = -1
else:
count += 1
print(count // 3)
| Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n,k = map(int, input().split())
s = list(map(int,input().split()))
count = 0
for i in range(len(s)):
if s[i] + k > 5:
s[i] = -1
else:
count += 1
print(count // 3)
``` | 3 | |
716 | B | Complete the Word | PROGRAMMING | 1,300 | [
"greedy",
"two pointers"
] | null | null | ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not n... | The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember... | If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line.
Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks... | [
"ABC??FGHIJK???OPQR?TUVWXY?\n",
"WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n",
"??????????????????????????\n",
"AABCDEFGHIJKLMNOPQRSTUVW??M\n"
] | [
"ABCDEFGHIJKLMNOPQRZTUVWXYS",
"-1",
"MNBVCXZLKJHGFDSAQPWOEIRUYT",
"-1"
] | In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZT... | 1,000 | [
{
"input": "ABC??FGHIJK???OPQR?TUVWXY?",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO",
"output": "-1"
},
{
"input": "??????????????????????????",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "AABCDEFGHIJKLMNO... | 1,605,788,120 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 307,200 | s=list(input())
if len(s)!=26:
print(-1)
else:
if '?' not in s:
if len(set(s))==len(s):
print(s)
else:
print(-1)
else:
if len(s)-s.count('?')+1==len(set(s)):
for i in range(65,91):
if chr(i) not in s:
s[s.index('?')]=chr(i... | Title: Complete the Word
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In pa... | ```python
s=list(input())
if len(s)!=26:
print(-1)
else:
if '?' not in s:
if len(set(s))==len(s):
print(s)
else:
print(-1)
else:
if len(s)-s.count('?')+1==len(set(s)):
for i in range(65,91):
if chr(i) not in s:
s[s.index('... | 0 | |
56 | D | Changing a String | PROGRAMMING | 2,100 | [
"dp"
] | D. Changing a String | 2 | 256 | There is a string *s*, consisting of capital Latin letters. Let's denote its current length as |*s*|. During one move it is allowed to apply one of the following operations to it:
- INSERT *pos* *ch* — insert a letter *ch* in the string *s* in the position *pos* (1<=≤<=*pos*<=≤<=|*s*|<=+<=1,<=*A*<=≤<=*ch*<=≤<=*Z*). ... | The first line contains *s*, the second line contains *t*. The lines consist only of capital Latin letters, their lengths are positive numbers from 1 to 1000. | In the first line print the number of moves *k* in the given sequence of operations. The number should be the minimal possible one. Then print *k* lines containing one operation each. Print the operations in the format, described above. If there are several solutions, print any of them. | [
"ABA\nABBBA\n",
"ACCEPTED\nWRONGANSWER\n"
] | [
"2\nINSERT 3 B\nINSERT 4 B\n",
"10\nREPLACE 1 W\nREPLACE 2 R\nREPLACE 3 O\nREPLACE 4 N\nREPLACE 5 G\nREPLACE 6 A\nINSERT 7 N\nINSERT 8 S\nINSERT 9 W\nREPLACE 11 R\n"
] | none | 2,000 | [
{
"input": "ABA\nABBBA",
"output": "2\nINSERT 3 B\nINSERT 4 B"
},
{
"input": "ACCEPTED\nWRONGANSWER",
"output": "10\nREPLACE 1 W\nREPLACE 2 R\nREPLACE 3 O\nREPLACE 4 N\nREPLACE 5 G\nREPLACE 6 A\nINSERT 7 N\nINSERT 8 S\nINSERT 9 W\nREPLACE 11 R"
},
{
"input": "V\nBNBNE",
"output": "5\... | 1,602,916,689 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 1,228,800 | import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
s, t = input().rstrip(), input().rstrip()
n, m = len(s), len(t)
dp = [[10**9] * (m + 2) for _ in range(n + 2)]
dp[n][m] = 0
prev = [[(-1, -1)] * (m + 2) for _ in range(n + 2)]
for i ... | Title: Changing a String
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a string *s*, consisting of capital Latin letters. Let's denote its current length as |*s*|. During one move it is allowed to apply one of the following operations to it:
- INSERT *pos* *ch* — insert a letter ... | ```python
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
s, t = input().rstrip(), input().rstrip()
n, m = len(s), len(t)
dp = [[10**9] * (m + 2) for _ in range(n + 2)]
dp[n][m] = 0
prev = [[(-1, -1)] * (m + 2) for _ in range(n + 2)]... | 0 |
465 | A | inc ARG | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell.
The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan... | Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. | [
"4\n1100\n",
"4\n1111\n"
] | [
"3\n",
"4\n"
] | In the first sample the cell ends up with value 0010, in the second sample — with 0000. | 500 | [
{
"input": "4\n1100",
"output": "3"
},
{
"input": "4\n1111",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "1"
},
{
"input": "2\n01",
"output": "1"
},
{
"input": "2\n1... | 1,568,548,161 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 124 | 0 | n = int(input())
e = input()
e = e[::-1]
q = len(e)-1
a = 0
p = ''
for i in range(0,n):
s = 2**q
if int(e[i])>0:
a += s
q -= 1
a += 1
while a>0:
p += str(a % 2)
a //= 2
p = p[::-1]
p = '0'*(len(e)-len(p)) + p
a = 0
if (len(e) < len(p)):
e = '1' + e
for y in range(0,len(e)):
if e[y]!... | Title: inc ARG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea... | ```python
n = int(input())
e = input()
e = e[::-1]
q = len(e)-1
a = 0
p = ''
for i in range(0,n):
s = 2**q
if int(e[i])>0:
a += s
q -= 1
a += 1
while a>0:
p += str(a % 2)
a //= 2
p = p[::-1]
p = '0'*(len(e)-len(p)) + p
a = 0
if (len(e) < len(p)):
e = '1' + e
for y in range(0,len(e)):
... | 3 | |
515 | C | Drazil and Factorial | PROGRAMMING | 1,400 | [
"greedy",
"math",
"sortings"
] | null | null | Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they shoul... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*.
The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes. | Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. | [
"4\n1234\n",
"3\n555\n"
] | [
"33222\n",
"555\n"
] | In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "4\n1234",
"output": "33222"
},
{
"input": "3\n555",
"output": "555"
},
{
"input": "15\n012345781234578",
"output": "7777553333222222222222"
},
{
"input": "1\n8",
"output": "7222"
},
{
"input": "10\n1413472614",
"output": "75333332222222"
},
{
... | 1,695,716,199 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | A={'7':0,'5':0,'3':0,'2':0}
t=''
for i in input():
if i=='9': A['7']+=1; A['3']+=2; A['2']+=1
elif i=='8': A['7']+=1; A['2']+=3
elif i=='6': A['5']+=1; A['3']+=1
elif i=='4': A['3']+=1; A['2']+=2
elif i=='7' or i=='5' or i=='3' or i=='2': A[i]+=1
for a,b in A.items():
t+=a*b
print(t) | Title: Drazil and Factorial
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that cont... | ```python
A={'7':0,'5':0,'3':0,'2':0}
t=''
for i in input():
if i=='9': A['7']+=1; A['3']+=2; A['2']+=1
elif i=='8': A['7']+=1; A['2']+=3
elif i=='6': A['5']+=1; A['3']+=1
elif i=='4': A['3']+=1; A['2']+=2
elif i=='7' or i=='5' or i=='3' or i=='2': A[i]+=1
for a,b in A.items():
t+=a*b
... | 0 | |
600 | B | Queries about less or equal elements | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | 0 | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -77918754... | 1,669,126,234 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n,m = map(int, input().split())
a=[]
b=[]
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
b.sort()
liste=[]
for i in b:
dicte=dict.fromkeys([i],[])
j=0
while j<len(a):
if i>=a[j]:
dicte[i].append(a[j])
j+=1
liste.... | Title: Queries about less or equal elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
In... | ```python
n,m = map(int, input().split())
a=[]
b=[]
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
b.sort()
liste=[]
for i in b:
dicte=dict.fromkeys([i],[])
j=0
while j<len(a):
if i>=a[j]:
dicte[i].append(a[j])
j+=1
... | 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,634,310,742 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 122 | 0 | s = input()
t = input()
s_len = len(s)
t_len = len(t)
i ,j = 0,0
while(i < s_len and j < t_len):
if s[i] == t[j] :
i+=1
j+=1
else:
j+=1
print(i+1) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
s = input()
t = input()
s_len = len(s)
t_len = len(t)
i ,j = 0,0
while(i < s_len and j < t_len):
if s[i] == t[j] :
i+=1
j+=1
else:
j+=1
print(i+1)
``` | 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,672,690,431 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 46 | 0 | s = input()
s = s.lower()
n = len(s)
count = 0
for i in range(n):
if s[i] == 'a':
count += s[:i].count('q') * s[i+1:].count('q')
print(count)
| 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
s = input()
s = s.lower()
n = len(s)
count = 0
for i in range(n):
if s[i] == 'a':
count += s[:i].count('q') * s[i+1:].count('q')
print(count)
``` | 3 | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,599,577,542 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | cards = input()
relevants = ['a', 'e', 'i', 'o', 'u', '0', '2', '4', '6', '8']
count = 0
for i in cards:
if(i in relevants):
count += 1
print(count)
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
cards = input()
relevants = ['a', 'e', 'i', 'o', 'u', '0', '2', '4', '6', '8']
count = 0
for i in cards:
if(i in relevants):
count += 1
print(count)
``` | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,658,400,076 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | from math import floor
n, k = map(int, input().split())
print(floor((n*k)/2)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
from math import floor
n, k = map(int, input().split())
print(floor((n*k)/2))
``` | 3.977 |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,693,674,433 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 124 | 0 | n = input().split()
n = [int(x) for x in n]
s = max(n)
if s == 1:
print("1/1")
elif s == 2:
print("5/6")
elif s == 3:
print("2/3")
elif s == 4:
print("1/2")
elif s == 5:
print("1/6")
else:
print("0/1") | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
n = input().split()
n = [int(x) for x in n]
s = max(n)
if s == 1:
print("1/1")
elif s == 2:
print("5/6")
elif s == 3:
print("2/3")
elif s == 4:
print("1/2")
elif s == 5:
print("1/6")
else:
print("0/1")
``` | 0 |
990 | A | Commentary Boxes | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations wil... | The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box. | Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$. | [
"9 7 3 8\n",
"2 7 3 7\n",
"30 6 17 19\n"
] | [
"15\n",
"14\n",
"0\n"
] | In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them.
In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them.
In the third example organizers are already able to distribute all the boxes eq... | 0 | [
{
"input": "9 7 3 8",
"output": "15"
},
{
"input": "2 7 3 7",
"output": "14"
},
{
"input": "30 6 17 19",
"output": "0"
},
{
"input": "500000000001 1000000000000 100 100",
"output": "49999999999900"
},
{
"input": "1000000000000 750000000001 10 100",
"output": "... | 1,571,513,650 | 250 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sc second
#define fr first
using namespace std;
int main(){
ll n,m,a,b;
cin>>n>>m>>a>>b;
swap(a,b);
ll t = n/m;
ll r = n - t*m;
r *= a;
r = min(r,((t+1)*m - n)*b);
... | Title: Commentary Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation shou... | ```python
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sc second
#define fr first
using namespace std;
int main(){
ll n,m,a,b;
cin>>n>>m>>a>>b;
swap(a,b);
ll t = n/m;
ll r = n - t*m;
r *= a;
r = min(r,((t+1)*m - n)... | -1 | |
689 | B | Mike and Shortcuts | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"greedy",
"shortest paths"
] | null | null | Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city.
City consists of *n* intersections numbered from 1 to *n*. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Wal... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Mike's city intersection.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*i*<=≤<=*a**i*<=≤<=*n* , , describing shortcuts of Mike's city, allowing to walk from intersection *i* to intersection *a**i* using only 1 unit of ... | In the only line print *n* integers *m*1,<=*m*2,<=...,<=*m**n*, where *m**i* denotes the least amount of total energy required to walk from intersection 1 to intersection *i*. | [
"3\n2 2 3\n",
"5\n1 2 3 4 5\n",
"7\n4 4 4 4 7 7 7\n"
] | [
"0 1 2 \n",
"0 1 2 3 4 \n",
"0 1 2 1 2 3 3 \n"
] | In the first sample case desired sequences are:
1: 1; *m*<sub class="lower-index">1</sub> = 0;
2: 1, 2; *m*<sub class="lower-index">2</sub> = 1;
3: 1, 3; *m*<sub class="lower-index">3</sub> = |3 - 1| = 2.
In the second sample case the sequence for any intersection 1 < *i* is always 1, *i* and *m*<sub class="lowe... | 1,000 | [
{
"input": "3\n2 2 3",
"output": "0 1 2 "
},
{
"input": "5\n1 2 3 4 5",
"output": "0 1 2 3 4 "
},
{
"input": "7\n4 4 4 4 7 7 7",
"output": "0 1 2 1 2 3 3 "
},
{
"input": "98\n17 17 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 87 87... | 1,468,268,655 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n = int(input())
a = list(map(int, input().split()))
d = [-1 for i in range(n)]
d[0] = 0
if a[0] > 1:
d[a[0]-1] = 1
for u in range(2):
for i in range(1, n):
if d[i] == -1:
min = 10**30
else:
min = d[i]
if d[i-1] + 1 < min:
min = d[i-... | Title: Mike and Shortcuts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city.
City consists of *n* intersections numbered from 1 to *n*. Mike starts walkin... | ```python
n = int(input())
a = list(map(int, input().split()))
d = [-1 for i in range(n)]
d[0] = 0
if a[0] > 1:
d[a[0]-1] = 1
for u in range(2):
for i in range(1, n):
if d[i] == -1:
min = 10**30
else:
min = d[i]
if d[i-1] + 1 < min:
... | 0 | |
353 | A | Domino | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half... | Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. | [
"2\n4 2\n6 4\n",
"1\n2 3\n",
"3\n1 4\n2 3\n4 4\n"
] | [
"0\n",
"-1\n",
"1\n"
] | In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the... | 500 | [
{
"input": "2\n4 2\n6 4",
"output": "0"
},
{
"input": "1\n2 3",
"output": "-1"
},
{
"input": "3\n1 4\n2 3\n4 4",
"output": "1"
},
{
"input": "5\n5 4\n5 4\n1 5\n5 5\n3 3",
"output": "1"
},
{
"input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n... | 1,605,590,520 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 307,200 | n = int(input())
l = u = count = 0
for i in range(n):
x,y = map(int,input().split())
if (u+x)%2==0 and (l+y)%2==0:
u = 0
l = 0
elif (u+y)%2==0 and (l+x)%2==0:
u = 0
l = 0
count += 1
else:
u += x
l += y
if u==l==0:
print(count)
e... | Title: Domino
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the n... | ```python
n = int(input())
l = u = count = 0
for i in range(n):
x,y = map(int,input().split())
if (u+x)%2==0 and (l+y)%2==0:
u = 0
l = 0
elif (u+y)%2==0 and (l+x)%2==0:
u = 0
l = 0
count += 1
else:
u += x
l += y
if u==l==0:
print... | 0 | |
450 | B | Jzzhu and Sequences | PROGRAMMING | 1,300 | [
"implementation",
"math"
] | null | null | Jzzhu has invented a kind of sequences, they meet the following property:
You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7). | The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). | Output a single integer representing *f**n* modulo 1000000007 (109<=+<=7). | [
"2 3\n3\n",
"0 -1\n2\n"
] | [
"1\n",
"1000000006\n"
] | In the first sample, *f*<sub class="lower-index">2</sub> = *f*<sub class="lower-index">1</sub> + *f*<sub class="lower-index">3</sub>, 3 = 2 + *f*<sub class="lower-index">3</sub>, *f*<sub class="lower-index">3</sub> = 1.
In the second sample, *f*<sub class="lower-index">2</sub> = - 1; - 1 modulo (10<sup class="upper-... | 1,000 | [
{
"input": "2 3\n3",
"output": "1"
},
{
"input": "0 -1\n2",
"output": "1000000006"
},
{
"input": "-9 -11\n12345",
"output": "1000000005"
},
{
"input": "0 0\n1000000000",
"output": "0"
},
{
"input": "-1000000000 1000000000\n2000000000",
"output": "1000000000"
... | 1,650,512,256 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def main():
f1, f2 = map(int, input().split())
n = int(input())
if n == 1:
print(f1 % 1000000007)
return
elif n == 2:
print(f2 % 1000000007)
return
for i in range(3, n+1):
f1, f2 = f2-f1, f1
print(f2 % 1000000007)
if __name__ == "__main__... | Title: Jzzhu and Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jzzhu has invented a kind of sequences, they meet the following property:
You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7).
Input Specification:
The first line contains two integers... | ```python
def main():
f1, f2 = map(int, input().split())
n = int(input())
if n == 1:
print(f1 % 1000000007)
return
elif n == 2:
print(f2 % 1000000007)
return
for i in range(3, n+1):
f1, f2 = f2-f1, f1
print(f2 % 1000000007)
if __name__ ==... | 0 | |
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu... | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"... | 1,695,464,508 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 46 | 0 | def calculate_min_cost(n, m, a, b):
result1 = ((n % m) * a) + (int(n // m) * b)
result2 = n * a
result3 = b + (int(n // m) * b)
if result1 > result2 and result3 > result2:
return result2
elif result2 > result3 and result1 > result3:
return result3
else:
ret... | Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl... | ```python
def calculate_min_cost(n, m, a, b):
result1 = ((n % m) * a) + (int(n // m) * b)
result2 = n * a
result3 = b + (int(n // m) * b)
if result1 > result2 and result3 > result2:
return result2
elif result2 > result3 and result1 > result3:
return result3
else:
... | 3 | |
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"... | 1,612,838,622 | 2,147,483,647 | PyPy 3 | OK | TESTS | 16 | 108 | 1,331,200 | n=int(input())
flag=False
fn=list(map(int,input().split()))
for i in range(0,n):
x=fn[i] #1 likes 8
y=fn[fn[i]-1] #8 likes 10
z=fn[fn[fn[i]-1]-1] #10 likes 1
if(z==i+1):
print("YES")
flag=True
break
if(flag==False):
print("NO")
| Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with ... | ```python
n=int(input())
flag=False
fn=list(map(int,input().split()))
for i in range(0,n):
x=fn[i] #1 likes 8
y=fn[fn[i]-1] #8 likes 10
z=fn[fn[fn[i]-1]-1] #10 likes 1
if(z==i+1):
print("YES")
flag=True
break
if(flag==False):
print("NO")
`... | 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,443,891,103 | 403 | Python 3 | OK | TESTS | 39 | 62 | 0 | n=int(input())
m1=[0 for i in range(n)]
m2=[0 for i in range(n)]
for i in range(n*n):
a,b=list(map(int,input().split()))
if m1[a-1]==m2[b-1]==0:
m1[a-1]=m2[b-1]=1
print(i+1,end=' ') | 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
n=int(input())
m1=[0 for i in range(n)]
m2=[0 for i in range(n)]
for i in range(n*n):
a,b=list(map(int,input().split()))
if m1[a-1]==m2[b-1]==0:
m1[a-1]=m2[b-1]=1
print(i+1,end=' ')
``` | 3 | |
811 | A | Vladik and Courtesy | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving eac... | Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. | Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. | [
"1 1\n",
"7 6\n"
] | [
"Valera\n",
"Vladik\n"
] | Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e... | 500 | [
{
"input": "1 1",
"output": "Valera"
},
{
"input": "7 6",
"output": "Vladik"
},
{
"input": "25 38",
"output": "Vladik"
},
{
"input": "8311 2468",
"output": "Valera"
},
{
"input": "250708 857756",
"output": "Vladik"
},
{
"input": "957985574 24997558",
... | 1,502,325,398 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 77 | 4,608,000 | a,b = map(int,input().rstrip().split())
t = True
i = 0
while True:
i += 1
if t:
a -= i
if a < 0:
break
else:
b -= i
if b < 0:
break
t = not t
if t:
print("Vladik")
else:
print("Valera")
| Title: Vladik and Courtesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vla... | ```python
a,b = map(int,input().rstrip().split())
t = True
i = 0
while True:
i += 1
if t:
a -= i
if a < 0:
break
else:
b -= i
if b < 0:
break
t = not t
if t:
print("Vladik")
else:
print("Valera")
``` | 3 | |
137 | B | Permutation | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is cal... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). | Print the only number — the minimum number of changes needed to get the permutation. | [
"3\n3 1 2\n",
"2\n2 2\n",
"5\n5 3 3 3 1\n"
] | [
"0\n",
"1\n",
"2\n"
] | The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with... | 1,000 | [
{
"input": "3\n3 1 2",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "2"
},
{
"input": "5\n6 6 6 6 6",
"output": "5"
},
{
"input": "10\n1 1 2 2 8 8 7 7 9 9",
"output": "5"
},
{
"input": "8\n9 8 7 6 5 4 3 2"... | 1,562,079,884 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 280 | 0 | n = int(input())
x = list(map(int, input().split()))
f = [0]*5009
ans = 0
for i in x:
if(f[i]==0):
f[i] = 1
else:
ans += 1
print(ans) | Title: Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task ... | ```python
n = int(input())
x = list(map(int, input().split()))
f = [0]*5009
ans = 0
for i in x:
if(f[i]==0):
f[i] = 1
else:
ans += 1
print(ans)
``` | 0 | |
412 | C | Pattern | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules.
In this task, a pattern will be a string con... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of patterns. Next *n* lines contain the patterns.
It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does no... | In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them. | [
"2\n?ab\n??b\n",
"2\na\nb\n",
"1\n?a?b\n"
] | [
"xab\n",
"?\n",
"cacb\n"
] | Consider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot of ot... | 1,500 | [
{
"input": "2\n?ab\n??b",
"output": "xab"
},
{
"input": "2\na\nb",
"output": "?"
},
{
"input": "1\n?a?b",
"output": "cacb"
},
{
"input": "1\n?",
"output": "x"
},
{
"input": "3\nabacaba\nabacaba\nabacaba",
"output": "abacaba"
},
{
"input": "3\nabc?t\n?b... | 1,656,056,015 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 22 | 1,000 | 14,028,800 | import sys
input = sys.stdin.readline
n = int(input())
g = [input()[:-1] for _ in range(n)]
w = map(lambda x:set(x), (zip(*g)))
d = ''
for i in w:
if len(i) == 1:
x = list(i)[0]
if x == '?':
d += 'a'
else:
d += x
elif len(i) == 2:
x = list(... | Title: Pattern
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check wheth... | ```python
import sys
input = sys.stdin.readline
n = int(input())
g = [input()[:-1] for _ in range(n)]
w = map(lambda x:set(x), (zip(*g)))
d = ''
for i in w:
if len(i) == 1:
x = list(i)[0]
if x == '?':
d += 'a'
else:
d += x
elif len(i) == 2:
... | 0 | |
979 | C | Kuro and Walking Route | PROGRAMMING | 1,600 | [
"dfs and similar",
"trees"
] | null | null | Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which h... | The first line contains three integers $n$, $x$ and $y$ ($1 \leq n \leq 3 \cdot 10^5$, $1 \leq x, y \leq n$, $x \ne y$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively.
$n - 1$ lines follow, each line contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), de... | A single integer resembles the number of pair of towns $(u, v)$ that Kuro can use as his walking route. | [
"3 1 3\n1 2\n2 3\n",
"3 1 3\n1 2\n1 3\n"
] | [
"5",
"4"
] | On the first example, Kuro can choose these pairs:
- $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 3)$: his route would be $2 \rightarrow 3$, - $(3, 2)$: his route would be $3 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 1)$: his route would be $3 \rightarrow 2 \rightarrow 1$... | 1,250 | [
{
"input": "3 1 3\n1 2\n2 3",
"output": "5"
},
{
"input": "3 1 3\n1 2\n1 3",
"output": "4"
},
{
"input": "61 26 12\n33 38\n32 8\n27 59\n1 21\n61 57\n61 22\n35 18\n61 14\n39 56\n50 10\n1 42\n21 43\n61 41\n31 30\n35 9\n23 28\n39 34\n39 4\n39 25\n27 60\n45 51\n1 11\n35 26\n29 15\n23 44\n31 ... | 1,526,493,498 | 5,298 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 186 | 125,747,200 | import threading
import sys
def main():
inp = sys.stdin.readlines()
n, x, y = [int(x) for x in inp[0].strip().split()]
nl = [[] for i in range(n+1)]
for _ in range(1, n):
a, b = [int(x) for x in inp[_].strip().split()]
nl[a].append(b)
nl[b].append(a)
def f... | Title: Kuro and Walking Route
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road ... | ```python
import threading
import sys
def main():
inp = sys.stdin.readlines()
n, x, y = [int(x) for x in inp[0].strip().split()]
nl = [[] for i in range(n+1)]
for _ in range(1, n):
a, b = [int(x) for x in inp[_].strip().split()]
nl[a].append(b)
nl[b].append(a)
... | 0 | |
313 | B | Ilya and Queries | PROGRAMMING | 1,100 | [
"dp",
"implementation"
] | null | null | Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<... | The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-t... | Print *m* integers — the answers to the queries in the order in which they are given in the input. | [
"......\n4\n3 4\n2 3\n1 6\n2 6\n",
"#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n"
] | [
"1\n1\n5\n4\n",
"1\n1\n2\n2\n0\n"
] | none | 1,000 | [
{
"input": "......\n4\n3 4\n2 3\n1 6\n2 6",
"output": "1\n1\n5\n4"
},
{
"input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4",
"output": "1\n1\n2\n2\n0"
},
{
"input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3",
"output": "2\n0\n0\n1\n2\n0"
},
{
"input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5... | 1,695,283,848 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 1,620 | 4,096,000 | # LUOGU_RID: 125426540
str = input()
list = [0] * len(str)
for i in range(1, len(str)):
list[i] = list[i-1] + (str[i] == str[i-1])
m = int(input())
for item in range(m):
start, end=map(int, input().split())
print(list[end-1] - list[start-1]) | Title: Ilya and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting ... | ```python
# LUOGU_RID: 125426540
str = input()
list = [0] * len(str)
for i in range(1, len(str)):
list[i] = list[i-1] + (str[i] == str[i-1])
m = int(input())
for item in range(m):
start, end=map(int, input().split())
print(list[end-1] - list[start-1])
``` | 3 | |
446 | A | DZY Loves Sequences | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"two pointers"
] | null | null | DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment.
Your task is to find the longest subsegment of *a*, such that it is possible ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | In a single line print the answer to the problem — the maximum length of the required subsegment. | [
"6\n7 2 3 1 5 6\n"
] | [
"5\n"
] | You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4. | 500 | [
{
"input": "6\n7 2 3 1 5 6",
"output": "5"
},
{
"input": "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422",
"output": "9"
},
{
"input": "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 1... | 1,610,621,987 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 307,200 | def seq(arr):
temp=[arr[0]]
ans=1
i=1
flag=False
r=[0,0]
while i<len(arr):
# print(temp)
if arr[i]>temp[-1]:
temp.append(arr[i])
ans=max(ans,len(temp))
else:
if flag==False:
temp.append(temp[-1]+1)
... | Title: DZY Loves Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the... | ```python
def seq(arr):
temp=[arr[0]]
ans=1
i=1
flag=False
r=[0,0]
while i<len(arr):
# print(temp)
if arr[i]>temp[-1]:
temp.append(arr[i])
ans=max(ans,len(temp))
else:
if flag==False:
temp.append(temp[-1]+1)... | 0 | |
757 | B | Bash's Big Day | PROGRAMMING | 1,400 | [
"greedy",
"math",
"number theory"
] | null | null | Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.
But Zulu warns him that a group of *k*<=><=1 Pokemon with strengths {*... | The input consists of two lines.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105), the number of Pokemon in the lab.
The next line contains *n* space separated integers, where the *i*-th of them denotes *s**i* (1<=≤<=*s**i*<=≤<=105), the strength of the *i*-th Pokemon. | Print single integer — the maximum number of Pokemons Bash can take. | [
"3\n2 3 4\n",
"5\n2 3 4 6 7\n"
] | [
"2\n",
"3\n"
] | *gcd* (greatest common divisor) of positive integers set {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>} is the maximum positive integer that divides all the integers {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a... | 1,000 | [
{
"input": "3\n2 3 4",
"output": "2"
},
{
"input": "5\n2 3 4 6 7",
"output": "3"
},
{
"input": "3\n5 6 4",
"output": "2"
},
{
"input": "8\n41 74 4 27 85 39 100 36",
"output": "4"
},
{
"input": "6\n89 20 86 81 62 23",
"output": "3"
},
{
"input": "71\n23... | 1,484,771,147 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 296 | 10,752,000 | n = int(input())
pokemones = input().split(' ')
if n==1:
print(1)
else:
for a in pokemones[::-1]:
if int(a)%2!=0:
pokemones.remove(a)
print(len(pokemones))
| Title: Bash's Big Day
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon fr... | ```python
n = int(input())
pokemones = input().split(' ')
if n==1:
print(1)
else:
for a in pokemones[::-1]:
if int(a)%2!=0:
pokemones.remove(a)
print(len(pokemones))
``` | 0 | |
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy start... | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second lin... | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fanta... | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
... | 1,662,889,777 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 46 | 218 | 2,457,600 | a=input()
forward=[input(),input()]
backward=[forward[1][::-1],forward[0][::-1]]
df,db=0,0
for i in range(len(a)):
if forward:
ii = i+df
if len(a) - ii >= len(forward[0]):
if a[ii:ii+len(forward[0])] == forward[0]:
df += len(forward[0])-1
del forward[0]
... | Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the... | ```python
a=input()
forward=[input(),input()]
backward=[forward[1][::-1],forward[0][::-1]]
df,db=0,0
for i in range(len(a)):
if forward:
ii = i+df
if len(a) - ii >= len(forward[0]):
if a[ii:ii+len(forward[0])] == forward[0]:
df += len(forward[0])-1
del for... | 0 |
257 | C | View Angle | PROGRAMMING | 1,800 | [
"brute force",
"geometry",
"math"
] | null | null | Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this a... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of mannequins.
Next *n* lines contain two space-separated integers each: *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=1000) — the coordinates of the *i*-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is gu... | Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10<=-<=6. | [
"2\n2 0\n0 2\n",
"3\n2 0\n0 2\n-2 2\n",
"4\n2 0\n0 2\n-2 0\n0 -2\n",
"2\n2 1\n1 2\n"
] | [
"90.0000000000\n",
"135.0000000000\n",
"270.0000000000\n",
"36.8698976458\n"
] | Solution for the first sample test is shown below:
Solution for the second sample test is shown below:
Solution for the third sample test is shown below:
Solution for the fourth sample test is shown below: | 1,500 | [
{
"input": "2\n2 0\n0 2",
"output": "90.0000000000"
},
{
"input": "3\n2 0\n0 2\n-2 2",
"output": "135.0000000000"
},
{
"input": "4\n2 0\n0 2\n-2 0\n0 -2",
"output": "270.0000000000"
},
{
"input": "2\n2 1\n1 2",
"output": "36.8698976458"
},
{
"input": "1\n1 1",
... | 1,578,069,544 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 12 | 1,620 | 6,144,000 | from math import atan2 as ast
from math import pi
n=int(input())
minn=1000000000
maxx=0
for z in range(n):
x,y=map(int,input().split())
i=ast(y,x)
if i<0:
i+=pi*2
if i<minn:
minn=i
if i>maxx:
maxx=i
print(((maxx-minn)/pi)*180)
| Title: View Angle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex ... | ```python
from math import atan2 as ast
from math import pi
n=int(input())
minn=1000000000
maxx=0
for z in range(n):
x,y=map(int,input().split())
i=ast(y,x)
if i<0:
i+=pi*2
if i<minn:
minn=i
if i>maxx:
maxx=i
print(((maxx-minn)/pi)*180)
``` | 0 | |
616 | B | Dinner with Emma | PROGRAMMING | 1,000 | [
"games",
"greedy"
] | null | null | Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The stree... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan.
Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue. | Print the only integer *a* — the cost of the dinner for Jack and Emma. | [
"3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n",
"3 3\n1 2 3\n2 3 1\n3 1 2\n"
] | [
"2\n",
"1\n"
] | In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the din... | 0 | [
{
"input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1",
"output": "2"
},
{
"input": "3 3\n1 2 3\n2 3 1\n3 1 2",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 10\n74 35 82 39 1 84 29 41 70 12",
"output": "1"
},
{
"input": "10 1\n44\n23\n65\n17\n48\n29\n... | 1,662,316,445 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 16 | 62 | 1,843,200 | import sys
readline=sys.stdin.readline
N,M=map(int,readline().split())
C=[list(map(int,readline().split())) for n in range(N)]
ans=max(min(C[n][m] for m in range(M)) for n in range(N))
print(ans) | Title: Dinner with Emma
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and... | ```python
import sys
readline=sys.stdin.readline
N,M=map(int,readline().split())
C=[list(map(int,readline().split())) for n in range(N)]
ans=max(min(C[n][m] for m in range(M)) for n in range(N))
print(ans)
``` | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.