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
181
A
Series of Crimes
PROGRAMMING
800
[ "brute force", "geometry", "implementation" ]
null
null
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and m...
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly. Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A charact...
Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right.
[ "3 2\n.*\n..\n**\n", "3 3\n*.*\n*..\n...\n" ]
[ "1 1\n", "2 3\n" ]
none
500
[ { "input": "3 2\n.*\n..\n**", "output": "1 1" }, { "input": "2 5\n*....\n*...*", "output": "1 5" }, { "input": "7 2\n..\n**\n..\n..\n..\n..\n.*", "output": "7 1" }, { "input": "7 2\n*.\n..\n..\n..\n..\n..\n**", "output": "1 2" }, { "input": "2 10\n*......*..\n.......
1,628,256,522
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
6,963,200
N = 100 # imp changes M = 100 # imp changes a = ['?'*M for i in range(N)] row = [False for i in range(N)] column = [False for j in range(M)] flag = bool(-1) def main(): # taking input n, m = map(int, input().split()) for i in range(n): a[i] = input() # marking stars for i i...
Title: Series of Crimes Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the ma...
```python N = 100 # imp changes M = 100 # imp changes a = ['?'*M for i in range(N)] row = [False for i in range(N)] column = [False for j in range(M)] flag = bool(-1) def main(): # taking input n, m = map(int, input().split()) for i in range(n): a[i] = input() # marking stars ...
0
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,680,427,114
2,147,483,647
Python 3
OK
TESTS
30
92
0
n = int(input()) show = sum(list(map(int, input().split()))) counter = 0 for i in range(1, 6): if (show + i) % (n+1) != 1: counter += 1 print(counter)
Title: Dima and Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the...
```python n = int(input()) show = sum(list(map(int, input().split()))) counter = 0 for i in range(1, 6): if (show + i) % (n+1) != 1: counter += 1 print(counter) ```
3
145
A
Lucky Conversion
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits...
The first and the second line contains strings *a* and *b*, correspondingly. Strings *a* and *b* have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105.
Print on the single line the single number — the minimum number of operations needed to convert string *a* into string *b*.
[ "47\n74\n", "774\n744\n", "777\n444\n" ]
[ "1\n", "1\n", "3\n" ]
In the first sample it is enough simply to swap the first and the second digit. In the second sample we should replace the second digit with its opposite. In the third number we should replace all three digits with their opposites.
500
[ { "input": "47\n74", "output": "1" }, { "input": "774\n744", "output": "1" }, { "input": "777\n444", "output": "3" }, { "input": "74747474\n77777777", "output": "4" }, { "input": "444444444444\n777777777777", "output": "12" }, { "input": "4744744447774...
1,571,515,852
2,147,483,647
Python 3
OK
TESTS
51
278
409,600
a = input() b = input() a7,a4 = a.count('7'),a.count('4') b7,b4 = b.count('7'),b.count('4') c = 0 for i in range(len(a)): if a[i]!=b[i]: c += 1 if a7==b7 and a4==b4: if c%2: print(c//2+1) else: print(c//2) else: if b7>a7: d = b7-a7 else: d...
Title: Lucky Conversion Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are no...
```python a = input() b = input() a7,a4 = a.count('7'),a.count('4') b7,b4 = b.count('7'),b.count('4') c = 0 for i in range(len(a)): if a[i]!=b[i]: c += 1 if a7==b7 and a4==b4: if c%2: print(c//2+1) else: print(c//2) else: if b7>a7: d = b7-a7 else: ...
3
9
B
Running Student
PROGRAMMING
1,200
[ "brute force", "geometry", "implementation" ]
B. Running Student
1
64
And again a misfortune fell on Poor Student. He is being late for an exam. Having rushed to a bus stop that is in point (0,<=0), he got on a minibus and they drove along a straight line, parallel to axis *OX*, in the direction of increasing *x*. Poor Student knows the following: - during one run the minibus makes ...
The first line contains three integer numbers: 2<=≤<=*n*<=≤<=100, 1<=≤<=*v**b*,<=*v**s*<=≤<=1000. The second line contains *n* non-negative integers in ascending order: coordinates *x**i* of the bus stop with index *i*. It is guaranteed that *x*1 equals to zero, and *x**n*<=≤<=105. The third line contains the coordinat...
In the only line output the answer to the problem — index of the optimum bus stop.
[ "4 5 2\n0 2 4 6\n4 1\n", "2 1 1\n0 100000\n100000 100000\n" ]
[ "3", "2" ]
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
0
[ { "input": "4 5 2\n0 2 4 6\n4 1", "output": "3" }, { "input": "2 1 1\n0 100000\n100000 100000", "output": "2" }, { "input": "6 5 1\n0 1 2 3 4 5\n0 0", "output": "2" }, { "input": "4 100 10\n0 118 121 178\n220 220", "output": "4" }, { "input": "4 3 3\n0 6 8 10\n7 -...
1,571,840,257
2,147,483,647
PyPy 3
OK
TESTS
23
280
0
n,vb,vs=map(int,input().split()) l=[int(i) for i in input().split()] get=[None]*n t=0 dx,dy=map(int,input().split()) get[0]=10**9 from math import sqrt as S def dist(x1,y1,x2,y2): return S((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) def time(d,v): return d/v prev=0 for i in range(1,n): #t=0 t1...
Title: Running Student Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: And again a misfortune fell on Poor Student. He is being late for an exam. Having rushed to a bus stop that is in point (0,<=0), he got on a minibus and they drove along a straight line, parallel to axis *OX*, in the direct...
```python n,vb,vs=map(int,input().split()) l=[int(i) for i in input().split()] get=[None]*n t=0 dx,dy=map(int,input().split()) get[0]=10**9 from math import sqrt as S def dist(x1,y1,x2,y2): return S((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) def time(d,v): return d/v prev=0 for i in range(1,n): #t...
3.86
489
C
Given Length and Sum of Digits...
PROGRAMMING
1,400
[ "dp", "greedy", "implementation" ]
null
null
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers.
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
[ "2 15\n", "3 0\n" ]
[ "69 96\n", "-1 -1\n" ]
none
1,500
[ { "input": "2 15", "output": "69 96" }, { "input": "3 0", "output": "-1 -1" }, { "input": "2 1", "output": "10 10" }, { "input": "3 10", "output": "109 910" }, { "input": "100 100", "output": "1000000000000000000000000000000000000000000000000000000000000000000...
1,693,754,721
21
Python 3
WRONG_ANSWER
TESTS
2
31
0
i,j=map(int,input().split()) tmp1=i tmp2=j sol1=[0]*tmp1 idx=-1 for q in range(1,i+1) : sol1[idx]=min((tmp2-(i-q)),9) tmp2-=sol1[idx] idx-=1 arr=[] tmp=0 for i in sol1 : tmp+=i tmp*=10 arr.append(tmp//10) tmp=0 for i in range(len(sol1)-1,-1,-1) : tmp+=sol1[i] tmp*=10 a...
Title: Given Length and Sum of Digits... Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should ...
```python i,j=map(int,input().split()) tmp1=i tmp2=j sol1=[0]*tmp1 idx=-1 for q in range(1,i+1) : sol1[idx]=min((tmp2-(i-q)),9) tmp2-=sol1[idx] idx-=1 arr=[] tmp=0 for i in sol1 : tmp+=i tmp*=10 arr.append(tmp//10) tmp=0 for i in range(len(sol1)-1,-1,-1) : tmp+=sol1[i] ...
0
272
C
Dima and Staircase
PROGRAMMING
1,500
[ "data structures", "implementation" ]
null
null
Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*). Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The *i*-th box has width *w**i...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of stairs in the staircase. The second line contains a non-decreasing sequence, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109; *a**i*<=≤<=*a**i*<=+<=1). The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the numbe...
Print *m* integers — for each box the height, where the bottom of the box will be after landing. Print the answers for the boxes in the order, in which the boxes are given in the input. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I...
[ "5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3\n", "3\n1 2 3\n2\n1 1\n3 1\n", "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10\n" ]
[ "1\n3\n4\n6\n", "1\n3\n", "1\n3\n13\n23\n33\n" ]
The first sample are shown on the picture.
1,500
[ { "input": "5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3", "output": "1\n3\n4\n6" }, { "input": "3\n1 2 3\n2\n1 1\n3 1", "output": "1\n3" }, { "input": "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10", "output": "1\n3\n13\n23\n33" }, { "input": "8\n6 10 18 23 30 31 31 33\n1\n5 3", "output":...
1,628,879,472
2,147,483,647
Python 3
OK
TESTS
48
872
15,155,200
I=lambda:map(int,input().split()) n,=I() l=[*I()] m,=I() q=0 r="" for i in range(m): w,h=I() q=max(q,l[w-1]) r+=str(q)+"\n" q+=h print(r)
Title: Dima and Staircase Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*). Dima decided to play with the st...
```python I=lambda:map(int,input().split()) n,=I() l=[*I()] m,=I() q=0 r="" for i in range(m): w,h=I() q=max(q,l[w-1]) r+=str(q)+"\n" q+=h print(r) ```
3
291
A
Spyke Talks
PROGRAMMING
800
[ "*special", "implementation", "sortings" ]
null
null
Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session numbe...
The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the number of secretaries in Polycarpus's corporation. The next line contains *n* space-separated integers: *id*1,<=*id*2,<=...,<=*id**n* (0<=≤<=*id**i*<=≤<=109). Number *id**i* equals the number of the call session of the *i*-th secretary, if the secretary is t...
Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place.
[ "6\n0 1 7 1 7 10\n", "3\n1 1 1\n", "1\n0\n" ]
[ "2\n", "-1\n", "0\n" ]
In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed.
500
[ { "input": "6\n0 1 7 1 7 10", "output": "2" }, { "input": "3\n1 1 1", "output": "-1" }, { "input": "1\n0", "output": "0" }, { "input": "5\n2 2 1 1 3", "output": "2" }, { "input": "1\n1", "output": "0" }, { "input": "10\n4 21 3 21 21 1 1 2 2 3", "ou...
1,625,061,396
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
92
0
n = int(input()) li = list(map(int,input().split())) a = list(set(li)) c = 0 for i in range(len(a)): if li.count(a[i])==2: c+=1 if n==1: print(0) elif c>0: print(c) else: print(-1)
Title: Spyke Talks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each othe...
```python n = int(input()) li = list(map(int,input().split())) a = list(set(li)) c = 0 for i in range(len(a)): if li.count(a[i])==2: c+=1 if n==1: print(0) elif c>0: print(c) else: print(-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*<=&gt;<=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,485,040,570
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
5,120,000
from collections import Counter n, ss = int(input()), map(int, input().split()) counts = Counter(ss) sieve = [1] * (max(counts)+1) for i in range(2, len(sieve)): for j in range(2*i, len(sieve), i): sieve[i] += counts[j] sieve[1] = min(sieve[1], 1) print(max(sieve))
Title: Bash's Big Day Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon fr...
```python from collections import Counter n, ss = int(input()), map(int, input().split()) counts = Counter(ss) sieve = [1] * (max(counts)+1) for i in range(2, len(sieve)): for j in range(2*i, len(sieve), i): sieve[i] += counts[j] sieve[1] = min(sieve[1], 1) print(max(sieve)) ```
0
237
A
Free Cash
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is...
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
[ "4\n8 0\n8 10\n8 10\n8 45\n", "3\n0 12\n10 11\n22 22\n" ]
[ "2\n", "1\n" ]
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so ...
500
[ { "input": "4\n8 0\n8 10\n8 10\n8 45", "output": "2" }, { "input": "3\n0 12\n10 11\n22 22", "output": "1" }, { "input": "5\n12 8\n15 27\n15 27\n16 2\n19 52", "output": "2" }, { "input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23", "output": "3" }, { "input": "...
1,684,660,183
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
19
2,000
15,257,600
n=int(input()) l=[] for i in range(n): h,m=map(int,input().split()) l.append([h,m]) d=1 for i in range(len(l)): c=0 while (i+c)<len(l) and l[i+c]==l[i]: c+=1 if c>d: d=c print(d)
Title: Free Cash Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l...
```python n=int(input()) l=[] for i in range(n): h,m=map(int,input().split()) l.append([h,m]) d=1 for i in range(len(l)): c=0 while (i+c)<len(l) and l[i+c]==l[i]: c+=1 if c>d: d=c print(d) ```
0
22
A
Second Order Statistics
PROGRAMMING
800
[ "brute force" ]
A. Second Order Statistics
2
256
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ...
The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
[ "4\n1 2 2 -4\n", "5\n1 2 3 1 1\n" ]
[ "1\n", "2\n" ]
none
0
[ { "input": "4\n1 2 2 -4", "output": "1" }, { "input": "5\n1 2 3 1 1", "output": "2" }, { "input": "1\n28", "output": "NO" }, { "input": "2\n-28 12", "output": "12" }, { "input": "3\n-83 40 -80", "output": "-80" }, { "input": "8\n93 77 -92 26 21 -48 53 ...
1,592,853,187
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
186
6,656,000
N=int(input()) Cont=0 R = list(map(int, input().rstrip().split())) for i in range (len(R)): if (R[i] > R[i-1]): Cont=i print(Cont)
Title: Second Order Statistics Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis...
```python N=int(input()) Cont=0 R = list(map(int, input().rstrip().split())) for i in range (len(R)): if (R[i] > R[i-1]): Cont=i print(Cont) ```
0
155
A
I_love_\%username\%
PROGRAMMING
800
[ "brute force" ]
null
null
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e...
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ...
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
[ "5\n100 50 200 150 200\n", "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n" ]
[ "2\n", "4\n" ]
In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
500
[ { "input": "5\n100 50 200 150 200", "output": "2" }, { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242", "output": "4" }, { "input": "1\n6", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "5\n100 36 53 7 81", "output": "2" ...
1,699,261,867
2,147,483,647
Python 3
OK
TESTS
37
92
0
n=int(input()) a=[int(i) for i in input().split()] mini=maxi=a[0] ans=0 for i in range(1,n): if a[i]<mini: mini=a[i] ans+=1 if a[i]>maxi: maxi=a[i] ans+=1 print(ans)
Title: I_love_\%username\% Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the re...
```python n=int(input()) a=[int(i) for i in input().split()] mini=maxi=a[0] ans=0 for i in range(1,n): if a[i]<mini: mini=a[i] ans+=1 if a[i]>maxi: maxi=a[i] ans+=1 print(ans) ```
3
346
B
Lucky Common Subsequence
PROGRAMMING
2,000
[ "dp", "strings" ]
null
null
In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substri...
The input contains three strings in three separate lines: *s*1, *s*2 and *virus* (1<=≤<=|*s*1|,<=|*s*2|,<=|*virus*|<=≤<=100). Each string consists only of uppercase English letters.
Output the longest common subsequence of *s*1 and *s*2 without *virus* as a substring. If there are multiple answers, any of them will be accepted. If there is no valid common subsequence, output 0.
[ "AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ\n", "AA\nA\nA\n" ]
[ "ORZ\n", "0\n" ]
none
1,000
[ { "input": "AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ", "output": "ORZ" }, { "input": "AA\nA\nA", "output": "0" }, { "input": "PWBJTZPQHA\nZJMKLWSROQ\nUQ", "output": "WQ" }, { "input": "QNHRPFYMAAPJDUHBAEXNEEZSTMYHVGQPYKNMVKMBVSVLIYGUVMJHEFLJEPIWFHSLISTGOKRXNMSCXYKMAXBPKCOCNTIRPCU...
1,684,595,180
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
60
102,400
def LCS(X, Y): m = len(X) n = len(Y) c = [[0 for _ in range (n+1)]for _ in range(m+1)] for i in range (1,m+1): for j in range(1,n+1): if X[i-1] == Y[j-1]: c[i][j] = c[i-1][j-1] + 1 else: c[i][j] = max(c[i-1][j], c[i][j-1]) r...
Title: Lucky Common Subsequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequen...
```python def LCS(X, Y): m = len(X) n = len(Y) c = [[0 for _ in range (n+1)]for _ in range(m+1)] for i in range (1,m+1): for j in range(1,n+1): if X[i-1] == Y[j-1]: c[i][j] = c[i-1][j-1] + 1 else: c[i][j] = max(c[i-1][j], c[i][j-...
0
230
B
T-primes
PROGRAMMING
1,300
[ "binary search", "implementation", "math", "number theory" ]
null
null
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout st...
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
[ "3\n4 5 6\n" ]
[ "YES\nNO\nNO\n" ]
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
500
[ { "input": "3\n4 5 6", "output": "YES\nNO\nNO" }, { "input": "2\n48 49", "output": "NO\nYES" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO" }, { "input": "1\n36", "output": "NO" }, { "input": "1\n999966000289", "...
1,696,931,353
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
n = int(input()) numlist = list(map(int,input().split())) for i in numlist: if i **(1/2) % 1 != 0: print("NO") else: k = i ** (1/2) count = 0 for m in range(1,k//2+1): if k % m == 0: count += 1 if count == 0: print("YES"...
Title: T-primes Time Limit: None seconds Memory Limit: None megabytes Problem Description: We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an ar...
```python n = int(input()) numlist = list(map(int,input().split())) for i in numlist: if i **(1/2) % 1 != 0: print("NO") else: k = i ** (1/2) count = 0 for m in range(1,k//2+1): if k % m == 0: count += 1 if count == 0: p...
-1
889
E
Mod Mod Mod
PROGRAMMING
3,000
[ "binary search", "dp", "math" ]
null
null
You are given a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. Let , and for 1<=≤<=*i*<=&lt;<=*n*. Here, denotes the modulus operation. Find the maximum value of *f*(*x*,<=1) over all nonnegative integers *x*.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200000) — the length of the sequence. The second lines contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1013) — the elements of the sequence.
Output a single integer — the maximum value of *f*(*x*,<=1) over all nonnegative integers *x*.
[ "2\n10 5\n", "5\n5 4 3 2 1\n", "4\n5 10 5 10\n" ]
[ "13\n", "6\n", "16\n" ]
In the first example you can choose, for example, *x* = 19. In the second example you can choose, for example, *x* = 3 or *x* = 2.
2,250
[]
1,510,955,726
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
1,247
0
import math n=int(input()) list_a=[int(z) for z in input().split()] list_out=[int(z) for z in range(0,n)] _max=0 for i in range(0,n-1): for x in range(0,200000): list_out[i]= int(math.fmod(x,list_a[i]) + math.fmod( math.fmod(x,list_a[i]),list_a[i+1])) if list_out[i] > _max: _max=list_out[i] print(_...
Title: Mod Mod Mod Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. Let , and for 1<=≤<=*i*<=&lt;<=*n*. Here, denotes the modulus operation. Find the maximum value of *f*(*x*,<=1) over all nonnegative integers *x*. Input Sp...
```python import math n=int(input()) list_a=[int(z) for z in input().split()] list_out=[int(z) for z in range(0,n)] _max=0 for i in range(0,n-1): for x in range(0,200000): list_out[i]= int(math.fmod(x,list_a[i]) + math.fmod( math.fmod(x,list_a[i]),list_a[i+1])) if list_out[i] > _max: _max=list_out[i]...
0
570
A
Elections
PROGRAMMING
1,100
[ "implementation" ]
null
null
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in ...
The first line of the input contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of candidates and of cities, respectively. Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*j*<=≤<=*n*, 1<=≤<=*i*<=≤<=*m*, 0<=≤<=*a**ij*<=≤<=109) denotes ...
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
[ "3 3\n1 2 3\n2 3 1\n1 2 1\n", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n" ]
[ "2", "1" ]
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm...
500
[ { "input": "3 3\n1 2 3\n2 3 1\n1 2 1", "output": "2" }, { "input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "output": "1" }, { "input": "1 3\n5\n3\n2", "output": "1" }, { "input": "3 1\n1 2 3", "output": "3" }, { "input": "3 1\n100 100 100", "output": "1" }, {...
1,625,389,319
2,147,483,647
Python 3
OK
TESTS
62
77
0
x=list(map(int, input().split())) n=x[0] m=x[1] q=[] for i in range(m): y=list(map(int, input().split())) p=y.index(max(y))+1 q.append(p) freq = {} for item in q: if (item in freq): freq[item] += 1 else: freq[item] = 1 t=[k for k,v in freq.items() if float(v) == max(fre...
Title: Elections Time Limit: None seconds Memory Limit: None megabytes Problem Description: The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusu...
```python x=list(map(int, input().split())) n=x[0] m=x[1] q=[] for i in range(m): y=list(map(int, input().split())) p=y.index(max(y))+1 q.append(p) freq = {} for item in q: if (item in freq): freq[item] += 1 else: freq[item] = 1 t=[k for k,v in freq.items() if float(v) ...
3
932
F
Escape Through Leaf
PROGRAMMING
2,700
[ "data structures", "dp", "geometry" ]
null
null
You are given a tree with *n* nodes (numbered from 1 to *n*) rooted at node 1. Also, each node has two values associated with it. The values for *i*-th node are *a**i* and *b**i*. You can jump from a node to any node in its subtree. The cost of one jump from node *x* to node *y* is the product of *a**x* and *b**y*. Th...
The first line of input contains an integer *n* (2<=≤<=*n*<=≤<=105) — the number of nodes in the tree. The second line contains *n* space-separated integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n*(<=-<=105<=<=≤<=<=*a**i*<=<=≤<=<=105). The third line contains *n* space-separated integers *b*1,<=<=*b*2,<=<=...,<=<=*b**n*(<=-<...
Output *n* space-separated integers, *i*-th of which denotes the minimum cost of a path from node *i* to reach any leaf.
[ "3\n2 10 -1\n7 -7 5\n2 3\n2 1\n", "4\n5 -10 5 7\n-8 -80 -3 -10\n2 1\n2 4\n1 3\n" ]
[ "10 50 0 ", "-300 100 0 0 " ]
In the first example, node 3 is already a leaf, so the cost is 0. For node 2, jump to node 3 with cost *a*<sub class="lower-index">2</sub> × *b*<sub class="lower-index">3</sub> = 50. For node 1, jump directly to node 3 with cost *a*<sub class="lower-index">1</sub> × *b*<sub class="lower-index">3</sub> = 10. In the sec...
2,500
[ { "input": "3\n2 10 -1\n7 -7 5\n2 3\n2 1", "output": "10 50 0 " }, { "input": "4\n5 -10 5 7\n-8 -80 -3 -10\n2 1\n2 4\n1 3", "output": "-300 100 0 0 " }, { "input": "5\n7 -8 -8 -3 -10\n6 1 -6 7 5\n3 1\n2 5\n1 4\n4 5", "output": "-42 0 0 -25 -10 " }, { "input": "6\n4 -8 9 -1 -2...
1,694,988,921
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
Timestamp: 09_17_2023_18_15_20 code11
Title: Escape Through Leaf Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a tree with *n* nodes (numbered from 1 to *n*) rooted at node 1. Also, each node has two values associated with it. The values for *i*-th node are *a**i* and *b**i*. You can jump from a node to any no...
```python Timestamp: 09_17_2023_18_15_20 code11 ```
-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,622,710,643
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
109
0
n = int(input()) towns = [int(i) for i in input().split()] maxx = towns[0] minn = towns[0] for i in range(n): if i != 0 and i != n - 1: maxx = max(abs(towns[i] - towns[-1]), abs(towns[i] - towns[0])) minn = min(abs(towns[i] - towns[i - 1]), abs(towns[i] - towns[i + 1])) else: ma...
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()) towns = [int(i) for i in input().split()] maxx = towns[0] minn = towns[0] for i in range(n): if i != 0 and i != n - 1: maxx = max(abs(towns[i] - towns[-1]), abs(towns[i] - towns[0])) minn = min(abs(towns[i] - towns[i - 1]), abs(towns[i] - towns[i + 1])) else: ...
0
1,003
D
Coins and Queries
PROGRAMMING
1,600
[ "greedy" ]
null
null
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. It is guaranteed that all the values are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$). Polycarp wants to know answers on $q$ queries. The $j$-th query is described as integer number $b_j$. The answer to the query is the...
The first line of the input contains two integers $n$ and $q$ ($1 \le n, q \le 2 \cdot 10^5$) — the number of coins and the number of queries. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ — values of coins ($1 \le a_i \le 2 \cdot 10^9$). It is guaranteed that all $a_i$ are integer powers o...
Print $q$ integers $ans_j$. The $j$-th integer must be equal to the answer on the $j$-th query. If Polycarp can't obtain the value $b_j$ the answer to the $j$-th query is -1.
[ "5 4\n2 4 8 2 4\n8\n5\n14\n10\n" ]
[ "1\n-1\n3\n2\n" ]
none
0
[ { "input": "5 4\n2 4 8 2 4\n8\n5\n14\n10", "output": "1\n-1\n3\n2" }, { "input": "3 3\n1 1 1\n1\n2\n3", "output": "1\n2\n3" }, { "input": "4 1\n2 4 16 32\n14", "output": "-1" }, { "input": "1 10\n8\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16", "output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n1\...
1,595,614,301
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
139
20,480,000
#had to go through the editorial import collections n,q=map(int,input().split()) a=list(map(int,input().split())) li=[0]*32 for i,val in collections.Counter(a).items(): li[len(bin(i)[2:])-1]=val print(li) for _ in range(q): ans=0 k=int(input()) for i in range(31,-1,-1): mini=min(k>>i...
Title: Coins and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. It is guaranteed that all the values are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$). Polycarp wants to know answer...
```python #had to go through the editorial import collections n,q=map(int,input().split()) a=list(map(int,input().split())) li=[0]*32 for i,val in collections.Counter(a).items(): li[len(bin(i)[2:])-1]=val print(li) for _ in range(q): ans=0 k=int(input()) for i in range(31,-1,-1): min...
0
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,652,808,372
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
4,300,800
x=int(input(),2) y=int(input(),2) t=format((x^y),"b") print(t)
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 x=int(input(),2) y=int(input(),2) t=format((x^y),"b") print(t) ```
0
975
B
Mancala
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next ...
The only line contains 14 integers $a_1, a_2, \ldots, a_{14}$ ($0 \leq a_i \leq 10^9$) — the number of stones in each hole. It is guaranteed that for any $i$ ($1\leq i \leq 14$) $a_i$ is either zero or odd, and there is at least one stone in the board.
Output one integer, the maximum possible score after one move.
[ "0 1 1 0 0 0 0 0 0 7 0 0 0 0\n", "5 1 1 1 1 0 0 0 0 0 0 0 0 0\n" ]
[ "4\n", "8\n" ]
In the first test case the board after the move from the hole with $7$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $4$.
1,000
[ { "input": "0 1 1 0 0 0 0 0 0 7 0 0 0 0", "output": "4" }, { "input": "5 1 1 1 1 0 0 0 0 0 0 0 0 0", "output": "8" }, { "input": "10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 1", "output": "54294" }, { "input": "0 0 0 0 0 0 0 0 0 0 0 0 0 15", ...
1,602,353,643
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
140
1,331,200
w = list(map(int,input().split())) n = len(w) ma = max(w) res = 0 ind = w.index(ma) while(ma!=0): ind += 1 ind = ind%n w[ind] += 1 ma -= 1 for j in range(n): if(w[j]%2 == 0): res += w[j] print(res)
Title: Mancala Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. ...
```python w = list(map(int,input().split())) n = len(w) ma = max(w) res = 0 ind = w.index(ma) while(ma!=0): ind += 1 ind = ind%n w[ind] += 1 ma -= 1 for j in range(n): if(w[j]%2 == 0): res += w[j] print(res) ```
0
780
A
Andryusha and Socks
PROGRAMMING
800
[ "implementation" ]
null
null
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ...
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs. The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ...
Print single integer — the maximum number of socks that were on the table at the same time.
[ "1\n1 1\n", "3\n2 1 1 3 2 3\n" ]
[ "1\n", "2\n" ]
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - ...
500
[ { "input": "1\n1 1", "output": "1" }, { "input": "3\n2 1 1 3 2 3", "output": "2" }, { "input": "5\n5 1 3 2 4 3 1 2 4 5", "output": "5" }, { "input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7", "output": "6" }, { "input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ...
1,499,603,519
2,147,483,647
Python 3
OK
TESTS
56
202
19,558,400
import sys n = int(input()) an = list(map(int, sys.stdin.readline().split())) ans = 0 cur = 0 on_table = set() for x in an: if x in on_table: on_table.remove(x) else: on_table.add(x) if len(on_table) > ans: ans = len(on_table) print(ans)
Title: Andryusha and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere...
```python import sys n = int(input()) an = list(map(int, sys.stdin.readline().split())) ans = 0 cur = 0 on_table = set() for x in an: if x in on_table: on_table.remove(x) else: on_table.add(x) if len(on_table) > ans: ans = len(on_table) print(ans) ```
3
165
B
Burning Midnight Oil
PROGRAMMING
1,500
[ "binary search", "implementation" ]
null
null
One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lin...
The input consists of two integers *n* and *k*, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1<=≤<=*n*<=≤<=109, 2<=≤<=*k*<=≤<=10.
Print the only integer — the minimum value of *v* that lets Vasya write the program in one night.
[ "7 2\n", "59 9\n" ]
[ "4\n", "54\n" ]
In the first sample the answer is *v* = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task. In the second sample the answer is *v* = 54. Vasya writes the code in the following por...
1,000
[ { "input": "7 2", "output": "4" }, { "input": "59 9", "output": "54" }, { "input": "1 9", "output": "1" }, { "input": "11 2", "output": "7" }, { "input": "747 2", "output": "376" }, { "input": "6578 2", "output": "3293" }, { "input": "37212...
1,614,837,690
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
154
0
def sum_func(v,k): p = 0 sums = 0 while v//k**p != 0: sums += v//k**p p += 1 return sums def search_v(n,k): k = k lo = 0 hi = n while (lo<=hi): v = (lo + hi) // 2 if (sum_func(v,k) > n): hi = v - 1 elif (sum_func(v,...
Title: Burning Midnight Oil Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of c...
```python def sum_func(v,k): p = 0 sums = 0 while v//k**p != 0: sums += v//k**p p += 1 return sums def search_v(n,k): k = k lo = 0 hi = n while (lo<=hi): v = (lo + hi) // 2 if (sum_func(v,k) > n): hi = v - 1 elif (s...
0
185
A
Plant
PROGRAMMING
1,300
[ "math" ]
null
null
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divide...
The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Print a single integer — the remainder of dividing the number of plants that will point "upwards" in *n* years by 1000000007 (109<=+<=7).
[ "1\n", "2\n" ]
[ "3\n", "10\n" ]
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
500
[ { "input": "1", "output": "3" }, { "input": "2", "output": "10" }, { "input": "385599124", "output": "493875375" }, { "input": "989464295", "output": "31966163" }, { "input": "376367012", "output": "523204186" }, { "input": "529357306", "output": "...
1,687,016,965
2,147,483,647
PyPy 3-64
OK
TESTS
49
124
0
def mult(a,b,m): n1,m1=len(a),len(a[0]) n2,m2=len(b),len(b[0]) if m1!=n2: raise Exception('Dimension error') c=[[0]*m2 for i in range(n1)] for i in range(m2): for j in range(n1): for k in range(n2): c[j][i]=(c[j][i]+b[k][i]*a[j][k])%m return c def ...
Title: Plant Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will poi...
```python def mult(a,b,m): n1,m1=len(a),len(a[0]) n2,m2=len(b),len(b[0]) if m1!=n2: raise Exception('Dimension error') c=[[0]*m2 for i in range(n1)] for i in range(m2): for j in range(n1): for k in range(n2): c[j][i]=(c[j][i]+b[k][i]*a[j][k])%m return...
3
998
B
Cutting
PROGRAMMING
1,200
[ "dp", "greedy", "sortings" ]
null
null
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers. There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulti...
First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have. Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal...
Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins.
[ "6 4\n1 2 5 10 15 20\n", "4 10\n1 3 2 4\n", "6 100\n1 2 3 4 5 6\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins. In the second sample it is not possible to make even one cut even with unlimited number of bitcoins. In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$....
1,000
[ { "input": "6 4\n1 2 5 10 15 20", "output": "1" }, { "input": "4 10\n1 3 2 4", "output": "0" }, { "input": "6 100\n1 2 3 4 5 6", "output": "2" }, { "input": "2 100\n13 78", "output": "0" }, { "input": "10 1\n56 56 98 2 11 64 97 41 95 53", "output": "0" }, ...
1,667,081,964
2,147,483,647
Python 3
OK
TESTS
34
46
0
def cutting(n, b, array): # print(n, b, array) odd, even = 0, 0 for val in array: if val % 2 == 0: even += 1 else: odd += 1 new_odd, new_even = 0, 0 if array[0] % 2 == 0: new_even += 1; even -= 1 else: new_odd += 1; odd -= 1 # print("odd, even", o...
Title: Cutting Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers. There is a sequence of integers, which contains the equal number of even and odd numbers. Gi...
```python def cutting(n, b, array): # print(n, b, array) odd, even = 0, 0 for val in array: if val % 2 == 0: even += 1 else: odd += 1 new_odd, new_even = 0, 0 if array[0] % 2 == 0: new_even += 1; even -= 1 else: new_odd += 1; odd -= 1 # print("odd...
3
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th...
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 ...
1,679,954,375
2,147,483,647
PyPy 3-64
OK
TESTS
34
62
0
n = int(input()) lista = list(map(int, input().split())) l = 0 r = n-1 sereja = 0 dima = 0 i = 0 while (l <= r): maximo = max(lista[l], lista[r]) if maximo == lista[l]: if i % 2 == 0: sereja += lista[l] l += 1 else: dima += lista[l] l += 1 else: if i % 2 == 0: ...
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du...
```python n = int(input()) lista = list(map(int, input().split())) l = 0 r = n-1 sereja = 0 dima = 0 i = 0 while (l <= r): maximo = max(lista[l], lista[r]) if maximo == lista[l]: if i % 2 == 0: sereja += lista[l] l += 1 else: dima += lista[l] l += 1 else: if i ...
3
45
D
Event Dates
PROGRAMMING
1,900
[ "greedy", "meet-in-the-middle", "sortings" ]
D. Event Dates
2
256
On a history lesson the teacher asked Vasya to name the dates when *n* famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [*l**i*,<=*r**i*] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of known events. Then follow *n* lines containing two integers *l**i* and *r**i* each (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=107) — the earliest acceptable date and the latest acceptable date of the *i*-th event.
Print *n* numbers — the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
[ "3\n1 2\n2 3\n3 4\n", "2\n1 3\n1 3\n" ]
[ "1 2 3 \n", "1 2 \n" ]
none
0
[ { "input": "3\n1 2\n2 3\n3 4", "output": "1 2 3 " }, { "input": "2\n1 3\n1 3", "output": "1 2 " }, { "input": "10\n1 10\n3 4\n8 10\n3 4\n5 9\n1 4\n7 10\n1 9\n1 8\n4 10", "output": "7 3 10 4 6 1 9 5 2 8 " }, { "input": "10\n1 1\n8 10\n1 7\n6 8\n5 7\n1 9\n8 8\n6 10\n1 4\n3 4", ...
1,629,485,835
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
186
20,172,800
def process(A): A = sorted(A) answer = [] for l, r in A: if len(answer)==0: answer.append(l) else: x = answer[-1] if l <= x+1 <= r: answer.append(x+1) else: answer.append(l) return answer t = i...
Title: Event Dates Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: On a history lesson the teacher asked Vasya to name the dates when *n* famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [*l**i*,<=*r**i*] (inclusive) on which the event could hav...
```python def process(A): A = sorted(A) answer = [] for l, r in A: if len(answer)==0: answer.append(l) else: x = answer[-1] if l <= x+1 <= r: answer.append(x+1) else: answer.append(l) return answe...
0
259
B
Little Elephant and Magic Square
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Little Elephant loves magic squares very much. A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals ...
The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented...
Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditio...
[ "0 1 1\n1 0 1\n1 1 0\n", "0 3 6\n5 0 5\n4 7 0\n" ]
[ "1 1 1\n1 1 1\n1 1 1\n", "6 3 6\n5 5 5\n4 7 4\n" ]
none
1,000
[ { "input": "0 1 1\n1 0 1\n1 1 0", "output": "1 1 1\n1 1 1\n1 1 1" }, { "input": "0 3 6\n5 0 5\n4 7 0", "output": "6 3 6\n5 5 5\n4 7 4" }, { "input": "0 4 4\n4 0 4\n4 4 0", "output": "4 4 4\n4 4 4\n4 4 4" }, { "input": "0 54 48\n36 0 78\n66 60 0", "output": "69 54 48\n36 5...
1,622,639,674
2,147,483,647
Python 3
OK
TESTS
24
248
0
mat = [] for i in range(3): row = list(map(int, input().split())) mat.append(row) sm = (sum(mat[0]) + sum(mat[1]) + sum(mat[2]))//2 mat[0][0] = sm - mat[0][1] - mat[0][2] mat[1][1] = sm - mat[1][0] - mat[1][2] mat[2][2] = sm - mat[2][0] - mat[2][1] for i in range(3): print(*mat[i])
Title: Little Elephant and Magic Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Elephant loves magic squares very much. A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table ...
```python mat = [] for i in range(3): row = list(map(int, input().split())) mat.append(row) sm = (sum(mat[0]) + sum(mat[1]) + sum(mat[2]))//2 mat[0][0] = sm - mat[0][1] - mat[0][2] mat[1][1] = sm - mat[1][0] - mat[1][2] mat[2][2] = sm - mat[2][0] - mat[2][1] for i in range(3): print(*mat[i]) ```
3
63
A
Sinking Ship
PROGRAMMING
900
[ "implementation", "sortings", "strings" ]
A. Sinking Ship
2
256
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a stri...
The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spa...
Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship.
[ "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n" ]
[ "Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n" ]
none
500
[ { "input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack" }, { "input": "1\nA captain", "output": "A" }, { "input": "1\nAbcdefjhij captain", "output": "Abcdefjhij" }, { "input": "5\nA captain...
1,662,889,114
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
CM = int(input()) Array = [] R = [] CW = [] M = [] Cap = [] for i in range(0,CM): ele = input() Array.append(ele) Array = " ".join(Array) print(Array) Array = Array.split(" ") print(Array) for j in range(0,len(Array)): if Array[j] == "rat": R.append(Array[j-1]) elif Array[j] == "...
Title: Sinking Ship Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to ...
```python CM = int(input()) Array = [] R = [] CW = [] M = [] Cap = [] for i in range(0,CM): ele = input() Array.append(ele) Array = " ".join(Array) print(Array) Array = Array.split(" ") print(Array) for j in range(0,len(Array)): if Array[j] == "rat": R.append(Array[j-1]) elif Arr...
0
712
E
Memory and Casinos
PROGRAMMING
2,500
[ "data structures", "math", "probabilities" ]
null
null
There are *n* casinos lined in a row. If Memory plays at casino *i*, he has probability *p**i* to win and move to the casino on the right (*i*<=+<=1) or exit the row (if *i*<==<=*n*), and a probability 1<=-<=*p**i* to lose and move to the casino on the left (*i*<=-<=1) or also exit the row (if *i*<==<=1). We say that...
The first line of the input contains two integers *n* and *q*(1<=≤<=*n*,<=*q*<=≤<=100<=000),  — number of casinos and number of requests respectively. The next *n* lines each contain integers *a**i* and *b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=109)  — is the probability *p**i* of winning in casino *i*. The next *q* li...
Print a real number for every request of type 2 — the probability that boy will "dominate" on that interval. Your answer will be considered correct if its absolute error does not exceed 10<=-<=4. Namely: let's assume that one of your answers is *a*, and the corresponding answer of the jury is *b*. The checker program ...
[ "3 13\n1 3\n1 2\n2 3\n2 1 1\n2 1 2\n2 1 3\n2 2 2\n2 2 3\n2 3 3\n1 2 2 3\n2 1 1\n2 1 2\n2 1 3\n2 2 2\n2 2 3\n2 3 3\n" ]
[ "0.3333333333\n0.2000000000\n0.1666666667\n0.5000000000\n0.4000000000\n0.6666666667\n0.3333333333\n0.2500000000\n0.2222222222\n0.6666666667\n0.5714285714\n0.6666666667\n" ]
none
2,500
[]
1,689,650,479
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689650479.7468753")# 1689650479.7468953
Title: Memory and Casinos Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* casinos lined in a row. If Memory plays at casino *i*, he has probability *p**i* to win and move to the casino on the right (*i*<=+<=1) or exit the row (if *i*<==<=*n*), and a probability 1<=-<=*p**i* t...
```python print("_RANDOM_GUESS_1689650479.7468753")# 1689650479.7468953 ```
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,694,578,649
2,147,483,647
Python 3
OK
TESTS
32
92
0
n=int(input()) data=[int(x)%2 for x in input().split()] if data[0]!=data[1]: if data[0]==data[2]: print(2) else: print(1) else: for i in range(2,n): if data[i]!=data[0]: print(i+1) break
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python n=int(input()) data=[int(x)%2 for x in input().split()] if data[0]!=data[1]: if data[0]==data[2]: print(2) else: print(1) else: for i in range(2,n): if data[i]!=data[0]: print(i+1) break ```
3.977
913
A
Modular Exponentiation
PROGRAMMING
900
[ "implementation", "math" ]
null
null
The following problem is well-known: given integers *n* and *m*, calculate where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*. You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108). The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108).
Output a single integer — the value of .
[ "4\n42\n", "1\n58\n", "98765432\n23456789\n" ]
[ "10\n", "0\n", "23456789\n" ]
In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10. In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0.
500
[ { "input": "4\n42", "output": "10" }, { "input": "1\n58", "output": "0" }, { "input": "98765432\n23456789", "output": "23456789" }, { "input": "8\n88127381", "output": "149" }, { "input": "32\n92831989", "output": "92831989" }, { "input": "92831989\n25...
1,699,573,400
2,147,483,647
Python 3
OK
TESTS
49
530
47,001,600
def modular_exponentiation(n, m): return m % 2 ** n if __name__ == "__main__": n = int(input()) m = int(input()) invertido = modular_exponentiation(n, m) print(invertido)
Title: Modular Exponentiation Time Limit: None seconds Memory Limit: None megabytes Problem Description: The following problem is well-known: given integers *n* and *m*, calculate where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*. You are asked to solve the "reverse" prob...
```python def modular_exponentiation(n, m): return m % 2 ** n if __name__ == "__main__": n = int(input()) m = int(input()) invertido = modular_exponentiation(n, m) print(invertido) ```
3
468
C
Hack it!
PROGRAMMING
2,500
[ "binary search", "constructive algorithms", "math" ]
null
null
Little X has met the following problem recently. Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen...
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1018).
Print two integers: *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=&lt;<=10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists.
[ "46\n", "126444381000032\n" ]
[ "1 10\n", "2333333 2333333333333\n" ]
none
1,500
[ { "input": "46", "output": "1 10" }, { "input": "126444381000032", "output": "2333333 2333333333333" }, { "input": "69645082595", "output": "613752823618441225798858488535 713259406474207764329704856394" }, { "input": "70602205995", "output": "11 2492213340204320744986569...
1,642,772,461
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
a = int(input()) num = 45 * (10 ** 100) L = 0 R = (10 ** 100) - 1 x = (a + (a - (num % a))) print(x,x + R)
Title: Hack it! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little X has met the following problem recently. Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate Of course Little X ...
```python a = int(input()) num = 45 * (10 ** 100) L = 0 R = (10 ** 100) - 1 x = (a + (a - (num % a))) print(x,x + R) ```
0
265
B
Roadside Trees (Simplified Edition)
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the fol...
The first line contains an integer *n* (1<=<=≤<=<=*n*<=≤<=105) — the number of trees. Next *n* lines contains the height of trees: *i*-th line contains an integer *h**i* (1<=≤<=*h**i*<=≤<=104) — the height of the tree with the number *i*.
Print a single integer — the minimal time required to eat all nuts in seconds.
[ "2\n1\n2\n", "5\n2\n1\n2\n1\n1\n" ]
[ "5\n", "14\n" ]
none
1,000
[ { "input": "2\n1\n2", "output": "5" }, { "input": "5\n2\n1\n2\n1\n1", "output": "14" }, { "input": "1\n1", "output": "2" } ]
1,588,174,008
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
186
0
n=int(input()) for i in range(n): m=int(input()) else: print((n-1)*3+2)
Title: Roadside Trees (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wan...
```python n=int(input()) for i in range(n): m=int(input()) else: print((n-1)*3+2) ```
0
837
A
Text Volume
PROGRAMMING
800
[ "implementation" ]
null
null
You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text. Calculate the volume of the given text.
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text. The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters.
Print one integer number — volume of text.
[ "7\nNonZERO\n", "24\nthis is zero answer text\n", "24\nHarbour Space University\n" ]
[ "5\n", "0\n", "1\n" ]
In the first example there is only one word, there are 5 capital letters in it. In the second example all of the words contain 0 capital letters.
0
[ { "input": "7\nNonZERO", "output": "5" }, { "input": "24\nthis is zero answer text", "output": "0" }, { "input": "24\nHarbour Space University", "output": "1" }, { "input": "2\nWM", "output": "2" }, { "input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd...
1,503,433,582
2,147,483,647
Python 3
OK
TESTS
29
62
0
inp = int(input()) mas = list(input().split()) maxx = 0 for i in mas: now = 0 for j in i: #print(ord(j)) if ord(j) < 91: now += 1 if maxx < now: maxx = now print(maxx)
Title: Text Volume Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex...
```python inp = int(input()) mas = list(input().split()) maxx = 0 for i in mas: now = 0 for j in i: #print(ord(j)) if ord(j) < 91: now += 1 if maxx < now: maxx = now print(maxx) ```
3
617
A
Elephant
PROGRAMMING
800
[ "math" ]
null
null
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ...
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
[ "5\n", "12\n" ]
[ "1\n", "3\n" ]
In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
500
[ { "input": "5", "output": "1" }, { "input": "12", "output": "3" }, { "input": "999999", "output": "200000" }, { "input": "41", "output": "9" }, { "input": "1000000", "output": "200000" }, { "input": "1", "output": "1" }, { "input": "2", ...
1,697,787,993
2,147,483,647
Python 3
OK
TESTS
34
46
0
x=int(input()) step=[5,4,3,2,1] ct=0 y=len(step) for i in range (y): if(x>=step[i]): ct=ct+ (x//step[i]) x=x%step[i] print(ct)
Title: Elephant Time Limit: None seconds Memory Limit: None megabytes Problem Description: An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2...
```python x=int(input()) step=[5,4,3,2,1] ct=0 y=len(step) for i in range (y): if(x>=step[i]): ct=ct+ (x//step[i]) x=x%step[i] print(ct) ```
3
399
A
Pages
PROGRAMMING
0
[ "implementation" ]
null
null
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this: When someone clicks the button "&lt;&lt;" he is redirected to page 1, and wh...
The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*)
Print the proper navigation. Follow the format of the output from the test samples.
[ "17 5 2\n", "6 5 2\n", "6 1 2\n", "6 2 2\n", "9 6 3\n", "10 6 3\n", "8 5 4\n" ]
[ "&lt;&lt; 3 4 (5) 6 7 &gt;&gt; ", "&lt;&lt; 3 4 (5) 6 ", "(1) 2 3 &gt;&gt; ", "1 (2) 3 4 &gt;&gt;", "&lt;&lt; 3 4 5 (6) 7 8 9", "&lt;&lt; 3 4 5 (6) 7 8 9 &gt;&gt;", "1 2 3 4 (5) 6 7 8 " ]
none
500
[ { "input": "17 5 2", "output": "<< 3 4 (5) 6 7 >> " }, { "input": "6 5 2", "output": "<< 3 4 (5) 6 " }, { "input": "6 1 2", "output": "(1) 2 3 >> " }, { "input": "6 2 2", "output": "1 (2) 3 4 >> " }, { "input": "9 6 3", "output": "<< 3 4 5 (6) 7 8 9 " }, {...
1,689,601,934
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689601933.9651673")# 1689601933.9651866
Title: Pages Time Limit: None seconds Memory Limit: None megabytes Problem Description: User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will lo...
```python print("_RANDOM_GUESS_1689601933.9651673")# 1689601933.9651866 ```
0
950
A
Left-handers, Right-handers and Ambidexters
PROGRAMMING
800
[ "implementation", "math" ]
null
null
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and ...
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
[ "1 4 2\n", "5 5 5\n", "0 2 0\n" ]
[ "6\n", "14\n", "0\n" ]
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five l...
500
[ { "input": "1 4 2", "output": "6" }, { "input": "5 5 5", "output": "14" }, { "input": "0 2 0", "output": "0" }, { "input": "30 70 34", "output": "128" }, { "input": "89 32 24", "output": "112" }, { "input": "89 44 77", "output": "210" }, { ...
1,574,412,995
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
124
0
l, r, a = map(int, input().split()) mini = min(l, r) maxi = max(l, r) cnt = 2 * mini if a % 2 == 0: cnt += a else: cnt += a - 1 print(cnt)
Title: Left-handers, Right-handers and Ambidexters Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand....
```python l, r, a = map(int, input().split()) mini = min(l, r) maxi = max(l, r) cnt = 2 * mini if a % 2 == 0: cnt += a else: cnt += a - 1 print(cnt) ```
0
514
B
Han Solo and Lazer Gun
PROGRAMMING
1,400
[ "brute force", "data structures", "geometry", "implementation", "math" ]
null
null
There are *n* Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (*x*,<=*y*) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (*x*0,<=*y*0). In one shot...
The first line contains three integers *n*, *x*0 и *y*0 (1<=≤<=*n*<=≤<=1000, <=-<=104<=≤<=*x*0,<=*y*0<=≤<=104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next *n* lines contain two integers each *x**i*, *y**i* (<=-<=104<=≤<=*x**i*,<=*y**i*<=≤<=104) — the coordinates of the storm...
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
[ "4 0 0\n1 1\n2 2\n2 0\n-1 -1\n", "2 1 2\n1 1\n1 0\n" ]
[ "2\n", "1\n" ]
Explanation to the first and second samples from the statement, respectively:
1,000
[ { "input": "4 0 0\n1 1\n2 2\n2 0\n-1 -1", "output": "2" }, { "input": "2 1 2\n1 1\n1 0", "output": "1" }, { "input": "1 1 1\n0 0", "output": "1" }, { "input": "2 0 0\n10000 -10000\n-10000 10000", "output": "1" }, { "input": "2 0 0\n10000 -10000\n10000 10000", ...
1,690,227,626
2,147,483,647
PyPy 3-64
OK
TESTS
29
77
2,252,800
import sys # sys.stdin = open(".in", "r") # sys.stdout = open(".out", "w") input = sys.stdin.readline def print(*args, end='\n', sep=' ') -> None: sys.stdout.write(sep.join(map(str, args)) + end) def map_int(): return map(int, input().split()) def list_int(): return list(map(int, input().split())) from coll...
Title: Han Solo and Lazer Gun Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (*x*,<=*y*) on this plane. Han Solo has the ...
```python import sys # sys.stdin = open(".in", "r") # sys.stdout = open(".out", "w") input = sys.stdin.readline def print(*args, end='\n', sep=' ') -> None: sys.stdout.write(sep.join(map(str, args)) + end) def map_int(): return map(int, input().split()) def list_int(): return list(map(int, input().split()))...
3
339
A
Helpful Maths
PROGRAMMING
800
[ "greedy", "implementation", "sortings", "strings" ]
null
null
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe...
The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Print the new sum that Xenia can count.
[ "3+2+1\n", "1+1+3+1+3\n", "2\n" ]
[ "1+2+3\n", "1+1+1+3+3\n", "2\n" ]
none
500
[ { "input": "3+2+1", "output": "1+2+3" }, { "input": "1+1+3+1+3", "output": "1+1+1+3+3" }, { "input": "2", "output": "2" }, { "input": "2+2+1+1+3", "output": "1+1+2+2+3" }, { "input": "2+1+2+2+2+3+1+3+1+2", "output": "1+1+1+2+2+2+2+2+3+3" }, { "input": ...
1,695,699,308
2,147,483,647
PyPy 3
OK
TESTS
21
154
0
# Helpful Maths formula = input() number = list(formula.split('+')) number.sort() print('+'.join(number))
Title: Helpful Maths Time Limit: None seconds Memory Limit: None megabytes Problem Description: Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak...
```python # Helpful Maths formula = input() number = list(formula.split('+')) number.sort() print('+'.join(number)) ```
3
218
B
Airport
PROGRAMMING
1,100
[ "implementation" ]
null
null
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=&gt;<=0) empty seats at the given moment, then the ticket for such a plane ...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th...
Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly.
[ "4 3\n2 1 1\n", "4 3\n2 2 2\n" ]
[ "5 5\n", "7 6\n" ]
In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum. In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd pl...
500
[ { "input": "4 3\n2 1 1", "output": "5 5" }, { "input": "4 3\n2 2 2", "output": "7 6" }, { "input": "10 5\n10 3 3 1 2", "output": "58 26" }, { "input": "10 1\n10", "output": "55 55" }, { "input": "10 1\n100", "output": "955 955" }, { "input": "10 2\n4 7...
1,652,644,632
2,147,483,647
PyPy 3
OK
TESTS
33
248
20,889,600
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: Airport Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen pl...
```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
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,617,473,490
2,147,483,647
PyPy 3
OK
TESTS
30
216
0
a = input() ucount = 0 for i in a: if i.isupper(): ucount += 1 if len(a)-ucount >= ucount: print(a.lower()) else: print(a.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python a = input() ucount = 0 for i in a: if i.isupper(): ucount += 1 if len(a)-ucount >= ucount: print(a.lower()) else: print(a.upper()) ```
3.946
934
A
A Compatible Pair
PROGRAMMING
1,400
[ "brute force", "games" ]
null
null
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big B...
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109.
Print a single integer — the brightness of the chosen pair.
[ "2 2\n20 18\n2 14\n", "5 3\n-1 0 1 2 3\n-1 0 1\n" ]
[ "252\n", "2\n" ]
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
500
[ { "input": "2 2\n20 18\n2 14", "output": "252" }, { "input": "5 3\n-1 0 1 2 3\n-1 0 1", "output": "2" }, { "input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7", "output": "70" }, { "input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 ...
1,527,671,700
2,147,483,647
Python 3
OK
TESTS
87
170
7,065,600
n,m = input().split() n = int(n) m = int(m) a = list(map(int,input().split())) b = list(map(int,input().split())) a.sort() b.sort() ans = 10000000000000000000 for i in range(n): maxi = -10000000000000000000 for j in range(n): if j != i: for k in range(m): pr = a[...
Title: A Compatible Pair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cr...
```python n,m = input().split() n = int(n) m = int(m) a = list(map(int,input().split())) b = list(map(int,input().split())) a.sort() b.sort() ans = 10000000000000000000 for i in range(n): maxi = -10000000000000000000 for j in range(n): if j != i: for k in range(m): ...
3
1,004
A
Sonya and Hotels
PROGRAMMING
900
[ "implementation" ]
null
null
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin...
The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coord...
Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$.
[ "4 3\n-3 2 9 16\n", "5 2\n4 8 11 18 19\n" ]
[ "6\n", "5\n" ]
In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$. In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$.
500
[ { "input": "4 3\n-3 2 9 16", "output": "6" }, { "input": "5 2\n4 8 11 18 19", "output": "5" }, { "input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83", "output": "8" }, { "input": "10 10\n0 20 48 58 81 95 111 137 147 159", "output": "9" }, { "input": "100 1\n0 1 2 3...
1,622,056,135
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
arr=[int(i) for i in input().split()] arr.sort() ans=2 for i in range(1,n): if arr[i]-d==arr[i-1]+d:ans+=1 elif arr[i]-d>arr[i-1]+d:ans+=2 print(ans)
Title: Sonya and Hotels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer c...
```python arr=[int(i) for i in input().split()] arr.sort() ans=2 for i in range(1,n): if arr[i]-d==arr[i-1]+d:ans+=1 elif arr[i]-d>arr[i-1]+d:ans+=2 print(ans) ```
-1
650
A
Watchmen
PROGRAMMING
1,400
[ "data structures", "geometry", "math" ]
null
null
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha...
The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen. Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109). Some positions may coincide.
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
[ "3\n1 1\n7 5\n1 5\n", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n" ]
[ "2\n", "11\n" ]
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs...
500
[ { "input": "3\n1 1\n7 5\n1 5", "output": "2" }, { "input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1", "output": "11" }, { "input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55", "output": "33" }, { "input": "1\n-5 -90", "output": "0" }, { ...
1,672,126,911
2,147,483,647
PyPy 3-64
OK
TESTS
71
607
48,128,000
from collections import defaultdict import sys input=sys.stdin.readline dx,dy,dxy=defaultdict(int),defaultdict(int),defaultdict(int) n=int(input()) for _ in range(n): x,y=map(int,input().split()) dx[x]+=1 dy[y]+=1 dxy[(x,y)]+=1 ans=0 for x in dx: ans+=(dx[x]*(dx[x]-1))//2 for y in dy:...
Title: Watchmen Time Limit: None seconds Memory Limit: None megabytes Problem Description: Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They n...
```python from collections import defaultdict import sys input=sys.stdin.readline dx,dy,dxy=defaultdict(int),defaultdict(int),defaultdict(int) n=int(input()) for _ in range(n): x,y=map(int,input().split()) dx[x]+=1 dy[y]+=1 dxy[(x,y)]+=1 ans=0 for x in dx: ans+=(dx[x]*(dx[x]-1))//2 fo...
3
584
A
Olesya and Rodion
PROGRAMMING
1,000
[ "math" ]
null
null
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-...
The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by.
Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
[ "3 2\n" ]
[ "712" ]
none
500
[ { "input": "3 2", "output": "222" }, { "input": "2 2", "output": "22" }, { "input": "4 3", "output": "3333" }, { "input": "5 3", "output": "33333" }, { "input": "10 7", "output": "7777777777" }, { "input": "2 9", "output": "99" }, { "input"...
1,688,765,366
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
n = 3 t = 8 x=10**(n-1) for i in range (9): if i==8 and (x+1)%t!=0: print(-1) elif x%t!=0: x+=1 else: print(x) break
Title: Olesya and Rodion Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larg...
```python n = 3 t = 8 x=10**(n-1) for i in range (9): if i==8 and (x+1)%t!=0: print(-1) elif x%t!=0: x+=1 else: print(x) break ```
0
401
C
Team
PROGRAMMING
1,400
[ "constructive algorithms", "greedy", "implementation" ]
null
null
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing ...
The first line contains two integers: *n* (1<=≤<=*n*<=≤<=106) — the number of cards containing number 0; *m* (1<=≤<=*m*<=≤<=106) — the number of cards containing number 1.
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
[ "1 2\n", "4 8\n", "4 10\n", "1 5\n" ]
[ "101\n", "110110110101\n", "11011011011011\n", "-1\n" ]
none
1,500
[ { "input": "1 2", "output": "101" }, { "input": "4 8", "output": "110110110101" }, { "input": "4 10", "output": "11011011011011" }, { "input": "1 5", "output": "-1" }, { "input": "3 4", "output": "1010101" }, { "input": "3 10", "output": "-1" }, ...
1,593,838,400
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
109
0
n, m = map(int, input().split()) if (m > 2 * (n + 1)) or (n > m + 1): print(-1) elif n >= m: print(str(i%2) for i in range(n + m)) elif m == 2 * (n + 1): print('110' * n + '11') else: print('110' * (m - n) + '10' * (2 * n - m))
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each t...
```python n, m = map(int, input().split()) if (m > 2 * (n + 1)) or (n > m + 1): print(-1) elif n >= m: print(str(i%2) for i in range(n + m)) elif m == 2 * (n + 1): print('110' * n + '11') else: print('110' * (m - n) + '10' * (2 * n - m)) ```
0
763
A
Timofey and a tree
PROGRAMMING
1,600
[ "dfs and similar", "dp", "dsu", "graphs", "implementation", "trees" ]
null
null
Each New Year Timofey and his friends cut down a tree of *n* vertices and bring it home. After that they paint all the *n* its vertices, so that the *i*-th vertex gets color *c**i*. Now it's time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes ...
The first line contains single integer *n* (2<=≤<=*n*<=≤<=105) — the number of vertices in the tree. Each of the next *n*<=-<=1 lines contains two integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*), denoting there is an edge between vertices *u* and *v*. It is guaranteed that the given graph is a tree. The n...
Print "NO" in a single line, if Timofey can't take the tree in such a way that it doesn't annoy him. Otherwise print "YES" in the first line. In the second line print the index of the vertex which Timofey should take in hands. If there are multiple answers, print any of them.
[ "4\n1 2\n2 3\n3 4\n1 2 1 1\n", "3\n1 2\n2 3\n1 2 3\n", "4\n1 2\n2 3\n3 4\n1 2 1 2\n" ]
[ "YES\n2", "YES\n2", "NO" ]
none
500
[ { "input": "4\n1 2\n2 3\n3 4\n1 2 1 1", "output": "YES\n2" }, { "input": "3\n1 2\n2 3\n1 2 3", "output": "YES\n2" }, { "input": "4\n1 2\n2 3\n3 4\n1 2 1 2", "output": "NO" }, { "input": "3\n2 1\n2 3\n1 2 3", "output": "YES\n2" }, { "input": "4\n1 2\n2 4\n4 3\n1 1 ...
1,583,368,286
2,147,483,647
PyPy 3
OK
TESTS
67
951
14,950,400
n = int(input()) u = [] v = [] for i in range(n-1): a, b = map(int, input().split()) u.append(a) v.append(b) c = [0] + [int(x) for x in input().split()] e = 0 dic = {} for i in range(1, n+1): dic[i] = 0 def plus(dic, n): if n in dic: dic[n] += 1 else: ...
Title: Timofey and a tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: Each New Year Timofey and his friends cut down a tree of *n* vertices and bring it home. After that they paint all the *n* its vertices, so that the *i*-th vertex gets color *c**i*. Now it's time for Timofey birthda...
```python n = int(input()) u = [] v = [] for i in range(n-1): a, b = map(int, input().split()) u.append(a) v.append(b) c = [0] + [int(x) for x in input().split()] e = 0 dic = {} for i in range(1, n+1): dic[i] = 0 def plus(dic, n): if n in dic: dic[n] += 1 else:...
3
106
B
Choosing Laptop
PROGRAMMING
1,000
[ "brute force", "implementation" ]
B. Choosing Laptop
2
256
Vasya is choosing a laptop. The shop has *n* laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those propertie...
The first line contains number *n* (1<=≤<=*n*<=≤<=100). Then follow *n* lines. Each describes a laptop as *speed* *ram* *hdd* *cost*. Besides, - *speed*, *ram*, *hdd* and *cost* are integers - 1000<=≤<=*speed*<=≤<=4200 is the processor's speed in megahertz - 256<=≤<=*ram*<=≤<=4096 the RAM volume in megabytes - 1...
Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to *n* in the order in which they are given in the input data.
[ "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150\n" ]
[ "4" ]
In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
1,000
[ { "input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150", "output": "4" }, { "input": "2\n1500 500 50 755\n1600 600 80 700", "output": "2" }, { "input": "2\n1500 512 50 567\n1600 400 70 789", "output": "1" }, { "input": "4\n10...
1,594,743,660
2,147,483,647
Python 3
OK
TESTS
55
218
6,963,200
l=[];c=[] n=int(input()) for _ in range(n): t=list(map(int,input().split())) l.append(t) c.append(t[3]) s = [] for i in range(n): f=0 for j in range(n): if i==j: continue if l[i][0]<l[j][0] and l[i][1]<l[j][1] and l[i][2]<l[j][2]: f=1 break s.append(f) m = float('inf') for i in r...
Title: Choosing Laptop Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is choosing a laptop. The shop has *n* laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in ...
```python l=[];c=[] n=int(input()) for _ in range(n): t=list(map(int,input().split())) l.append(t) c.append(t[3]) s = [] for i in range(n): f=0 for j in range(n): if i==j: continue if l[i][0]<l[j][0] and l[i][1]<l[j][1] and l[i][2]<l[j][2]: f=1 break s.append(f) m = float('inf') ...
3.93253
508
B
Anton and currency you all know
PROGRAMMING
1,300
[ "greedy", "math", "strings" ]
null
null
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer. Reliable sources have informed the financier Anton of some information about the exchange rate of...
The first line contains an odd positive integer *n* — the exchange rate of currency you all know for today. The length of number *n*'s representation is within range from 2 to 105, inclusive. The representation of *n* doesn't contain any leading zeroes.
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print <=-<=1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained fro...
[ "527\n", "4573\n", "1357997531\n" ]
[ "572\n", "3574\n", "-1\n" ]
none
1,000
[ { "input": "527", "output": "572" }, { "input": "4573", "output": "3574" }, { "input": "1357997531", "output": "-1" }, { "input": "444443", "output": "444434" }, { "input": "22227", "output": "72222" }, { "input": "24683", "output": "34682" }, ...
1,662,918,934
2,147,483,647
PyPy 3-64
OK
TESTS
58
77
4,812,800
import math import copy import itertools import bisect import sys input = sys.stdin.readline def ilst(): return list(map(int,input().split())) def islst(): return list(map(str,input().split())) def inum(): return map(int,input().split()) n, pos = input()[:-1], -1 for ...
Title: Anton and currency you all know Time Limit: None seconds Memory Limit: None megabytes Problem Description: Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed...
```python import math import copy import itertools import bisect import sys input = sys.stdin.readline def ilst(): return list(map(int,input().split())) def islst(): return list(map(str,input().split())) def inum(): return map(int,input().split()) n, pos = input()[:-1], -...
3
799
A
Carrot Cakes
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady...
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
[ "8 6 4 5\n", "8 6 4 6\n", "10 3 11 4\n", "4 2 1 4\n" ]
[ "YES\n", "NO\n", "NO\n", "YES\n" ]
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whe...
500
[ { "input": "8 6 4 5", "output": "YES" }, { "input": "8 6 4 6", "output": "NO" }, { "input": "10 3 11 4", "output": "NO" }, { "input": "4 2 1 4", "output": "YES" }, { "input": "28 17 16 26", "output": "NO" }, { "input": "60 69 9 438", "output": "NO"...
1,681,301,120
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
n, t, k, d = float(input()), float(input()), float(input()), float(input()) onecaketime = t/k totaltime = onecaketime*(n-1) if totaltime>d: print("YES") else: print("N0")
Title: Carrot Cakes Time Limit: None seconds Memory Limit: None megabytes Problem Description: In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu...
```python n, t, k, d = float(input()), float(input()), float(input()), float(input()) onecaketime = t/k totaltime = onecaketime*(n-1) if totaltime>d: print("YES") else: print("N0") ```
-1
535
B
Tavas and SaDDas
PROGRAMMING
1,100
[ "bitmasks", "brute force", "combinatorics", "implementation" ]
null
null
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You ar...
The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109).
Print the index of *n* among all lucky numbers.
[ "4\n", "7\n", "77\n" ]
[ "1\n", "2\n", "6\n" ]
none
1,000
[ { "input": "4", "output": "1" }, { "input": "7", "output": "2" }, { "input": "77", "output": "6" }, { "input": "4", "output": "1" }, { "input": "474744", "output": "83" }, { "input": "777774", "output": "125" }, { "input": "447", "outpu...
1,668,234,290
2,147,483,647
Python 3
OK
TESTS
33
46
0
number = input() aux = (1 << len(number)) - 2 position = 0 i = len(number) - 1 while i >= 0: if number[i] == '7': aux += (1 << position) i -= 1 position += 1 print(aux + 1)
Title: Tavas and SaDDas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone...
```python number = input() aux = (1 << len(number)) - 2 position = 0 i = len(number) - 1 while i >= 0: if number[i] == '7': aux += (1 << position) i -= 1 position += 1 print(aux + 1) ```
3
348
A
Mafia
PROGRAMMING
1,600
[ "binary search", "math", "sortings" ]
null
null
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the min...
The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play.
In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3\n3 2 2\n", "4\n2 2 2 2\n" ]
[ "4\n", "3\n" ]
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
500
[ { "input": "3\n3 2 2", "output": "4" }, { "input": "4\n2 2 2 2", "output": "3" }, { "input": "7\n9 7 7 8 8 7 8", "output": "9" }, { "input": "10\n13 12 10 13 13 14 10 10 12 12", "output": "14" }, { "input": "10\n94 96 91 95 99 94 96 92 95 99", "output": "106" ...
1,380,773,602
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
124
0
n = eval(input()) a = eval(input().replace(" ",",")+',') print(round(sum(a) / (n-1)))
Title: Mafia Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a...
```python n = eval(input()) a = eval(input().replace(" ",",")+',') print(round(sum(a) / (n-1))) ```
0
202
A
LLPS
PROGRAMMING
800
[ "binary search", "bitmasks", "brute force", "greedy", "implementation", "strings" ]
null
null
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*...
The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10.
Print the lexicographically largest palindromic subsequence of string *s*.
[ "radar\n", "bowwowwow\n", "codeforces\n", "mississipp\n" ]
[ "rr\n", "wwwww\n", "s\n", "ssss\n" ]
Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".
500
[ { "input": "radar", "output": "rr" }, { "input": "bowwowwow", "output": "wwwww" }, { "input": "codeforces", "output": "s" }, { "input": "mississipp", "output": "ssss" }, { "input": "tourist", "output": "u" }, { "input": "romka", "output": "r" }, ...
1,583,774,936
2,147,483,647
Python 3
OK
TESTS
54
248
409,600
from collections import Counter c = Counter(input()) a = sorted(c,key = lambda x:x[0],reverse=True)[0] print(a * (c[a]))
Title: LLPS Time Limit: None seconds Memory Limit: None megabytes Problem Description: This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ...
```python from collections import Counter c = Counter(input()) a = sorted(c,key = lambda x:x[0],reverse=True)[0] print(a * (c[a])) ```
3
994
B
Knights of a Polygonal Table
PROGRAMMING
1,400
[ "greedy", "implementation", "sortings" ]
null
null
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo...
The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement. The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct. The third line contains $n...
Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights.
[ "4 2\n4 5 9 7\n1 2 11 33\n", "5 1\n1 2 3 4 5\n1 2 3 4 5\n", "1 0\n2\n3\n" ]
[ "1 3 46 36 ", "1 3 5 7 9 ", "3 " ]
Consider the first example. - The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is o...
1,000
[ { "input": "4 2\n4 5 9 7\n1 2 11 33", "output": "1 3 46 36 " }, { "input": "5 1\n1 2 3 4 5\n1 2 3 4 5", "output": "1 3 5 7 9 " }, { "input": "1 0\n2\n3", "output": "3 " }, { "input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9", "output": "0 3 10 16 14 17 18 " }, { "input"...
1,529,236,248
2,147,483,647
Python 3
OK
TESTS
73
358
16,179,200
from heapq import heappush, heappushpop n, k = map(int, input().split()) pp = list(map(int, input().split())) id = sorted(range(n), key=pp.__getitem__) cc = list(map(int, input().split())) rr, hh, s, t = cc[:], [], 0, 0 for i in id: p = pp[i] while pp[id[t]] < p: c = cc[id[t]] if len(hh) < k: ...
Title: Knights of a Polygonal Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power ...
```python from heapq import heappush, heappushpop n, k = map(int, input().split()) pp = list(map(int, input().split())) id = sorted(range(n), key=pp.__getitem__) cc = list(map(int, input().split())) rr, hh, s, t = cc[:], [], 0, 0 for i in id: p = pp[i] while pp[id[t]] < p: c = cc[id[t]] if len(...
3
252
B
Unsorting Array
PROGRAMMING
1,800
[ "brute force", "sortings" ]
null
null
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of *n* elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct ...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* non-negative space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to *n*.
[ "1\n1\n", "2\n1 2\n", "4\n1 2 3 4\n", "3\n1 1 1\n" ]
[ "-1\n", "-1\n", "1 2\n", "-1\n" ]
In the first two samples the required pairs obviously don't exist. In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
1,000
[ { "input": "1\n1", "output": "-1" }, { "input": "2\n1 2", "output": "-1" }, { "input": "4\n1 2 3 4", "output": "1 2" }, { "input": "3\n1 1 1", "output": "-1" }, { "input": "3\n1 2 2", "output": "1 2" }, { "input": "5\n1 1 1 1 2", "output": "2 5" ...
1,686,568,527
2,147,483,647
Python 3
OK
TESTS
58
186
12,902,400
n=int(input()) a=list(map(int,input().split())) b,c=sorted(a),sorted(a,reverse=True) for i in range(n-1): if a[i]!=a[i+1]: a[i],a[i+1]=a[i+1],a[i] if a==b or a==c: a[i],a[i+1]=a[i+1],a[i] else: print(i+1,i+2) exit() print(-1)
Title: Unsorting Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of *n* elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the...
```python n=int(input()) a=list(map(int,input().split())) b,c=sorted(a),sorted(a,reverse=True) for i in range(n-1): if a[i]!=a[i+1]: a[i],a[i+1]=a[i+1],a[i] if a==b or a==c: a[i],a[i+1]=a[i+1],a[i] else: print(i+1,i+2) exit() print(-1) ```
3
408
A
Line to Cashier
PROGRAMMING
900
[ "implementation" ]
null
null
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier. The *i*-th of the next *n* lines contains *k**i*...
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
[ "1\n1\n1\n", "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n" ]
[ "20\n", "100\n" ]
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou...
500
[ { "input": "1\n1\n1", "output": "20" }, { "input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100" }, { "input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3", "output": "100" }, { "input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3"...
1,578,775,996
2,147,483,647
PyPy 3
OK
TESTS
20
156
1,536,000
# Link: http://codeforces.com/problemset/problem/408/A # Love you Atreyee my life. I cannot live without you. n = int(input()) #no of cashier k = list(map(int, input().rstrip().split())) #Number of people in queue mat = [] for i in range(n): a = list(map(int, input().rstrip().split())) mat += [sum(a) * 5 + k...
Title: Line to Cashier Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* c...
```python # Link: http://codeforces.com/problemset/problem/408/A # Love you Atreyee my life. I cannot live without you. n = int(input()) #no of cashier k = list(map(int, input().rstrip().split())) #Number of people in queue mat = [] for i in range(n): a = list(map(int, input().rstrip().split())) mat += [sum(...
3
368
B
Sereja and Suffixes
PROGRAMMING
1,100
[ "data structures", "dp" ]
null
null
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
[ "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" ]
[ "6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n" ]
none
1,000
[ { "input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1" }, { "input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2", "output": "3\n4\n5" }, { "input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4", "output": "3\n5\n2\n4\n3\n3\...
1,681,690,690
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
109
0
n,m = map(int,input().split()) a = list(map(lambda q:int(q), input().split(" "))) r = len(set(a)) t=[] q=[] for i in range(n): t.append(r) if a[i] in q: r-=1 q.append(a[i]) t[n-1]=1 print(t) for i in range(m): l=int(input()) print(t[l-1])
Title: Sereja and Suffixes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=......
```python n,m = map(int,input().split()) a = list(map(lambda q:int(q), input().split(" "))) r = len(set(a)) t=[] q=[] for i in range(n): t.append(r) if a[i] in q: r-=1 q.append(a[i]) t[n-1]=1 print(t) for i in range(m): l=int(input()) print(t[l-1]) ```
0
610
A
Pasha and Stick
PROGRAMMING
1,000
[ "combinatorics", "math" ]
null
null
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to ...
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick.
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
[ "6\n", "20\n" ]
[ "1\n", "4\n" ]
There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
500
[ { "input": "6", "output": "1" }, { "input": "20", "output": "4" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "2000000000", "output": "4...
1,539,295,524
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
109
409,600
def NumCuts(n): if n == 1: return(1) elif n == 3: return(1) return(NumCuts(n // 2) + 1) n = int(input()) print(NumCuts(n / 2))
Title: Pasha and Stick Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obv...
```python def NumCuts(n): if n == 1: return(1) elif n == 3: return(1) return(NumCuts(n // 2) + 1) n = int(input()) print(NumCuts(n / 2)) ```
-1
16
B
Burglar and Matches
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
B. Burglar and Matches
0
64
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactl...
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer.
Output the only number — answer to the problem.
[ "7 3\n5 10\n2 5\n3 6\n", "3 3\n1 3\n2 2\n3 1\n" ]
[ "62\n", "7\n" ]
none
0
[ { "input": "7 3\n5 10\n2 5\n3 6", "output": "62" }, { "input": "3 3\n1 3\n2 2\n3 1", "output": "7" }, { "input": "1 1\n1 2", "output": "2" }, { "input": "1 2\n1 9\n1 6", "output": "9" }, { "input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1", "ou...
1,593,101,249
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
8
248
6,963,200
# import sys # sys.stdin = open("test.in","r") # sys.stdout = open("test.out.py","w") n,m=map(int,input().split()) l=[] for i in range(m): x,y=map(int,input().split()) l.append((x,y)) l.sort(key=lambda x:x[1],reverse=True) a=0 b=0 i=0 while(n>0): if l[i][0]>=n: b=n else: b=l[i][0] a+=b*l[i][1]...
Title: Burglar and Matches Time Limit: 0 seconds Memory Limit: 64 megabytes Problem Description: A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* mat...
```python # import sys # sys.stdin = open("test.in","r") # sys.stdout = open("test.out.py","w") n,m=map(int,input().split()) l=[] for i in range(m): x,y=map(int,input().split()) l.append((x,y)) l.sort(key=lambda x:x[1],reverse=True) a=0 b=0 i=0 while(n>0): if l[i][0]>=n: b=n else: b=l[i][0] a+...
-1
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th...
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 ...
1,695,242,241
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
30
0
n=int(input()) lst=list(map(int,input().split())) a,b=0,0 while len(lst)!=0: if len(lst)>1: a+=lst.pop(lst.index(max(lst[0],lst[-1]))) else: a += lst.pop(0) if len(lst) > 1: b+=lst.pop(lst.index(max(lst[0],lst[-1]))) else: b += lst.pop(0) print(a,b) ...
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du...
```python n=int(input()) lst=list(map(int,input().split())) a,b=0,0 while len(lst)!=0: if len(lst)>1: a+=lst.pop(lst.index(max(lst[0],lst[-1]))) else: a += lst.pop(0) if len(lst) > 1: b+=lst.pop(lst.index(max(lst[0],lst[-1]))) else: b += lst.pop(0) print(a,b...
-1
233
A
Perfect Permutation
PROGRAMMING
800
[ "implementation", "math" ]
null
null
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He lik...
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
[ "1\n", "2\n", "4\n" ]
[ "-1\n", "2 1 \n", "2 1 4 3 \n" ]
none
500
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "2 1 " }, { "input": "4", "output": "2 1 4 3 " }, { "input": "3", "output": "-1" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "2 1 4 3 6 5 " }, { "input": "7", ...
1,671,722,564
2,147,483,647
PyPy 3-64
OK
TESTS
30
124
0
n=int(input()) if n%2==1: print(-1) else: l=[x for x in range (1,n+1)] for i in range (0,n-1,2): # print(i) l[i],l[i+1]=l[i+1],l[i] print(*l)
Title: Perfect Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ...
```python n=int(input()) if n%2==1: print(-1) else: l=[x for x in range (1,n+1)] for i in range (0,n-1,2): # print(i) l[i],l[i+1]=l[i+1],l[i] print(*l) ```
3
285
C
Building Permutation
PROGRAMMING
1,200
[ "greedy", "implementation", "sortings" ]
null
null
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. You ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the size of the sought permutation. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Print a single number — the minimum number of moves. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "2\n3 0\n", "3\n-1 -1 2\n" ]
[ "2\n", "6\n" ]
In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1). In the second sample you need 6 moves to build permutation (1, 3, 2).
1,500
[ { "input": "2\n3 0", "output": "2" }, { "input": "3\n-1 -1 2", "output": "6" }, { "input": "5\n-3 5 -3 3 3", "output": "10" }, { "input": "10\n9 6 -2 4 1 1 1 9 6 2", "output": "18" }, { "input": "9\n2 0 0 6 5 4 1 9 3", "output": "15" }, { "input": "100...
1,614,177,330
2,147,483,647
PyPy 3
OK
TESTS
33
436
23,449,600
import sys try: sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') except: pass input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) a.sort() start = 1 ans = 0 for el in a: ans += abs(el-start) start += 1 print(ans)
Title: Building Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *...
```python import sys try: sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') except: pass input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) a.sort() start = 1 ans = 0 for el in a: ans += abs(el-start) start += 1 print(ans) ...
3
899
A
Splitting in Teams
PROGRAMMING
800
[ "constructive algorithms", "greedy", "math" ]
null
null
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of tea...
The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*.
Print the maximum number of teams of three people the coach can form.
[ "4\n1 1 2 1\n", "2\n2 2\n", "7\n2 2 2 1 1 1 1\n", "3\n1 1 1\n" ]
[ "1\n", "0\n", "3\n", "1\n" ]
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) an...
500
[ { "input": "4\n1 1 2 1", "output": "1" }, { "input": "2\n2 2", "output": "0" }, { "input": "7\n2 2 2 1 1 1 1", "output": "3" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "3\n2 2 2", "output": "0" }, { "input": "3\n1 2 1", "output": "1" }...
1,515,348,208
2,147,483,647
Python 3
OK
TESTS
67
124
9,420,800
n = int(input()) a = [int(x) for x in input().split()] _1 = a.count(1) _2 = a.count(2) d = min(_2, _1) _1 -= d print(d+_1//3)
Title: Splitting in Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The co...
```python n = int(input()) a = [int(x) for x in input().split()] _1 = a.count(1) _2 = a.count(2) d = min(_2, _1) _1 -= d print(d+_1//3) ```
3
581
A
Vasya the Hipster
PROGRAMMING
800
[ "implementation", "math" ]
null
null
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning ...
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he'...
[ "3 1\n", "2 3\n", "7 3\n" ]
[ "1 1\n", "2 0\n", "3 2\n" ]
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
500
[ { "input": "3 1", "output": "1 1" }, { "input": "2 3", "output": "2 0" }, { "input": "7 3", "output": "3 2" }, { "input": "100 100", "output": "100 0" }, { "input": "4 10", "output": "4 3" }, { "input": "6 10", "output": "6 2" }, { "input":...
1,693,590,928
2,147,483,647
PyPy 3-64
OK
TESTS
30
62
0
a,b = map(int, list(input().split(' '))) print(min(a,b), ' ',(max(a,b)-min(a,b))//2)
Title: Vasya the Hipster Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red...
```python a,b = map(int, list(input().split(' '))) print(min(a,b), ' ',(max(a,b)-min(a,b))//2) ```
3
53
C
Little Frog
PROGRAMMING
1,200
[ "constructive algorithms" ]
C. Little Frog
2
256
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For tha...
The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds.
Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan. - All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1). If there are several solutions, output any.
[ "2\n", "3\n" ]
[ "1 2 ", "1 3 2 " ]
none
1,500
[ { "input": "2", "output": "1 2 " }, { "input": "3", "output": "1 3 2 " }, { "input": "4", "output": "1 4 2 3 " }, { "input": "5", "output": "1 5 2 4 3 " }, { "input": "6", "output": "1 6 2 5 3 4 " }, { "input": "1", "output": "1 " }, { "inp...
1,545,492,307
2,147,483,647
Python 3
OK
TESTS
22
248
512,000
n=int(input()) lo=1 hi=n cnt=0 ans=[] while lo<=hi: if cnt%2==0: ans.append(lo) lo+=1 else: ans.append(hi) hi-=1 cnt+=1 print(*ans)
Title: Little Frog Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants ...
```python n=int(input()) lo=1 hi=n cnt=0 ans=[] while lo<=hi: if cnt%2==0: ans.append(lo) lo+=1 else: ans.append(hi) hi-=1 cnt+=1 print(*ans) ```
3.937046
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,669,411,298
2,147,483,647
PyPy 3-64
OK
TESTS
13
93
2,252,800
import re n = input() string = input() ans = 0 for i in re.findall(r'x{3,}', string): ans += len(i) - 2 print(ans)
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 import re n = input() string = input() ans = 0 for i in re.findall(r'x{3,}', string): ans += len(i) - 2 print(ans) ```
3
3
A
Shortest path of the king
PROGRAMMING
1,000
[ "greedy", "shortest paths" ]
A. Shortest path of the king
1
64
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the le...
The first line contains the chessboard coordinates of square *s*, the second line — of square *t*. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diago...
[ "a8\nh1\n" ]
[ "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n" ]
none
0
[ { "input": "a8\nh1", "output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD" }, { "input": "b2\nb4", "output": "2\nU\nU" }, { "input": "a5\na5", "output": "0" }, { "input": "h1\nb2", "output": "6\nLU\nL\nL\nL\nL\nL" }, { "input": "c5\nh2", "output": "5\nRD\nRD\nRD\nR\nR" ...
1,604,120,918
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
186
307,200
S1 = str(input()) S2 = str(input()) if S1[0] == 'a': S1 += "1" if S1[0] == 'b': S1 += "2" if S1[0] == 'c': S1 += "3" if S1[0] == 'd': S1 += "4" if S1[0] == 'e': S1 += "5" if S1[0] == 'f': S1 += "6" if S1[0] == 'g': S1 += "7" if S1[0] == 'h': S1 += "8" if S2[0] == 'a': ...
Title: Shortest path of the king Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king ...
```python S1 = str(input()) S2 = str(input()) if S1[0] == 'a': S1 += "1" if S1[0] == 'b': S1 += "2" if S1[0] == 'c': S1 += "3" if S1[0] == 'd': S1 += "4" if S1[0] == 'e': S1 += "5" if S1[0] == 'f': S1 += "6" if S1[0] == 'g': S1 += "7" if S1[0] == 'h': S1 += "8" if S2[0]...
0
448
B
Suffix Structures
PROGRAMMING
1,400
[ "implementation", "strings" ]
null
null
Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team. At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*. You need to transform word *s* into word *t*". The task looked simple to the guys because they know th...
The first line contains a non-empty word *s*. The second line contains a non-empty word *t*. Words *s* and *t* are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.
In the single line print the answer to the problem. Print "need tree" (without the quotes) if word *s* cannot be transformed into word *t* even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without th...
[ "automaton\ntomat\n", "array\narary\n", "both\nhot\n", "need\ntree\n" ]
[ "automaton\n", "array\n", "both\n", "need tree\n" ]
In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot".
1,000
[ { "input": "automaton\ntomat", "output": "automaton" }, { "input": "array\narary", "output": "array" }, { "input": "both\nhot", "output": "both" }, { "input": "need\ntree", "output": "need tree" }, { "input": "abacaba\naaaa", "output": "automaton" }, { ...
1,696,400,797
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
62
0
def solve(s,t): sa,ta=s.copy(),t.copy() sa.sort(),ta.sort() if sa==ta: return "array" if sa!=ta and len(sa)==len(ta): return "need tree" for e in t: if sa.count(e)>0:sa.remove(e) else: return "need tree" s,t="".join(s),"".join(t) if s.find(t)<0: return "both" re...
Title: Suffix Structures Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team. At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*....
```python def solve(s,t): sa,ta=s.copy(),t.copy() sa.sort(),ta.sort() if sa==ta: return "array" if sa!=ta and len(sa)==len(ta): return "need tree" for e in t: if sa.count(e)>0:sa.remove(e) else: return "need tree" s,t="".join(s),"".join(t) if s.find(t)<0: return "bot...
0
807
B
T-Shirt Hunt
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt. Unfortunately, you didn't manage to get into top 25, but you got into top 500, taking place *p*. Now the elimination r...
The only line contains three integers *p*, *x* and *y* (26<=≤<=*p*<=≤<=500; 1<=≤<=*y*<=≤<=*x*<=≤<=20000) — your place in Codecraft-17, your current score in the elimination round of 8VC Venture Cup 2017, and the smallest number of points you consider sufficient for winning the current round.
Output a single integer — the smallest number of successful hacks you have to do in order to both win the elimination round of 8VC Venture Cup 2017 and ensure getting a Codecraft-17 T-shirt. It's guaranteed that your goal is achievable for any valid input data.
[ "239 10880 9889\n", "26 7258 6123\n", "493 8000 8000\n", "101 6800 6500\n", "329 19913 19900\n" ]
[ "0\n", "2\n", "24\n", "0\n", "8\n" ]
In the first example, there is no need to do any hacks since 10880 points already bring the T-shirt to the 239-th place of Codecraft-17 (that is, you). In this case, according to the pseudocode, the T-shirts will be given to the participants at the following places: In the second example, you have to do two successfu...
1,000
[ { "input": "239 10880 9889", "output": "0" }, { "input": "26 7258 6123", "output": "2" }, { "input": "493 8000 8000", "output": "24" }, { "input": "101 6800 6500", "output": "0" }, { "input": "329 19913 19900", "output": "8" }, { "input": "264 19252 10...
1,494,185,327
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
#!/bin/python3 import math n = int(input()) for rd in range(n): my , tot , p , q = list(map(int , input().split())) m = 0 if(tot % q == 0): m = tot // q else: m = (tot // q + 1) np = m * p ; nq = m * q for i in range(500000): if(np - my <= nq - tot and np - my >= 0): ...
Title: T-Shirt Hunt Time Limit: None seconds Memory Limit: None megabytes Problem Description: Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt. Unfortunately, you di...
```python #!/bin/python3 import math n = int(input()) for rd in range(n): my , tot , p , q = list(map(int , input().split())) m = 0 if(tot % q == 0): m = tot // q else: m = (tot // q + 1) np = m * p ; nq = m * q for i in range(500000): if(np - my <= nq - tot and np - my...
-1
758
A
Holiday Of Equality
PROGRAMMING
800
[ "implementation", "math" ]
null
null
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl...
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen.
In the only line print the integer *S* — the minimum number of burles which are had to spend.
[ "5\n0 1 2 3 4\n", "5\n1 1 0 1 1\n", "3\n1 3 1\n", "1\n12\n" ]
[ "10", "1", "4", "0" ]
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the thi...
500
[ { "input": "5\n0 1 2 3 4", "output": "10" }, { "input": "5\n1 1 0 1 1", "output": "1" }, { "input": "3\n1 3 1", "output": "4" }, { "input": "1\n12", "output": "0" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "14\n52518 718438 358883 462189 853...
1,686,806,681
2,147,483,647
PyPy 3-64
OK
TESTS
41
62
0
def solve(): n = int(input()) welfare = list(map(int, input().split(maxsplit=n))) max_bienestar = max(welfare) return sum( map( lambda c: max_bienestar - c, welfare ) ) print(solve())
Title: Holiday Of Equality Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens...
```python def solve(): n = int(input()) welfare = list(map(int, input().split(maxsplit=n))) max_bienestar = max(welfare) return sum( map( lambda c: max_bienestar - c, welfare ) ) print(solve()) ```
3
254
A
Cards with Numbers
PROGRAMMING
1,200
[ "constructive algorithms", "sortings" ]
null
null
Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split t...
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces.
If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line — the indices of the cards that form the pairs. Separate the numbers on the lines by spaces. You...
[ "3\n20 30 10 30 20 10\n", "1\n1 2\n" ]
[ "4 2\n1 5\n6 3\n", "-1" ]
none
500
[ { "input": "3\n20 30 10 30 20 10", "output": "4 2\n1 5\n6 3" }, { "input": "1\n1 2", "output": "-1" }, { "input": "5\n2 2 2 2 2 1 2 2 1 2", "output": "2 1\n3 4\n7 5\n6 9\n10 8" }, { "input": "5\n2 1 2 2 1 1 1 1 1 2", "output": "3 1\n2 5\n7 6\n8 9\n10 4" }, { "inpu...
1,675,524,873
2,147,483,647
Python 3
OK
TESTS
35
732
43,008,000
# LUOGU_RID: 101473279 import sys sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') n, *a = map(int, sys.stdin.read().split()) d, ans = {}, [] for i in range(n * 2): if a[i] not in d: d[a[i]] = i + 1 else: ans += str(d[a[i]]) + ' ' + str(i+1), del(d[a[i]])...
Title: Cards with Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card wit...
```python # LUOGU_RID: 101473279 import sys sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') n, *a = map(int, sys.stdin.read().split()) d, ans = {}, [] for i in range(n * 2): if a[i] not in d: d[a[i]] = i + 1 else: ans += str(d[a[i]]) + ' ' + str(i+1), de...
3
579
A
Raising Bacteria
PROGRAMMING
1,000
[ "bitmasks" ]
null
null
You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment. What is the mini...
The only line containing one integer *x* (1<=≤<=*x*<=≤<=109).
The only line containing one integer: the answer.
[ "5\n", "8\n" ]
[ "2\n", "1\n" ]
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th ...
250
[ { "input": "5", "output": "2" }, { "input": "8", "output": "1" }, { "input": "536870911", "output": "29" }, { "input": "1", "output": "1" }, { "input": "343000816", "output": "14" }, { "input": "559980448", "output": "12" }, { "input": "697...
1,673,639,697
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
n = int(input()) c = 1 while c<n: if c<n: c*=2 print(1+n-c)
Title: Raising Bacteria Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split...
```python n = int(input()) c = 1 while c<n: if c<n: c*=2 print(1+n-c) ```
0
672
B
Different is Good
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "strings" ]
null
null
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*. The second line contains the string *s* of length *n* consisting of only lowercase English letters.
If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
[ "2\naa\n", "4\nkoko\n", "5\nmurat\n" ]
[ "1\n", "2\n", "0\n" ]
In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
1,000
[ { "input": "2\naa", "output": "1" }, { "input": "4\nkoko", "output": "2" }, { "input": "5\nmurat", "output": "0" }, { "input": "6\nacbead", "output": "1" }, { "input": "7\ncdaadad", "output": "4" }, { "input": "25\npeoaicnbisdocqofsqdpgobpn", "outp...
1,593,321,043
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
108
6,963,200
n=int(input()) s=input() z=set(s) if(len(z)>26): print('-1') else: print(n-len(z))
Title: Different is Good Time Limit: None seconds Memory Limit: None megabytes Problem Description: A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are di...
```python n=int(input()) s=input() z=set(s) if(len(z)>26): print('-1') else: print(n-len(z)) ```
0
7
E
Defining Macros
PROGRAMMING
2,600
[ "dp", "expression parsing", "implementation" ]
E. Defining Macros
3
256
Most C/C++ programmers know about excellent opportunities that preprocessor #define directives give; but many know as well about the problems that can arise because of their careless use. In this problem we consider the following model of #define constructions (also called macros). Each macro has its name and value. T...
The first line contains the only number *n* (0<=≤<=*n*<=≤<=100) — the amount of #define constructions in the given program. Then there follow *n* lines, each of them contains just one #define construction. Each construction has the following syntax: #define name expression where - name — the macro name, - express...
Output "OK", if the expression is correct according to the above given criterion, otherwise output "Suspicious".
[ "1\n#define sum x + y\n1 * sum\n", "1\n#define sum (x + y)\nsum - sum\n", "4\n#define sum x + y\n#define mul a * b\n#define div a / b\n#define expr sum + mul * div * mul\nexpr\n", "3\n#define SumSafe (a+b)\n#define DivUnsafe a/b\n#define DenominatorUnsafe a*b\n((SumSafe) + DivUnsafe/DivUnsafe + x/Deno...
[ "Suspicious\n", "OK\n", "OK\n", "Suspicious\n" ]
none
0
[ { "input": "1\n#define sum x + y\n1 * sum", "output": "Suspicious" }, { "input": "1\n#define sum (x + y)\nsum - sum", "output": "OK" }, { "input": "4\n#define sum x + y\n#define mul a * b\n#define div a / b\n#define expr sum + mul * div * mul\nexpr", "output": "OK" }, { "...
1,588,095,703
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
21
280
1,228,800
# 1:correct, 2:incorrect, 3:(a+b), no - at front, no * or / neighbor, 4:(a*b),(a/b) no / at front def helper(s, d): if s[0] == '(' and s[-1] == ')': if helper(s[1:-1], d) == 2: return 2 else: return 1 if s in d: return d[s] cnt = 0 for idx, c in reversed(...
Title: Defining Macros Time Limit: 3 seconds Memory Limit: 256 megabytes Problem Description: Most C/C++ programmers know about excellent opportunities that preprocessor #define directives give; but many know as well about the problems that can arise because of their careless use. In this problem we consider the fo...
```python # 1:correct, 2:incorrect, 3:(a+b), no - at front, no * or / neighbor, 4:(a*b),(a/b) no / at front def helper(s, d): if s[0] == '(' and s[-1] == ')': if helper(s[1:-1], d) == 2: return 2 else: return 1 if s in d: return d[s] cnt = 0 for idx, c in...
0
849
B
Tell Your World
PROGRAMMING
1,600
[ "brute force", "geometry" ]
null
null
Connect the countless points with lines, till we reach the faraway yonder. There are *n* points on a coordinate plane, the *i*-th of which being (*i*,<=*y**i*). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of the...
The first line of input contains a positive integer *n* (3<=≤<=*n*<=≤<=1<=000) — the number of points. The second line contains *n* space-separated integers *y*1,<=*y*2,<=...,<=*y**n* (<=-<=109<=≤<=*y**i*<=≤<=109) — the vertical coordinates of each point.
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower).
[ "5\n7 5 8 6 9\n", "5\n-1 -2 0 0 -5\n", "5\n5 4 3 2 1\n", "5\n1000000000 0 0 0 0\n" ]
[ "Yes\n", "No\n", "No\n", "Yes\n" ]
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, ...
1,000
[ { "input": "5\n7 5 8 6 9", "output": "Yes" }, { "input": "5\n-1 -2 0 0 -5", "output": "No" }, { "input": "5\n5 4 3 2 1", "output": "No" }, { "input": "5\n1000000000 0 0 0 0", "output": "Yes" }, { "input": "5\n1000000000 1 0 -999999999 -1000000000", "output": "...
1,504,275,885
2,985
Python 3
WRONG_ANSWER
PRETESTS
0
46
204,800
import sys n = int(input()) a = [0] + list(map(int, input().split())) if n == 1: print('No') sys.exit() if n == 2: print('Yes') sys.exit() # try line 1 -- 2 k = a[2] - a[1] i = 3 delta = None while i <= n: d = a[i] - a[1] + k * (i - 1) if d != 0: if delta is None: del...
Title: Tell Your World Time Limit: None seconds Memory Limit: None megabytes Problem Description: Connect the countless points with lines, till we reach the faraway yonder. There are *n* points on a coordinate plane, the *i*-th of which being (*i*,<=*y**i*). Determine whether it's possible to draw two parallel and...
```python import sys n = int(input()) a = [0] + list(map(int, input().split())) if n == 1: print('No') sys.exit() if n == 2: print('Yes') sys.exit() # try line 1 -- 2 k = a[2] - a[1] i = 3 delta = None while i <= n: d = a[i] - a[1] + k * (i - 1) if d != 0: if delta is None: ...
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,605,113,364
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
248
0
n=input() m=input() l=len(n) c=0 if n==m: print("NO") else: if(sorted(n)==sorted(m)): 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 n=input() m=input() l=len(n) c=0 if n==m: print("NO") else: if(sorted(n)==sorted(m)): print("YES") else: print("NO") ```
0
275
A
Lights Out
PROGRAMMING
900
[ "implementation" ]
null
null
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw...
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
[ "1 0 0\n0 0 0\n0 0 1\n", "1 0 1\n8 8 8\n2 0 3\n" ]
[ "001\n010\n100\n", "010\n011\n100\n" ]
none
500
[ { "input": "1 0 0\n0 0 0\n0 0 1", "output": "001\n010\n100" }, { "input": "1 0 1\n8 8 8\n2 0 3", "output": "010\n011\n100" }, { "input": "13 85 77\n25 50 45\n65 79 9", "output": "000\n010\n000" }, { "input": "96 95 5\n8 84 74\n67 31 61", "output": "011\n011\n101" }, {...
1,692,822,233
2,147,483,647
Python 3
OK
TESTS
33
46
102,400
arr = [] a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] c = [int(i) for i in input().split()] arr.append(a) arr.append(b) arr.append(c) x = [[1, 1, 1],[1, 1, 1],[1, 1, 1]] for i in range(0,3): for j in range(0,3): if arr[i][j] % 2 != 0: # self if x[i][j] ...
Title: Lights Out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ...
```python arr = [] a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] c = [int(i) for i in input().split()] arr.append(a) arr.append(b) arr.append(c) x = [[1, 1, 1],[1, 1, 1],[1, 1, 1]] for i in range(0,3): for j in range(0,3): if arr[i][j] % 2 != 0: # self i...
3
682
A
Alyona and Numbers
PROGRAMMING
1,100
[ "constructive algorithms", "math", "number theory" ]
null
null
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first...
The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000).
Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5.
[ "6 12\n", "11 14\n", "1 5\n", "3 8\n", "5 7\n", "21 21\n" ]
[ "14\n", "31\n", "1\n", "5\n", "7\n", "88\n" ]
Following pairs are suitable in the first sample case: - for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9. Only th...
500
[ { "input": "6 12", "output": "14" }, { "input": "11 14", "output": "31" }, { "input": "1 5", "output": "1" }, { "input": "3 8", "output": "5" }, { "input": "5 7", "output": "7" }, { "input": "21 21", "output": "88" }, { "input": "10 15", ...
1,669,247,386
2,147,483,647
Python 3
OK
TESTS
128
46
0
import math num = sorted([int(x) for x in input().split()]) c = 0 if num[0] > 5: for i in range(1, 6): c += len(range(5 if 5-i == 0 else 5-i, num[1]+1, 5)) c *= (math.floor(num[0]/5)) for x in range(1, num[0] % 5 + 1): c += len(range(5 if 5-x == 0 else 5-x, num[1]+1, 5)) else: ...
Title: Alyona and Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers ...
```python import math num = sorted([int(x) for x in input().split()]) c = 0 if num[0] > 5: for i in range(1, 6): c += len(range(5 if 5-i == 0 else 5-i, num[1]+1, 5)) c *= (math.floor(num[0]/5)) for x in range(1, num[0] % 5 + 1): c += len(range(5 if 5-x == 0 else 5-x, num[1]+1, 5)...
3
47
A
Triangular numbers
PROGRAMMING
800
[ "brute force", "math" ]
A. Triangular numbers
2
256
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers fr...
The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer.
If the given integer is a triangular number output YES, otherwise output NO.
[ "1\n", "2\n", "3\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "1", "output": "YES" }, { "input": "2", "output": "NO" }, { "input": "3", "output": "YES" }, { "input": "4", "output": "NO" }, { "input": "5", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "7", "output": "NO...
1,631,713,111
2,147,483,647
Python 3
OK
TESTS
71
154
6,758,400
if int(input()) in [1,3,6,10,15,21,28,36,45,55,66,78,91,105,120,136,153,171,190,210,231,253,276,300,325,351,378,406,435,465,496]: print('YES') else: print('NO')
Title: Triangular numbers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t...
```python if int(input()) in [1,3,6,10,15,21,28,36,45,55,66,78,91,105,120,136,153,171,190,210,231,253,276,300,325,351,378,406,435,465,496]: print('YES') else: print('NO') ```
3.948911
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,658,002,103
2,147,483,647
Python 3
OK
TESTS
16
31
0
n = int(input()) p = list(map(int, input().split())) p = [ (p[i] - 1) for i in range (n)] for i in range(n): if p[p[p[i]]] == i: print("YES") break if i == n - 1: 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()) p = list(map(int, input().split())) p = [ (p[i] - 1) for i in range (n)] for i in range(n): if p[p[p[i]]] == i: print("YES") break if i == n - 1: print("NO") ```
3
399
A
Pages
PROGRAMMING
0
[ "implementation" ]
null
null
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this: When someone clicks the button "&lt;&lt;" he is redirected to page 1, and wh...
The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*)
Print the proper navigation. Follow the format of the output from the test samples.
[ "17 5 2\n", "6 5 2\n", "6 1 2\n", "6 2 2\n", "9 6 3\n", "10 6 3\n", "8 5 4\n" ]
[ "&lt;&lt; 3 4 (5) 6 7 &gt;&gt; ", "&lt;&lt; 3 4 (5) 6 ", "(1) 2 3 &gt;&gt; ", "1 (2) 3 4 &gt;&gt;", "&lt;&lt; 3 4 5 (6) 7 8 9", "&lt;&lt; 3 4 5 (6) 7 8 9 &gt;&gt;", "1 2 3 4 (5) 6 7 8 " ]
none
500
[ { "input": "17 5 2", "output": "<< 3 4 (5) 6 7 >> " }, { "input": "6 5 2", "output": "<< 3 4 (5) 6 " }, { "input": "6 1 2", "output": "(1) 2 3 >> " }, { "input": "6 2 2", "output": "1 (2) 3 4 >> " }, { "input": "9 6 3", "output": "<< 3 4 5 (6) 7 8 9 " }, {...
1,567,667,380
2,147,483,647
Python 3
OK
TESTS
26
109
0
# cook your dish here n,p,k = map(int,(input()).split()) result_list = ['({p})'.format(p=p)] end=beg=p if p<n: for i in range(k): if end>=n: break end+=1 result_list.append(end) if end<n: result_list.append('>>') if p>1: for i in range(k): if...
Title: Pages Time Limit: None seconds Memory Limit: None megabytes Problem Description: User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will lo...
```python # cook your dish here n,p,k = map(int,(input()).split()) result_list = ['({p})'.format(p=p)] end=beg=p if p<n: for i in range(k): if end>=n: break end+=1 result_list.append(end) if end<n: result_list.append('>>') if p>1: for i in range(k): ...
3
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }...
1,695,497,121
2,147,483,647
PyPy 3-64
OK
TESTS
15
46
0
k,n,w=map(int,input().split()) print(max(k*w*(1+w)//2-n,0))
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He h...
```python k,n,w=map(int,input().split()) print(max(k*w*(1+w)//2-n,0)) ```
3
46
C
Hamsters and Tigers
PROGRAMMING
1,600
[ "two pointers" ]
C. Hamsters and Tigers
2
256
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
The first line contains number *n* (2<=≤<=*n*<=≤<=1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of *n* symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at ...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
[ "3\nHTH\n", "9\nHTHTHTHHT\n" ]
[ "0\n", "2\n" ]
In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
0
[ { "input": "3\nHTH", "output": "0" }, { "input": "9\nHTHTHTHHT", "output": "2" }, { "input": "2\nTH", "output": "0" }, { "input": "4\nHTTH", "output": "0" }, { "input": "4\nHTHT", "output": "1" }, { "input": "7\nTTTHTTT", "output": "0" }, { ...
1,647,006,400
2,147,483,647
Python 3
OK
TESTS
27
92
0
n=int(input()) s=input() q=s.count("H") w=n-q o=1001 for i in range(n-q+1): o=min(o,q-s[i:i+q].count("H")) for i in range(n-w+1): o=min(o,w-s[i:i+w].count("T")) print(o)
Title: Hamsters and Tigers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap ...
```python n=int(input()) s=input() q=s.count("H") w=n-q o=1001 for i in range(n-q+1): o=min(o,q-s[i:i+q].count("H")) for i in range(n-w+1): o=min(o,w-s[i:i+w].count("T")) print(o) ```
3.977
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If...
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "outp...
1,685,538,020
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
36
92
0
n = int(input()) n_array = list(str(n)) team1 = 0 team0 = 0 bad = True for i in range(len((n_array))): if n_array[i] == "0": team0 +=1 team1 = 0 if n_array[i] == "1": team1 +=1 team0 = 0 if team0 ==7 or team1 ==7: print("YES") bad = False ...
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A...
```python n = int(input()) n_array = list(str(n)) team1 = 0 team0 = 0 bad = True for i in range(len((n_array))): if n_array[i] == "0": team0 +=1 team1 = 0 if n_array[i] == "1": team1 +=1 team0 = 0 if team0 ==7 or team1 ==7: print("YES") bad = Fal...
0
0
none
none
none
0
[ "none" ]
null
null
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly *n* skills. Each skill is represented by a non-negative integer *a**i* — the current skill level. All skills have the same maximum level *A*. Al...
The first line of the input contains five space-separated integers *n*, *A*, *c**f*, *c**m* and *m* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*A*<=≤<=109, 0<=≤<=*c**f*,<=*c**m*<=≤<=1000, 0<=≤<=*m*<=≤<=1015). The second line contains exactly *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*A*), separated by spaces, — the current levels of ...
On the first line print the maximum value of the Force that the character can achieve using no more than *m* currency units. On the second line print *n* integers *a*'*i* (*a**i*<=≤<=*a*'*i*<=≤<=*A*), skill levels which one must achieve in order to reach the specified value of the Force, while using no more than *m* c...
[ "3 5 10 1 5\n1 3 1\n", "3 5 10 1 339\n1 3 1\n" ]
[ "12\n2 5 2 \n", "35\n5 5 5 \n" ]
In the first test the optimal strategy is to increase the second skill to its maximum, and increase the two others by 1. In the second test one should increase all skills to maximum.
0
[ { "input": "3 5 10 1 5\n1 3 1", "output": "12\n2 5 2 " }, { "input": "3 5 10 1 339\n1 3 1", "output": "35\n5 5 5 " }, { "input": "2 6 0 1 4\n5 1", "output": "5\n5 5 " }, { "input": "1 1000000000 1000 1000 1000000000000000\n0", "output": "1000000001000\n1000000000 " }, ...
1,500,609,241
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
93
23,142,400
n, A, cf, cm, m = [int(i) for i in input().split(' ')] a = [int(i) for i in input().split(' ')] b = [[a[i], i] for i in range(len(a))] b.sort() nA = 0 while b[-1-nA][0] == A: nA += 1 mi = b[0][0] f = cf * nA + cm * mi rm = m for i in range(nA,n+1): rm = rm - A + b[-i][0] if i>0 else rm if rm < 0: br...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly *n* skills. Each skill is represented by a non-negative...
```python n, A, cf, cm, m = [int(i) for i in input().split(' ')] a = [int(i) for i in input().split(' ')] b = [[a[i], i] for i in range(len(a))] b.sort() nA = 0 while b[-1-nA][0] == A: nA += 1 mi = b[0][0] f = cf * nA + cm * mi rm = m for i in range(nA,n+1): rm = rm - A + b[-i][0] if i>0 else rm if rm < 0: ...
0
31
A
Worms Evolution
PROGRAMMING
1,200
[ "implementation" ]
A. Worms Evolution
2
256
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to ...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form.
Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*.
[ "5\n1 2 3 5 7\n", "5\n1 8 1 5 1\n" ]
[ "3 2 1\n", "-1\n" ]
none
500
[ { "input": "5\n1 2 3 5 7", "output": "3 2 1" }, { "input": "5\n1 8 1 5 1", "output": "-1" }, { "input": "4\n303 872 764 401", "output": "-1" }, { "input": "6\n86 402 133 524 405 610", "output": "6 4 1" }, { "input": "8\n217 779 418 895 996 473 3 22", "output":...
1,489,269,455
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
4,505,600
n = int(input()) a = [int(x) for x in input().split()] b = [x for x in a] def main(a, n): a = sorted(a) i = 0 k = 0 l = 0 l_zapas = 0 for j in range(n): i = n - j - 1 while a[l] < (a[i] / 2): l += 1 l_zapas = l while a[k] <= (a[i] / 2): w...
Title: Worms Evolution Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his...
```python n = int(input()) a = [int(x) for x in input().split()] b = [x for x in a] def main(a, n): a = sorted(a) i = 0 k = 0 l = 0 l_zapas = 0 for j in range(n): i = n - j - 1 while a[l] < (a[i] / 2): l += 1 l_zapas = l while a[k] <= (a[i] / 2): ...
0
401
A
Vanya and Cards
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value. Natasha doesn't like when Vanya spends a long time p...
The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their a...
Print a single number — the answer to the problem.
[ "3 2\n-1 1 2\n", "2 3\n-2 -2\n" ]
[ "1\n", "2\n" ]
In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
500
[ { "input": "3 2\n-1 1 2", "output": "1" }, { "input": "2 3\n-2 -2", "output": "2" }, { "input": "4 4\n1 2 3 4", "output": "3" }, { "input": "2 2\n-1 -1", "output": "1" }, { "input": "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2", "output": "4" }, { "...
1,624,805,860
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
n,x=map(int,input().split()) m=list(map(int,input().split())) if abs(sum(m))<=x: print(1) else: print(len(m))
Title: Vanya and Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each...
```python n,x=map(int,input().split()) m=list(map(int,input().split())) if abs(sum(m))<=x: print(1) else: print(len(m)) ```
0
665
C
Simple Strings
PROGRAMMING
1,300
[ "dp", "greedy", "strings" ]
null
null
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple. zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with th...
The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters.
Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them. Note that the string *s*' should also consist of only lowercase English letters.
[ "aab\n", "caaab\n", "zscoder\n" ]
[ "bab\n", "cabab\n", "zscoder\n" ]
none
0
[ { "input": "aab", "output": "bab" }, { "input": "caaab", "output": "cabab" }, { "input": "zscoder", "output": "zscoder" }, { "input": "u", "output": "u" }, { "input": "h", "output": "h" }, { "input": "dtottttotd", "output": "dtotataotd" }, { ...
1,615,826,300
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
1,715
9,113,600
s = input() + '6' cnt = 1 last = s[0] for i in range(1, len(s)): if s[i] == last: cnt += 1 else: cnt = 1 last = s[i] if cnt > 1 and cnt % 2 == 0: letter = 'y' s = s[0:i] + letter + s[i+1:len(s)] print(s[0:-1])
Title: Simple Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple. zscoder is given a string *s*. He wa...
```python s = input() + '6' cnt = 1 last = s[0] for i in range(1, len(s)): if s[i] == last: cnt += 1 else: cnt = 1 last = s[i] if cnt > 1 and cnt % 2 == 0: letter = 'y' s = s[0:i] + letter + s[i+1:len(s)] print(s[0:-1]) ```
0
262
A
Roma and Lucky Numbers
PROGRAMMING
800
[ "implementation" ]
null
null
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integer...
The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has. The numbers in the lines are separated by single spaces.
In a single line print a single integer — the answer to the problem.
[ "3 4\n1 2 4\n", "3 2\n447 44 77\n" ]
[ "3\n", "2\n" ]
In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
500
[ { "input": "3 4\n1 2 4", "output": "3" }, { "input": "3 2\n447 44 77", "output": "2" }, { "input": "2 2\n507978501 180480073", "output": "2" }, { "input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089", "output": "9" }, { ...
1,606,172,810
2,147,483,647
PyPy 3
OK
TESTS
34
280
0
def solve(t_id): n, k = map(int, input().split()) ans = 0 a = list(input().split()) for i in range(n): s = a[i] if s.count('4') + s.count('7') <= k: ans += 1 print(ans) t = 1 #t = int(input()) for t_id in range(1, t + 1): solve(t_id) t -= 1
Title: Roma and Lucky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits...
```python def solve(t_id): n, k = map(int, input().split()) ans = 0 a = list(input().split()) for i in range(n): s = a[i] if s.count('4') + s.count('7') <= k: ans += 1 print(ans) t = 1 #t = int(input()) for t_id in range(1, t + 1): solve(t_id) t -= 1 ...
3
460
A
Vasya and Socks
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la...
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Print a single integer — the answer to the problem.
[ "2 2\n", "9 3\n" ]
[ "3\n", "13\n" ]
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on...
500
[ { "input": "2 2", "output": "3" }, { "input": "9 3", "output": "13" }, { "input": "1 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "1 99", "output": "1" }, { "input": "4 4", "output": "5" }, { "input": "10 2", "outp...
1,678,068,438
2,147,483,647
Python 3
OK
TESTS
26
46
0
n, m = map(int, input().split()) days, socks = 0, n while socks > 0: days += 1 socks -= 1 if days % m == 0: socks += 1 print(days)
Title: Vasya and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th...
```python n, m = map(int, input().split()) days, socks = 0, n while socks > 0: days += 1 socks -= 1 if days % m == 0: socks += 1 print(days) ```
3
490
A
Team Olympiad
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at prog...
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
In the first line output integer *w* — the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to...
[ "7\n1 3 1 3 2 1 2\n", "4\n2 1 1 2\n" ]
[ "2\n3 5 2\n6 7 4\n", "0\n" ]
none
500
[ { "input": "7\n1 3 1 3 2 1 2", "output": "2\n3 5 2\n6 7 4" }, { "input": "4\n2 1 1 2", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "2\n3 1", "output": "0" }, { "input": "3\n2 1 2", "output": "0" }, { "input": "3\n1 2 3", "output...
1,678,211,066
2,147,483,647
Python 3
OK
TESTS
41
62
0
n = int(input()) t = list(map(int, input().split())) one = [] two = [] three = [] if len(t) < 3 or t.count(1) == 0 or t.count(2) == 0 or t.count(3) == 0: print(0) else: for i in range(len(t)): if t[i] == 1: one.append(i+1) elif t[i] == 2: two.append(i+1) ...
Title: Team Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)...
```python n = int(input()) t = list(map(int, input().split())) one = [] two = [] three = [] if len(t) < 3 or t.count(1) == 0 or t.count(2) == 0 or t.count(3) == 0: print(0) else: for i in range(len(t)): if t[i] == 1: one.append(i+1) elif t[i] == 2: two.app...
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,693,075,750
2,147,483,647
Python 3
OK
TESTS
40
46
0
s = input() check = "" for i in range(len(s)): char = s[i] if char == 'h' and len(check)==0: check+=char continue if char == 'e' and len(check)==1: check+=char continue if char == 'l' and len(check)==2: check+=char continue if char == 'l' and len(check)==3: check+=char continue ...
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python s = input() check = "" for i in range(len(s)): char = s[i] if char == 'h' and len(check)==0: check+=char continue if char == 'e' and len(check)==1: check+=char continue if char == 'l' and len(check)==2: check+=char continue if char == 'l' and len(check)==3: check+=char ...
3.977
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,588,447,621
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
248
0
t = int(input()) c = [0, 0, 0, 0] for _ in range(t): a, b = input().split(' ') a = int(a)%2 b = int(b)%2 c[a + 2 * b] = 1 #print(c) if (c[3]%2 == 0) and (abs(c[2]-c[1])%2 == 0): if c[1]%2 > 0: print(1) else: print(0) else: print(-1)
Title: Domino Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the n...
```python t = int(input()) c = [0, 0, 0, 0] for _ in range(t): a, b = input().split(' ') a = int(a)%2 b = int(b)%2 c[a + 2 * b] = 1 #print(c) if (c[3]%2 == 0) and (abs(c[2]-c[1])%2 == 0): if c[1]%2 > 0: print(1) else: print(0) else: print(-1) ```
0
448
A
Rewards
PROGRAMMING
800
[ "implementation" ]
null
null
Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize c...
The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100). The numbers in the lines are separated by single spaces.
Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).
[ "1 1 1\n1 1 1\n4\n", "1 1 3\n2 3 4\n2\n", "1 0 0\n1 0 0\n1\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "1 1 1\n1 1 1\n4", "output": "YES" }, { "input": "1 1 3\n2 3 4\n2", "output": "YES" }, { "input": "1 0 0\n1 0 0\n1", "output": "NO" }, { "input": "0 0 0\n0 0 0\n1", "output": "YES" }, { "input": "100 100 100\n100 100 100\n100", "output": "YES" }, ...
1,676,825,868
2,147,483,647
Python 3
OK
TESTS
25
46
0
a1, a2, a3 = map(int,input().split()) b1, b2, b3 = map(int,input().split()) n = int(input()) a = a1 + a2 + a3 b = b1 + b2 + b3 if (a%5 == 0): x = int((a/5)) else: x = int((a/5 + 1)) if (b%10 == 0): z = int((b/10)) else: z = int((b/10 + 1)) if (x + z) > n : print("NO") else: print("YES")
Title: Rewards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into ...
```python a1, a2, a3 = map(int,input().split()) b1, b2, b3 = map(int,input().split()) n = int(input()) a = a1 + a2 + a3 b = b1 + b2 + b3 if (a%5 == 0): x = int((a/5)) else: x = int((a/5 + 1)) if (b%10 == 0): z = int((b/10)) else: z = int((b/10 + 1)) if (x + z) > n : print("NO") else: print(...
3
706
B
Interesting drink
PROGRAMMING
1,100
[ "binary search", "dp", "implementation" ]
null
null
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite ...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop. The third line contains a single i...
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
[ "5\n3 10 8 6 11\n4\n1\n10\n3\n11\n" ]
[ "0\n4\n1\n5\n" ]
On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop.
1,000
[ { "input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11", "output": "0\n4\n1\n5" }, { "input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471", "output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2" }, { "input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521", "output": "...
1,698,416,715
2,147,483,647
PyPy 3-64
OK
TESTS
103
171
13,721,600
from sys import stdin input = lambda: stdin.readline().strip() n = int(input()) x = sorted(list(map(int,input().split()))) for _ in range(int(input())): q = int(input()) if q < x[0]: print(0) continue l,r = 0, n - 1 while l <= r: mid = (l + r) // 2 if x[mid] >...
Title: Interesting drink Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha...
```python from sys import stdin input = lambda: stdin.readline().strip() n = int(input()) x = sorted(list(map(int,input().split()))) for _ in range(int(input())): q = int(input()) if q < x[0]: print(0) continue l,r = 0, n - 1 while l <= r: mid = (l + r) // 2 i...
3
81
C
Average Score
PROGRAMMING
1,700
[ "greedy", "math", "sortings" ]
C. Average Score
2
256
After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received *n* marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wrote the mark. Now i...
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105), *n* is the number of marks in Polycarp's Journal. The second line contains two positive integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=*n*<=-<=1,<=*a*<=+<=*b*<==<=*n*). The third line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=5), th...
Print the sequence of integers *f*1,<=*f*2,<=...,<=*f**n*, where *f**i* (1<=≤<=*f**i*<=≤<=2) is the number of a subject to which the *i*-th mark should be attributed. If there are several possible solutions, then print such that the sequence *f*1,<=*f*2,<=...,<=*f**n* is the smallest lexicographically. The sequence *p...
[ "5\n3 2\n4 4 5 4 4\n", "4\n2 2\n3 5 4 5\n", "6\n1 5\n4 4 4 5 4 4\n" ]
[ "1 1 2 1 2 ", "1 1 2 2 ", "2 2 2 1 2 2 " ]
In the first sample the average score in the first subject is equal to 4, and in the second one — to 4.5. The total average score is 8.5.
1,500
[ { "input": "5\n3 2\n4 4 5 4 4", "output": "1 1 2 1 2 " }, { "input": "4\n2 2\n3 5 4 5", "output": "1 1 2 2 " }, { "input": "6\n1 5\n4 4 4 5 4 4", "output": "2 2 2 1 2 2 " }, { "input": "4\n2 2\n2 1 3 3", "output": "1 1 2 2 " }, { "input": "9\n3 6\n4 5 4 1 2 2 2 4 ...
1,378,383,702
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
33
2,000
2,662,400
import sys n=int(sys.stdin.readline()) a,b=map(int,sys.stdin.readline().split()) marks=list(map(int,sys.stdin.readline().split())) Indices_of_marks={} Order={} for item in set(marks): Indices_of_marks[item]=() Order[item]=0 for i in range(n): Indices_of_marks[marks[i]]+=(i,) if(a==b): sys.stdout...
Title: Average Score Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received *n* marks in them. When teachers wrote a mark in th...
```python import sys n=int(sys.stdin.readline()) a,b=map(int,sys.stdin.readline().split()) marks=list(map(int,sys.stdin.readline().split())) Indices_of_marks={} Order={} for item in set(marks): Indices_of_marks[item]=() Order[item]=0 for i in range(n): Indices_of_marks[marks[i]]+=(i,) if(a==b): ...
0
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,561,745,744
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
0
from math import * a,b=map(int,input().split()) l=[int(x) for x in input().split()] m=min(l.count(1),l.count(-1)) for x in range(a): c,d=map(int,input().split()) if ceil((d-c)/2)<=m and (d-c)%2!=0: print(1) else: print(0)
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 from math import * a,b=map(int,input().split()) l=[int(x) for x in input().split()] m=min(l.count(1),l.count(-1)) for x in range(a): c,d=map(int,input().split()) if ceil((d-c)/2)<=m and (d-c)%2!=0: print(1) else: print(0) ```
0
595
A
Vitaly and Night
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats num...
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively. Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on,...
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
[ "2 2\n0 0 0 1\n1 0 1 1\n", "1 3\n1 1 0 1 0 0\n" ]
[ "3\n", "2\n" ]
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off. In the second test case the house has one floor and the first floor has three flats. The ligh...
500
[ { "input": "2 2\n0 0 0 1\n1 0 1 1", "output": "3" }, { "input": "1 3\n1 1 0 1 0 0", "output": "2" }, { "input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1", "output": "8" }, { "input": "1 5\n1 0 1 1 1 0 1 1 1 1", "output": "5" }, { "input": "1 100\n1 1 1 1 1 1 1 ...
1,546,069,037
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
109
0
n = list(map(int, input().split())) counter = 0 b = [0 for i in range(n[1])] for i in range(n[0]): a = list(map(int, input().split())) for i in range(0, 2*n[1], 2): if a[i] == 1 or a[i+1] == 1: b[int(i/2)] = 1 counter += b.count(1) print(counter)
Title: Vitaly and Night Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vital...
```python n = list(map(int, input().split())) counter = 0 b = [0 for i in range(n[1])] for i in range(n[0]): a = list(map(int, input().split())) for i in range(0, 2*n[1], 2): if a[i] == 1 or a[i+1] == 1: b[int(i/2)] = 1 counter += b.count(1) print(counter) ```
0
792
A
New Bus Route
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct. It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport d...
The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct.
Print two integer numbers — the minimal distance and the quantity of pairs with this distance.
[ "4\n6 -3 0 4\n", "3\n-2 0 2\n" ]
[ "2 1\n", "2 2\n" ]
In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance.
0
[ { "input": "4\n6 -3 0 4", "output": "2 1" }, { "input": "3\n-2 0 2", "output": "2 2" }, { "input": "2\n1 2", "output": "1 1" }, { "input": "2\n1000000000 -1000000000", "output": "2000000000 1" }, { "input": "5\n-979619606 -979619602 -979619604 -979619605 -97961960...
1,490,627,108
1,808
Python 3
WRONG_ANSWER
TESTS
3
62
4,608,000
n=int(input()) A=list(map(int,input().split(" "))) A.sort() mindiff=max(A) for i in range(1,n): mindiff=min(mindiff,A[i]-A[i-1]) ct=0 for i in range(1,n): if A[i]-A[i-1]==mindiff: ct+=1 print(mindiff,ct)
Title: New Bus Route Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct. It is possible to get from on...
```python n=int(input()) A=list(map(int,input().split(" "))) A.sort() mindiff=max(A) for i in range(1,n): mindiff=min(mindiff,A[i]-A[i-1]) ct=0 for i in range(1,n): if A[i]-A[i-1]==mindiff: ct+=1 print(mindiff,ct) ```
0
609
D
Gadgets for dollars and pounds
PROGRAMMING
2,000
[ "binary search", "greedy", "two pointers" ]
null
null
Nura wants to buy *k* gadgets. She has only *s* burles for that. She can buy each gadget for dollars or for pounds. So each gadget is selling only for some type of currency. The type of currency and the cost in that currency are not changing. Nura can buy gadgets for *n* days. For each day you know the exchange rates ...
First line contains four integers *n*,<=*m*,<=*k*,<=*s* (1<=≤<=*n*<=≤<=2·105,<=1<=≤<=*k*<=≤<=*m*<=≤<=2·105,<=1<=≤<=*s*<=≤<=109) — number of days, total number and required number of gadgets, number of burles Nura has. Second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the cost of one dollar in burles on...
If Nura can't buy *k* gadgets print the only line with the number -1. Otherwise the first line should contain integer *d* — the minimum day index, when Nura will have *k* gadgets. On each of the next *k* lines print two integers *q**i*,<=*d**i* — the number of gadget and the day gadget should be bought. All values *q*...
[ "5 4 2 2\n1 2 3 2 1\n3 2 1 2 3\n1 1\n2 1\n1 2\n2 2\n", "4 3 2 200\n69 70 71 72\n104 105 106 107\n1 1\n2 2\n1 2\n", "4 3 1 1000000000\n900000 910000 940000 990000\n990000 999000 999900 999990\n1 87654\n2 76543\n1 65432\n" ]
[ "3\n1 1\n2 3\n", "-1\n", "-1\n" ]
none
0
[ { "input": "5 4 2 2\n1 2 3 2 1\n3 2 1 2 3\n1 1\n2 1\n1 2\n2 2", "output": "3\n1 1\n2 3" }, { "input": "4 3 2 200\n69 70 71 72\n104 105 106 107\n1 1\n2 2\n1 2", "output": "-1" }, { "input": "4 3 1 1000000000\n900000 910000 940000 990000\n990000 999000 999900 999990\n1 87654\n2 76543\n1 65...
1,691,518,511
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1691518511.2521472")# 1691518511.252165
Title: Gadgets for dollars and pounds Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nura wants to buy *k* gadgets. She has only *s* burles for that. She can buy each gadget for dollars or for pounds. So each gadget is selling only for some type of currency. The type of currency and the c...
```python print("_RANDOM_GUESS_1691518511.2521472")# 1691518511.252165 ```
0