contestId
int64
0
1.01k
index
stringclasses
40 values
name
stringlengths
2
54
type
stringclasses
2 values
rating
int64
0
3.4k
tags
listlengths
0
7
title
stringclasses
393 values
time-limit
stringclasses
7 values
memory-limit
stringclasses
6 values
problem-description
stringlengths
0
2.97k
input-specification
stringlengths
4
1.87k
output-specification
stringlengths
4
1.12k
demo-input
listlengths
0
7
demo-output
listlengths
0
7
note
stringlengths
0
5.24k
points
float64
0
3.5k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
1 value
testset
stringclasses
9 values
passedTestCount
int64
1
402
timeConsumedMillis
int64
15
8.06k
memoryConsumedBytes
int64
0
514M
code
stringlengths
11
61.4k
prompt
stringlengths
297
7.35k
response
stringlengths
25
61.4k
score
float64
2.82
3.99
119
A
Epic Game
PROGRAMMING
800
[ "implementation" ]
null
null
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take...
The only string contains space-separated integers *a*, *b* and *n* (1<=≀<=*a*,<=*b*,<=*n*<=≀<=100) β€” the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
[ "3 5 9\n", "1 1 100\n" ]
[ "0", "1" ]
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b...
500
[ { "input": "3 5 9", "output": "0" }, { "input": "1 1 100", "output": "1" }, { "input": "23 12 16", "output": "1" }, { "input": "95 26 29", "output": "1" }, { "input": "73 32 99", "output": "1" }, { "input": "1 1 1", "output": "0" }, { "inpu...
1,639,939,012
2,147,483,647
Python 3
OK
TESTS
45
122
0
def gcd(a, b): for i in range(min(a, b), 0, -1): if a % i == 0 and b % i == 0: return i return max(a, b) a, b, n = map(int, input().split()) turn = 0 while True: if not turn: a_gcd = gcd(a, n) if a_gcd > n: break n -= a_gcd else: ...
Title: Epic Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto...
```python def gcd(a, b): for i in range(min(a, b), 0, -1): if a % i == 0 and b % i == 0: return i return max(a, b) a, b, n = map(int, input().split()) turn = 0 while True: if not turn: a_gcd = gcd(a, n) if a_gcd > n: break n -= a_gcd ...
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≀<=*x**i*,<=*y**i*,<=*z**i*<=≀<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,621,415,426
2,147,483,647
Python 3
OK
TESTS
81
124
0
x,y,z=0,0,0 for t in range(int(input())): a,b,c=map(int,input().split()) x+=a y+=b z+=c if x==0 and y==0 and z==0: print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python x,y,z=0,0,0 for t in range(int(input())): a,b,c=map(int,input().split()) x+=a y+=b z+=c if x==0 and y==0 and z==0: print("YES") else: print("NO") ```
3.969
690
F1
Tree of Life (easy)
PROGRAMMING
1,300
[]
null
null
Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of *n* points...
The first line of the input contains a single integer *n* – the number of vertices in the tree (1<=≀<=*n*<=≀<=10000). The vertices are labeled with the numbers from 1 to *n*. Then *n*<=-<=1 lines follow, each describing one edge using two space-separated numbers *a* *b* – the labels of the vertices connected by the edg...
Print one integer – the number of lifelines in the tree.
[ "4\n1 2\n1 3\n1 4\n", "5\n1 2\n2 3\n3 4\n3 5\n" ]
[ "3", "4" ]
In the second sample, there are four lifelines: paths between vertices 1 and 3, 2 and 4, 2 and 5, and 4 and 5.
0
[ { "input": "4\n1 2\n1 3\n1 4", "output": "3" }, { "input": "5\n1 2\n2 3\n3 4\n3 5", "output": "4" }, { "input": "2\n1 2", "output": "0" }, { "input": "3\n2 1\n3 2", "output": "1" }, { "input": "10\n5 1\n1 2\n9 3\n10 5\n6 3\n8 5\n2 7\n2 3\n9 4", "output": "11" ...
1,679,567,931
2,147,483,647
Python 3
OK
TESTS
19
62
102,400
import math n=int(input()) l=[0]*(n+1) # print(*l) for i in range(n-1): a,b=map(int,input().split()) l[a]+=1 l[b]+=1 ans=0 for i in range(1,n+1): if l[i]>=2: ans+=math.comb(l[i],2) print(ans)
Title: Tree of Life (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a r...
```python import math n=int(input()) l=[0]*(n+1) # print(*l) for i in range(n-1): a,b=map(int,input().split()) l[a]+=1 l[b]+=1 ans=0 for i in range(1,n+1): if l[i]>=2: ans+=math.comb(l[i],2) print(ans) ```
3
572
A
Arrays
PROGRAMMING
900
[ "sortings" ]
null
null
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array.
The first line contains two integers *n**A*,<=*n**B* (1<=≀<=*n**A*,<=*n**B*<=≀<=105), separated by a space β€” the sizes of arrays *A* and *B*, correspondingly. The second line contains two integers *k* and *m* (1<=≀<=*k*<=≀<=*n**A*,<=1<=≀<=*m*<=≀<=*n**B*), separated by a space. The third line contains *n**A* numbers *...
Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes).
[ "3 3\n2 1\n1 2 3\n3 4 5\n", "3 3\n3 3\n1 2 3\n3 4 5\n", "5 2\n3 1\n1 1 1 1 1\n2 2\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 &lt; 3 and 2 &lt; 3). In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the num...
500
[ { "input": "3 3\n2 1\n1 2 3\n3 4 5", "output": "YES" }, { "input": "3 3\n3 3\n1 2 3\n3 4 5", "output": "NO" }, { "input": "5 2\n3 1\n1 1 1 1 1\n2 2", "output": "YES" }, { "input": "3 5\n1 1\n5 5 5\n5 5 5 5 5", "output": "NO" }, { "input": "1 1\n1 1\n1\n1", "ou...
1,571,567,141
2,147,483,647
Python 3
OK
TESTS
52
186
10,444,800
na,nb=map(int,input().split()) k,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a.sort() b.sort(reverse=True) x=a[:k] y=b[:m] y.sort() if x[k-1]<y[0]: print("YES") else: print("NO")
Title: Arrays Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the fi...
```python na,nb=map(int,input().split()) k,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a.sort() b.sort(reverse=True) x=a[:k] y=b[:m] y.sort() if x[k-1]<y[0]: print("YES") else: print("NO") ```
3
48
A
Rock-paper-scissors
PROGRAMMING
900
[ "implementation", "schedules" ]
A. Rock-paper-scissors
2
256
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obvio...
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
[ "rock\nrock\nrock\n", "paper\nrock\nrock\n", "scissors\nrock\nrock\n", "scissors\npaper\nrock\n" ]
[ "?\n", "F\n", "?\n", "?\n" ]
none
0
[ { "input": "rock\nrock\nrock", "output": "?" }, { "input": "paper\nrock\nrock", "output": "F" }, { "input": "scissors\nrock\nrock", "output": "?" }, { "input": "scissors\npaper\nrock", "output": "?" }, { "input": "paper\npaper\nrock", "output": "?" }, { ...
1,583,057,438
2,147,483,647
Python 3
OK
TESTS
27
216
0
a=[input()[0] for _ in " "*3];i=set(a);p=len(set(a));e=["F","M","S"];k={"pr":"p","rs":"r","ps":"s"} if p==1 or p==3:print("?") else : s=k.get("".join(sorted(i))) if a.count(s)>1:print("?") else:print(e[a.index(s)])
Title: Rock-paper-scissors Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case ...
```python a=[input()[0] for _ in " "*3];i=set(a);p=len(set(a));e=["F","M","S"];k={"pr":"p","rs":"r","ps":"s"} if p==1 or p==3:print("?") else : s=k.get("".join(sorted(i))) if a.count(s)>1:print("?") else:print(e[a.index(s)]) ```
3.946
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set...
The first line contains two space-separated integers *n* and *m* (1<=≀<=*m*<=≀<=*n*<=≀<=100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≀<=*a**i*<=≀<=1000) β€” prices of the TV sets.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "...
1,569,892,437
2,147,483,647
Python 3
OK
TESTS
25
218
0
n, m = map(int, input().split()) prices = sorted(list(map(int, input().split()))) max = 0 count = 0 while count < m and prices[count] < 0: max += abs(prices[count]) count += 1 print(max)
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can...
```python n, m = map(int, input().split()) prices = sorted(list(map(int, input().split()))) max = 0 count = 0 while count < m and prices[count] < 0: max += abs(prices[count]) count += 1 print(max) ```
3.9455
779
A
Pupils Redistribution
PROGRAMMING
1,000
[ "constructive algorithms", "math" ]
null
null
In Berland each high school student is characterized by academic performance β€” integer value between 1 and 5. In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consists of exactly *n* students. An academic performance of each student is known β€” integer value between 1 and ...
The first line of the input contains integer number *n* (1<=≀<=*n*<=≀<=100) β€” number of students in both groups. The second line contains sequence of integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=5), where *a**i* is academic performance of the *i*-th student of the group *A*. The third line contains se...
Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained.
[ "4\n5 4 4 4\n5 5 4 5\n", "6\n1 1 1 1 1 1\n5 5 5 5 5 5\n", "1\n5\n3\n", "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1\n" ]
[ "1\n", "3\n", "-1\n", "4\n" ]
none
500
[ { "input": "4\n5 4 4 4\n5 5 4 5", "output": "1" }, { "input": "6\n1 1 1 1 1 1\n5 5 5 5 5 5", "output": "3" }, { "input": "1\n5\n3", "output": "-1" }, { "input": "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1", "output": "4" }, { "input": "1\n1\n2", "output": "-1" ...
1,652,906,127
2,147,483,647
Python 3
OK
TESTS
81
61
4,300,800
input() A,B = input(),input() D = [abs(A.count(x)- B.count(x)) for x in '12345'] print(-1 if any(d % 2 for d in D) else sum(D) //4)
Title: Pupils Redistribution Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Berland each high school student is characterized by academic performance β€” integer value between 1 and 5. In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consis...
```python input() A,B = input(),input() D = [abs(A.count(x)- B.count(x)) for x in '12345'] print(-1 if any(d % 2 for d in D) else sum(D) //4) ```
3
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,656,510,302
2,147,483,647
Python 3
OK
TESTS
31
92
0
n = int(input()) A = list(map(int, input().split())) N = sorted(list(set(A))) if(len(N)==1): print("NO") else: print(N[1])
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()) A = list(map(int, input().split())) N = sorted(list(set(A))) if(len(N)==1): print("NO") else: print(N[1]) ```
3.977
931
A
Friends Meeting
PROGRAMMING
800
[ "brute force", "greedy", "implementation", "math" ]
null
null
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco...
The first line contains a single integer *a* (1<=≀<=*a*<=≀<=1000) β€” the initial position of the first friend. The second line contains a single integer *b* (1<=≀<=*b*<=≀<=1000) β€” the initial position of the second friend. It is guaranteed that *a*<=β‰ <=*b*.
Print the minimum possible total tiredness if the friends meet in the same point.
[ "3\n4\n", "101\n99\n", "5\n10\n" ]
[ "1\n", "2\n", "9\n" ]
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, an...
500
[ { "input": "3\n4", "output": "1" }, { "input": "101\n99", "output": "2" }, { "input": "5\n10", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n1000", "output": "250000" }, { "input": "999\n1000", "output": "1" }, { "inpu...
1,563,079,527
2,147,483,647
PyPy 3
OK
TESTS
40
140
0
a=int(input()) b=int(input()) dif=abs(a-b) m1=dif//2 m2=dif-m1 print(m1*(m1+1)//2+m2*(m2+1)//2)
Title: Friends Meeting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in...
```python a=int(input()) b=int(input()) dif=abs(a-b) m1=dif//2 m2=dif-m1 print(m1*(m1+1)//2+m2*(m2+1)//2) ```
3
895
B
XK Segments
PROGRAMMING
1,700
[ "binary search", "math", "sortings", "two pointers" ]
null
null
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array *a* and integer *x*. He should find the number of different ordered pairs of indexes (*i*,<=*j*) such that *a**i*<=≀<=*a**j* and...
The first line contains 3 integers *n*,<=*x*,<=*k* (1<=≀<=*n*<=≀<=105,<=1<=≀<=*x*<=≀<=109,<=0<=≀<=*k*<=≀<=109), where *n* is the size of the array *a* and *x* and *k* are numbers from the statement. The second line contains *n* integers *a**i* (1<=≀<=*a**i*<=≀<=109)Β β€” the elements of the array *a*.
Print one integerΒ β€” the answer to the problem.
[ "4 2 1\n1 3 5 7\n", "4 2 0\n5 3 1 7\n", "5 3 1\n3 3 3 3 3\n" ]
[ "3\n", "4\n", "25\n" ]
In first sample there are only three suitable pairs of indexesΒ β€” (1, 2), (2, 3), (3, 4). In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4). In third sample every pair (*i*, *j*) is suitable, so the answer is 5 * 5 = 25.
1,000
[ { "input": "4 2 1\n1 3 5 7", "output": "3" }, { "input": "4 2 0\n5 3 1 7", "output": "4" }, { "input": "5 3 1\n3 3 3 3 3", "output": "25" }, { "input": "5 3 4\n24 13 1 24 24", "output": "4" }, { "input": "4 2 2\n1 3 5 7", "output": "2" }, { "input": "5...
1,680,583,470
2,147,483,647
PyPy 3-64
OK
TESTS
69
249
15,974,400
def lowerBound(a, val1, i, n, k, x): low = 0 high = n-1 while(low <= high): mid = (low + high)//2 val2 = a[mid] if(val2 >= val1): noOfEle = (val2)//x - (val1 - 1)//x if(noOfEle == k): if(mid == 0): return mid ...
Title: XK Segments Time Limit: None seconds Memory Limit: None megabytes Problem Description: While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array *a* and integer *x*. He should ...
```python def lowerBound(a, val1, i, n, k, x): low = 0 high = n-1 while(low <= high): mid = (low + high)//2 val2 = a[mid] if(val2 >= val1): noOfEle = (val2)//x - (val1 - 1)//x if(noOfEle == k): if(mid == 0): return...
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,680,232,788
2,147,483,647
Python 3
OK
TESTS
40
46
0
s=input() letter=['h','e','l','l','o'] j=0 for i in s: if j!=5: if i==letter[j]: j+=1 elif j==5: break else: continue if j==5: print('YES') else: print('NO')
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() letter=['h','e','l','l','o'] j=0 for i in s: if j!=5: if i==letter[j]: j+=1 elif j==5: break else: continue if j==5: print('YES') else: print('NO') ```
3.977
263
A
Beautiful Matrix
PROGRAMMING
800
[ "implementation" ]
null
null
You've got a 5<=Γ—<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1....
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Print a single integer β€” the minimum number of moves needed to make the matrix beautiful.
[ "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 0 0 0 0...
1,696,422,597
2,147,483,647
PyPy 3-64
OK
TESTS
25
154
0
matrix = [[int(i) for i in input().split()] for j in range(5)] r,c = -1,-1 for i in range(5): for j in range(5): if matrix[i][j] == 1: r = i c = j break print(abs(2-r)+abs(2-c))
Title: Beautiful Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a 5<=Γ—<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri...
```python matrix = [[int(i) for i in input().split()] for j in range(5)] r,c = -1,-1 for i in range(5): for j in range(5): if matrix[i][j] == 1: r = i c = j break print(abs(2-r)+abs(2-c)) ```
3
622
C
Not Equal on a Segment
PROGRAMMING
1,700
[ "data structures", "implementation" ]
null
null
You are given array *a* with *n* integers and *m* queries. The *i*-th query is given with three integers *l**i*,<=*r**i*,<=*x**i*. For the *i*-th query find any position *p**i* (*l**i*<=≀<=*p**i*<=≀<=*r**i*) so that *a**p**i*<=β‰ <=*x**i*.
The first line contains two integers *n*,<=*m* (1<=≀<=*n*,<=*m*<=≀<=2Β·105) β€” the number of elements in *a* and the number of queries. The second line contains *n* integers *a**i* (1<=≀<=*a**i*<=≀<=106) β€” the elements of the array *a*. Each of the next *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≀<=...
Print *m* lines. On the *i*-th line print integer *p**i* β€” the position of any number not equal to *x**i* in segment [*l**i*,<=*r**i*] or the value <=-<=1 if there is no such number.
[ "6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2\n" ]
[ "2\n6\n-1\n4\n" ]
none
0
[ { "input": "6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2", "output": "2\n6\n-1\n4" }, { "input": "1 1\n1\n1 1 1", "output": "-1" }, { "input": "1 1\n2\n1 1 2", "output": "-1" }, { "input": "1 1\n569888\n1 1 967368", "output": "1" }, { "input": "10 10\n1 1 1 1 1 1 ...
1,689,914,503
2,147,483,647
PyPy 3-64
OK
TESTS
63
311
27,443,200
import sys input = sys.stdin.readline n, m = map(int, input().split()) a = list(map(int, input().split())) s = [-1] for i in range(1, n): if(a[i] != a[i - 1]): s.append(i - 1) else: s.append(s[-1]) for i in range(m): l, r, x = map(int, input().split()) if(a[r - 1] !...
Title: Not Equal on a Segment Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given array *a* with *n* integers and *m* queries. The *i*-th query is given with three integers *l**i*,<=*r**i*,<=*x**i*. For the *i*-th query find any position *p**i* (*l**i*<=≀<=*p**i*<=≀<=*r**i*) so ...
```python import sys input = sys.stdin.readline n, m = map(int, input().split()) a = list(map(int, input().split())) s = [-1] for i in range(1, n): if(a[i] != a[i - 1]): s.append(i - 1) else: s.append(s[-1]) for i in range(m): l, r, x = map(int, input().split()) if(...
3
967
B
Watering System
PROGRAMMING
1,000
[ "math", "sortings" ]
null
null
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole. Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After...
The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$)Β β€” the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole. The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$)...
Print a single integerΒ β€” the number of holes Arkady should block.
[ "4 10 3\n2 2 2 2\n", "4 80 20\n3 2 1 4\n", "5 10 10\n1000 1 1 1 1\n" ]
[ "1\n", "0\n", "4\n" ]
In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady. In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not les...
1,000
[ { "input": "4 10 3\n2 2 2 2", "output": "1" }, { "input": "4 80 20\n3 2 1 4", "output": "0" }, { "input": "5 10 10\n1000 1 1 1 1", "output": "4" }, { "input": "10 300 100\n20 1 3 10 8 5 3 6 4 3", "output": "1" }, { "input": "10 300 100\n20 25 68 40 60 37 44 85 23 ...
1,580,779,814
2,147,483,647
Python 3
OK
TESTS
26
187
6,656,000
def _input(): return map(int, input().strip().split()) def _print(s): print(''.join(map(str, s))) n, A, B = _input() s = list(_input()) r = list(s[1:]) r.sort(reverse=True) tot = sum(s) if s[0] * A >= B * tot: print(0) exit(0) cur = tot for i in range(len(r)): cur -= r[i] if s...
Title: Watering System Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the fi...
```python def _input(): return map(int, input().strip().split()) def _print(s): print(''.join(map(str, s))) n, A, B = _input() s = list(_input()) r = list(s[1:]) r.sort(reverse=True) tot = sum(s) if s[0] * A >= B * tot: print(0) exit(0) cur = tot for i in range(len(r)): cur -= r[i]...
3
679
A
Bear and Prime 100
PROGRAMMING
1,400
[ "constructive algorithms", "interactive", "math" ]
null
null
This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden numberΒ β€” an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite. Integer *x*<=&gt;<=1 is called prime if it has exactly two d...
After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise.
Up to 20 times you can ask a queryΒ β€” print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input. In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flu...
[ "yes\nno\nyes\n", "no\nyes\nno\nno\nno\n" ]
[ "2\n80\n5\ncomposite\n", "58\n59\n78\n78\n2\nprime\n" ]
The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/> The hi...
750
[ { "input": "30", "output": "composite 4" }, { "input": "59", "output": "prime 15" }, { "input": "2", "output": "prime 16" }, { "input": "7", "output": "prime 16" }, { "input": "9", "output": "composite 3" }, { "input": "13", "output": "prime 15" ...
1,596,366,280
2,147,483,647
Python 3
OK
TESTS
59
109
6,963,200
from sys import * l=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,4,9,25,49] s=0 for i in range(len(l)): print(l[i]) stdout.flush() a=input() if(a=="yes"): s+=1 if(s>=2): print("composite") exit(0) print("prime")
Title: Bear and Prime 100 Time Limit: None seconds Memory Limit: None megabytes Problem Description: This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden numberΒ β€” an integer from interval [2,<=100]. Your task is to say i...
```python from sys import * l=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,4,9,25,49] s=0 for i in range(len(l)): print(l[i]) stdout.flush() a=input() if(a=="yes"): s+=1 if(s>=2): print("composite") exit(0) print("prime") ```
3
219
A
k-String
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string...
The first input line contains integer *k* (1<=≀<=*k*<=≀<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≀<=|*s*|<=≀<=1000, where |*s*| is the length of string *s*.
Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
[ "2\naazz\n", "3\nabcabcabz\n" ]
[ "azaz\n", "-1\n" ]
none
500
[ { "input": "2\naazz", "output": "azaz" }, { "input": "3\nabcabcabz", "output": "-1" }, { "input": "1\na", "output": "a" }, { "input": "2\nabba", "output": "abab" }, { "input": "2\naaab", "output": "-1" }, { "input": "7\nabacaba", "output": "-1" }...
1,628,156,861
2,147,483,647
PyPy 3
OK
TESTS
42
280
128,000,000
from sys import stdin, stdout from heapq import heapify , heappush , heappop import sys from collections import Counter,defaultdict,deque from copy import deepcopy import math from itertools import permutations from types import GeneratorType sys.setrecursionlimit(11 ** 5) def bootstrap(f, stttt=[]): def wrappedf...
Title: k-String Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ...
```python from sys import stdin, stdout from heapq import heapify , heappush , heappop import sys from collections import Counter,defaultdict,deque from copy import deepcopy import math from itertools import permutations from types import GeneratorType sys.setrecursionlimit(11 ** 5) def bootstrap(f, stttt=[]): de...
3
4
B
Before an Exam
PROGRAMMING
1,200
[ "constructive algorithms", "greedy" ]
B. Before an Exam
0
64
Tomorrow Peter has a Biology exam. He does not like this subject much, but *d* days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than *minTime**i* and not more than *maxTime**i* hours per each *i*-th day. ...
The first input line contains two integer numbers *d*,<=*sumTime* (1<=≀<=*d*<=≀<=30,<=0<=≀<=*sumTime*<=≀<=240) β€” the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following *d* lines contains two integer numbers *minTime**i*,<=*maxTime**i* (0<=≀<=*minTime**...
In the first line print YES, and in the second line print *d* numbers (separated by a space), each of the numbers β€” amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or print NO in the unique line. If there are many solutions, print any of them.
[ "1 48\n5 7\n", "2 5\n0 1\n3 5\n" ]
[ "NO\n", "YES\n1 4 " ]
none
0
[ { "input": "1 48\n5 7", "output": "NO" }, { "input": "2 5\n0 1\n3 5", "output": "YES\n1 4 " }, { "input": "1 1\n5 6", "output": "NO" }, { "input": "1 4\n2 4", "output": "YES\n4 " }, { "input": "2 5\n4 6\n0 0", "output": "YES\n5 0 " }, { "input": "27 97...
1,692,939,234
2,147,483,647
PyPy 3-64
OK
TESTS
15
62
0
d, s = map(int, input().split()) sumamin = 0 sumamax = 0 ans = 'YES' horasmin = [] horasmax = [] for i in range(d): minim, maxim = map(int, input().split()) horasmin.append(minim) horasmax.append(maxim) sumamin += minim sumamax += maxim if s < sumamin or s > sumamax: ans = 'NO' if ans == 'YES...
Title: Before an Exam Time Limit: 0 seconds Memory Limit: 64 megabytes Problem Description: Tomorrow Peter has a Biology exam. He does not like this subject much, but *d* days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has...
```python d, s = map(int, input().split()) sumamin = 0 sumamax = 0 ans = 'YES' horasmin = [] horasmax = [] for i in range(d): minim, maxim = map(int, input().split()) horasmin.append(minim) horasmax.append(maxim) sumamin += minim sumamax += maxim if s < sumamin or s > sumamax: ans = 'NO' if a...
3
318
A
Even Odds
PROGRAMMING
900
[ "math" ]
null
null
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow...
The only line of input contains integers *n* and *k* (1<=≀<=*k*<=≀<=*n*<=≀<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Print the number that will stand at the position number *k* after Volodya's manipulations.
[ "10 3\n", "7 7\n" ]
[ "5", "6" ]
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
500
[ { "input": "10 3", "output": "5" }, { "input": "7 7", "output": "6" }, { "input": "7 1", "output": "1" }, { "input": "7 2", "output": "3" }, { "input": "8 5", "output": "2" }, { "input": "8 3", "output": "5" }, { "input": "8 4", "output...
1,696,529,114
2,147,483,647
Python 3
OK
TESTS
25
92
0
n,k=map(int,input().split()) if n%2==0: if k<=(n/2): print(int(2*k-1)) elif k>(n/2): print(int(2*(k-n/2))) elif n%2!=0: if k<=int(n/2)+1: print(int(2*k-1)) elif k>int(n/2)+1: print(int(2*(k-int(n/2)-1)))
Title: Even Odds Time Limit: None seconds Memory Limit: None megabytes Problem Description: Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ...
```python n,k=map(int,input().split()) if n%2==0: if k<=(n/2): print(int(2*k-1)) elif k>(n/2): print(int(2*(k-n/2))) elif n%2!=0: if k<=int(n/2)+1: print(int(2*k-1)) elif k>int(n/2)+1: print(int(2*(k-int(n/2)-1))) ```
3
858
C
Did you mean...
PROGRAMMING
1,500
[ "dp", "greedy", "implementation" ]
null
null
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them. Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are thr...
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Print the given word without any changes if there are no typos. If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
[ "hellno\n", "abacaba\n", "asdfasdf\n" ]
[ "hell no \n", "abacaba \n", "asd fasd f \n" ]
none
1,500
[ { "input": "hellno", "output": "hell no " }, { "input": "abacaba", "output": "abacaba " }, { "input": "asdfasdf", "output": "asd fasd f " }, { "input": "ooo", "output": "ooo " }, { "input": "moyaoborona", "output": "moyaoborona " }, { "input": "jxegxxx...
1,505,656,105
2,605
PyPy 3
OK
TESTS
108
233
30,003,200
a = input() gl = set(['a', 'e', 'i', 'o', 'u']) cn = [0] * (200 + 1) ans = [] for i in range(len(a)): if a[i] in gl: for i1 in range(ord('a'), ord('z') + 1): cn[i1] = 0 continue cn[ord(a[i])] += 1 st = set() cnt = 0 for j in range(ord('a'), ord('z') + 1): ...
Title: Did you mean... Time Limit: None seconds Memory Limit: None megabytes Problem Description: Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them. Beroffice works only with small English letters (...
```python a = input() gl = set(['a', 'e', 'i', 'o', 'u']) cn = [0] * (200 + 1) ans = [] for i in range(len(a)): if a[i] in gl: for i1 in range(ord('a'), ord('z') + 1): cn[i1] = 0 continue cn[ord(a[i])] += 1 st = set() cnt = 0 for j in range(ord('a'), ord('z') ...
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,690,632,301
2,147,483,647
Python 3
OK
TESTS
30
46
0
import sys sys.setrecursionlimit(100000000) input=lambda:sys.stdin.readline().strip() write=lambda x:sys.stdout.write(str(x)) # from random import randint # from copy import deepcopy # from collections import deque # from heapq import heapify,heappush,heappop # from bisect import bisect_left,bisect,insort fr...
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 import sys sys.setrecursionlimit(100000000) input=lambda:sys.stdin.readline().strip() write=lambda x:sys.stdout.write(str(x)) # from random import randint # from copy import deepcopy # from collections import deque # from heapq import heapify,heappush,heappop # from bisect import bisect_left,bisect,...
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,658,539,508
2,147,483,647
Python 3
OK
TESTS
30
92
0
# -*- coding: utf-8 -*- """Python2 Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1Y_gvadcJ9SqrMgAYBKxt96WXg5bG2r59 """ x=str(input()) y=[] for i in x: y.append(i.isupper()) if y.count(True)>y.count(False): print(x.upper()) else: print(x.lower()...
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python # -*- coding: utf-8 -*- """Python2 Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1Y_gvadcJ9SqrMgAYBKxt96WXg5bG2r59 """ x=str(input()) y=[] for i in x: y.append(i.isupper()) if y.count(True)>y.count(False): print(x.upper()) else: print...
3.977
274
A
k-Multiple Free Set
PROGRAMMING
1,500
[ "binary search", "greedy", "sortings" ]
null
null
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=&lt;<=*y*) from the set, such that *y*<==<=*x*Β·*k*. You're given a set of *n* distinct positive integers. Your task is to find th...
The first line of the input contains two integers *n* and *k* (1<=≀<=*n*<=≀<=105,<=1<=≀<=*k*<=≀<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109). All the numbers in the lines are separated by single spaces.
On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}.
[ "6 2\n2 3 6 5 4 10\n" ]
[ "3\n" ]
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
500
[ { "input": "6 2\n2 3 6 5 4 10", "output": "3" }, { "input": "10 2\n1 2 3 4 5 6 7 8 9 10", "output": "6" }, { "input": "1 1\n1", "output": "1" }, { "input": "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 1...
1,628,181,553
2,147,483,647
PyPy 3
OK
TESTS
43
466
33,996,800
n, k = map(int, input().split()) a = list(sorted(map(int, input().split()), reverse=True)) s = set() for i in range(len(a)): if a[i] * k not in s: s.add(a[i]) print(len(s))
Title: k-Multiple Free Set Time Limit: None seconds Memory Limit: None megabytes Problem Description: A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=&lt;<=*y*) from the set, ...
```python n, k = map(int, input().split()) a = list(sorted(map(int, input().split()), reverse=True)) s = set() for i in range(len(a)): if a[i] * k not in s: s.add(a[i]) print(len(s)) ```
3
556
A
Case of the Zeros and Ones
PROGRAMMING
900
[ "greedy" ]
null
null
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an...
First line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=2Β·105), the length of the string that Andreid has. The second line contains the string of length *n* consisting only from zeros and ones.
Output the minimum length of the string that may remain after applying the described operations several times.
[ "4\n1100\n", "5\n01010\n", "8\n11101111\n" ]
[ "0\n", "1\n", "6\n" ]
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test it is possible to change the string like...
250
[ { "input": "4\n1100", "output": "0" }, { "input": "5\n01010", "output": "1" }, { "input": "8\n11101111", "output": "6" }, { "input": "1\n0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "2\n00", "output": "2" }, { "input"...
1,654,613,940
2,147,483,647
Python 3
OK
TESTS
49
78
204,800
n = int(input()) arr = input() a = b = 0 for e in arr: if e == '0': a += 1 else: b += 1 print(abs(a - b))
Title: Case of the Zeros and Ones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Cons...
```python n = int(input()) arr = input() a = b = 0 for e in arr: if e == '0': a += 1 else: b += 1 print(abs(a - b)) ```
3
462
B
Appleman and Card Game
PROGRAMMING
1,300
[ "greedy" ]
null
null
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to lette...
The first line contains two integers *n* and *k* (1<=≀<=*k*<=≀<=*n*<=≀<=105). The next line contains *n* uppercase letters without spaces β€” the *i*-th letter describes the *i*-th card of the Appleman.
Print a single integer – the answer to the problem.
[ "15 10\nDZFDFZDFDDDDDDF\n", "6 4\nYJSNPI\n" ]
[ "82\n", "4\n" ]
In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin.
1,000
[ { "input": "15 10\nDZFDFZDFDDDDDDF", "output": "82" }, { "input": "6 4\nYJSNPI", "output": "4" }, { "input": "5 3\nAOWBY", "output": "3" }, { "input": "1 1\nV", "output": "1" }, { "input": "2 1\nWT", "output": "1" }, { "input": "2 2\nBL", "output":...
1,554,991,553
2,147,483,647
Python 3
OK
TESTS
41
171
1,126,400
n, k = input().split(" ") n = int(n) #qtd de cards k = int(k) #qtd escolhida por Toast s = input() s = list(s) t = list(set(s)) s = sorted(s) t = sorted(t) f = [0]*len(t) i = 0 j = 0 while i < len(s): if s[i] == t[j]: f[j] += 1 i += 1 else: j += 1 f = sorted(f) cont = 0 soma = 0 i ...
Title: Appleman and Card Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally...
```python n, k = input().split(" ") n = int(n) #qtd de cards k = int(k) #qtd escolhida por Toast s = input() s = list(s) t = list(set(s)) s = sorted(s) t = sorted(t) f = [0]*len(t) i = 0 j = 0 while i < len(s): if s[i] == t[j]: f[j] += 1 i += 1 else: j += 1 f = sorted(f) cont = 0 s...
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≀<=*x**i*,<=*y**i*,<=*z**i*<=≀<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,686,397,310
2,147,483,647
Python 3
OK
TESTS
81
92
0
def is_equilibrium(n, forces): sum_x = 0 sum_y = 0 sum_z = 0 for force in forces: sum_x += force[0] sum_y += force[1] sum_z += force[2] if sum_x == 0 and sum_y == 0 and sum_z == 0: return "YES" else: return "NO" n = int(input()) forces = [] ...
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python def is_equilibrium(n, forces): sum_x = 0 sum_y = 0 sum_z = 0 for force in forces: sum_x += force[0] sum_y += force[1] sum_z += force[2] if sum_x == 0 and sum_y == 0 and sum_z == 0: return "YES" else: return "NO" n = int(input()) fo...
3.977
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100)Β β€” the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i...
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" ...
1,698,600,778
2,147,483,647
PyPy 3
OK
TESTS
50
77
0
n,m=map(int,input().strip().split()) f=0 for i in range(n): li=input().strip().split() if "C" in li or "M" in li or "Y" in li: f=1 if f==1: print("#Color") else: print("#Black&White")
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the...
```python n,m=map(int,input().strip().split()) f=0 for i in range(n): li=input().strip().split() if "C" in li or "M" in li or "Y" in li: f=1 if f==1: print("#Color") else: print("#Black&White") ```
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,647,546,042
2,147,483,647
Python 3
OK
TESTS
40
92
0
i = input() j = input() print('YES' if i[::-1] == j else 'NO')
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python i = input() j = input() print('YES' if i[::-1] == j else 'NO') ```
3.977
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportio...
The first input line contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≀<=*p**i*<=≀<=100) β€” the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ...
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39...
1,689,189,005
2,147,483,647
Python 3
OK
TESTS
31
92
0
tam = int(input()) jugo_perc = [int(x) for x in input().split(" ")] num1 = sum(jugo_perc) ans = num1 / tam print(format(ans, '.12f'))
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*...
```python tam = int(input()) jugo_perc = [int(x) for x in input().split(" ")] num1 = sum(jugo_perc) ans = num1 / tam print(format(ans, '.12f')) ```
3
855
A
Tom Riddle's Diary
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ...
First line of input contains an integer *n* (1<=≀<=*n*<=≀<=100)Β β€” the number of names in the list. Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower).
[ "6\ntom\nlucius\nginny\nharry\nginny\nharry\n", "3\na\na\na\n" ]
[ "NO\nNO\nNO\nNO\nYES\nYES\n", "NO\nYES\nYES\n" ]
In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* &lt; *i*, which means that answer for *i* = 5 is "YES".
500
[ { "input": "6\ntom\nlucius\nginny\nharry\nginny\nharry", "output": "NO\nNO\nNO\nNO\nYES\nYES" }, { "input": "3\na\na\na", "output": "NO\nYES\nYES" }, { "input": "1\nzn", "output": "NO" }, { "input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb...
1,673,517,237
2,147,483,647
Python 3
OK
TESTS
55
62
0
x=[] for i in range(int(input())): n=input() if n in x: print("YES") else: print("NO") x.append(n)
Title: Tom Riddle's Diary Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ...
```python x=[] for i in range(int(input())): n=input() if n in x: print("YES") else: print("NO") x.append(n) ```
3
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=Γ—<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=Γ—<=*a*. What is the least number of flagstones needed to pave the...
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≀<=<=*n*,<=*m*,<=*a*<=≀<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3"...
1,662,063,727
2,147,483,647
PyPy 3-64
OK
TESTS
20
62
0
n,m,a=map(int,input().split()) if n%a ==0: x=n//a else: x=n//a +1 if m%a ==0: y=m//a else: y=m//a+1 print(x*y)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=Γ—<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ...
```python n,m,a=map(int,input().split()) if n%a ==0: x=n//a else: x=n//a +1 if m%a ==0: y=m//a else: y=m//a+1 print(x*y) ```
3.969
485
A
Factory
PROGRAMMING
1,400
[ "implementation", "math", "matrices" ]
null
null
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no cu...
The first line contains two integers *a* and *m* (1<=≀<=*a*,<=*m*<=≀<=105).
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
[ "1 5\n", "3 6\n" ]
[ "No\n", "Yes\n" ]
none
1,000
[ { "input": "1 5", "output": "No" }, { "input": "3 6", "output": "Yes" }, { "input": "1 8", "output": "Yes" }, { "input": "2 3", "output": "No" }, { "input": "3 24", "output": "Yes" }, { "input": "1 1", "output": "Yes" }, { "input": "100000 ...
1,624,377,483
2,147,483,647
PyPy 3
OK
TESTS
23
124
0
a,b=map(int,input().split()) flag=0 for i in range(21): a=a*(2**i) if a%b==0: flag=1 break if flag==1: print("Yes") else: print("No")
Title: Factory Time Limit: None seconds Memory Limit: None megabytes Problem Description: One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the fac...
```python a,b=map(int,input().split()) flag=0 for i in range(21): a=a*(2**i) if a%b==0: flag=1 break if flag==1: print("Yes") else: print("No") ```
3
266
A
Stones on the Table
PROGRAMMING
800
[ "implementation" ]
null
null
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
The first line contains integer *n* (1<=≀<=*n*<=≀<=50) β€” the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red...
Print a single integer β€” the answer to the problem.
[ "3\nRRG\n", "5\nRRRRR\n", "4\nBRBG\n" ]
[ "1\n", "4\n", "0\n" ]
none
500
[ { "input": "3\nRRG", "output": "1" }, { "input": "5\nRRRRR", "output": "4" }, { "input": "4\nBRBG", "output": "0" }, { "input": "1\nB", "output": "0" }, { "input": "2\nBG", "output": "0" }, { "input": "3\nBGB", "output": "0" }, { "input": "...
1,698,424,528
2,147,483,647
Python 3
OK
TESTS
34
92
0
num = int(input()) string = input() x=0 for i in range(len(string)-1): if string[i]==string[i+1]: x+=1 else:pass print(x)
Title: Stones on the Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ...
```python num = int(input()) string = input() x=0 for i in range(len(string)-1): if string[i]==string[i+1]: x+=1 else:pass print(x) ```
3
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as Β«.Β», 1 as Β«-.Β» and 2 as Β«--Β». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "1000022...
1,619,105,087
2,147,483,647
Python 3
OK
TESTS
30
154
0
n = input() n = n.replace("--","2").replace("-.", "1").replace(".", "0") print(n)
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as Β«.Β», 1 as Β«-.Β» and 2 as Β«--Β». You are to decode the Borze code, i.e. to find out the ternary ...
```python n = input() n = n.replace("--","2").replace("-.", "1").replace(".", "0") print(n) ```
3.9615
299
A
Ksusha and Array
PROGRAMMING
1,000
[ "brute force", "number theory", "sortings" ]
null
null
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!
The first line contains integer *n* (1<=≀<=*n*<=≀<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109) β€” the array elements.
Print a single integer β€” the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1. If there are multiple answers, you are allowed to print any of them.
[ "3\n2 2 4\n", "5\n2 1 3 1 6\n", "3\n2 3 5\n" ]
[ "2\n", "1\n", "-1\n" ]
none
500
[ { "input": "3\n2 2 4", "output": "2" }, { "input": "5\n2 1 3 1 6", "output": "1" }, { "input": "3\n2 3 5", "output": "-1" }, { "input": "1\n331358794", "output": "331358794" }, { "input": "5\n506904227 214303304 136194869 838256937 183952885", "output": "-1" ...
1,614,307,554
2,147,483,647
PyPy 3
OK
TESTS
32
404
10,854,400
import math n=int(input()) l=list(map(int,input().split())) gc=l[0] for i in range(1,n): gc=math.gcd(gc,l[i]) print(gc if gc in l else "-1")
Title: Ksusha and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that ...
```python import math n=int(input()) l=list(map(int,input().split())) gc=l[0] for i in range(1,n): gc=math.gcd(gc,l[i]) print(gc if gc in l else "-1") ```
3
519
B
A and B and Compilation Errors
PROGRAMMING
1,100
[ "data structures", "implementation", "sortings" ]
null
null
A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix...
The first line of the input contains integer *n* (3<=≀<=*n*<=≀<=105) β€” the initial number of compilation errors. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109) β€” the errors the compiler displayed for the first time. The third line contains *n*<=-<=1 space-sepa...
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
[ "5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n", "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n" ]
[ "8\n123\n", "1\n3\n" ]
In the first test sample B first corrects the error number 8, then the error number 123. In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.
1,000
[ { "input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7", "output": "8\n123" }, { "input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5", "output": "1\n3" }, { "input": "3\n1 2 3\n3 2\n2", "output": "1\n3" }, { "input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6...
1,628,871,089
2,147,483,647
Python 3
OK
TESTS
33
233
22,016,000
n = int(input()) ar1 = list(map(int,input().split())) ar2 = list(map(int,input().split())) ar3 = list(map(int,input().split())) o1 = sum(ar1) o2 = sum(ar2) o3 = sum(ar3) print(o1 - o2) print(o2 - o3)
Title: A and B and Compilation Errors Time Limit: None seconds Memory Limit: None megabytes Problem Description: A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler disp...
```python n = int(input()) ar1 = list(map(int,input().split())) ar2 = list(map(int,input().split())) ar3 = list(map(int,input().split())) o1 = sum(ar1) o2 = sum(ar2) o3 = sum(ar3) print(o1 - o2) print(o2 - o3) ```
3
56
A
Bar
PROGRAMMING
1,000
[ "implementation" ]
A. Bar
2
256
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can chec...
The first line contains an integer *n* (1<=≀<=*n*<=≀<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input da...
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
[ "5\n18\nVODKA\nCOKE\n19\n17\n" ]
[ "2\n" ]
In the sample test the second and fifth clients should be checked.
500
[ { "input": "5\n18\nVODKA\nCOKE\n19\n17", "output": "2" }, { "input": "2\n2\nGIN", "output": "2" }, { "input": "3\nWHISKEY\n3\nGIN", "output": "3" }, { "input": "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWI...
1,618,045,235
2,147,483,647
PyPy 3
OK
TESTS
28
218
0
n=int(input()) res=0 alcohol =['ABSINTH', 'BEER','BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA','VODKA', 'WHISKEY', 'WINE'] for i in range(n): a=input() try: a=int(a) if(a<18): res+=1; except: for j in alcohol: if(a==j): res...
Title: Bar Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya h...
```python n=int(input()) res=0 alcohol =['ABSINTH', 'BEER','BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA','VODKA', 'WHISKEY', 'WINE'] for i in range(n): a=input() try: a=int(a) if(a<18): res+=1; except: for j in alcohol: if(a==j): ...
3.9455
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set...
The first line contains two space-separated integers *n* and *m* (1<=≀<=*m*<=≀<=*n*<=≀<=100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≀<=*a**i*<=≀<=1000) β€” prices of the TV sets.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "...
1,598,982,415
2,147,483,647
PyPy 3
OK
TESTS
25
280
0
n, m = map(int, input().split()) arr = sorted(list(map(int, input().split()))) print(abs(sum(arr[i] for i in range(m) if arr[i] <= 0)))
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can...
```python n, m = map(int, input().split()) arr = sorted(list(map(int, input().split()))) print(abs(sum(arr[i] for i in range(m) if arr[i] <= 0))) ```
3.93
75
A
Life Without Zeros
PROGRAMMING
1,000
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*...
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≀<=*a*,<=*b*<=≀<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }...
1,623,398,253
2,147,483,647
Python 3
OK
TESTS
43
124
0
a = int(input()) b = int(input()) aa = [] bb = [] cc = [] for i in str(a): if i != '0': aa.append(i) for i in str(b): if i != '0': bb.append(i) for i in str(a + b): if i != '0': cc.append(i) a = int(''.join(map(str, aa))) b = int(''.join(map(str, bb))) c = int(''.join(map(str, cc))) ...
Title: Life Without Zeros Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu...
```python a = int(input()) b = int(input()) aa = [] bb = [] cc = [] for i in str(a): if i != '0': aa.append(i) for i in str(b): if i != '0': bb.append(i) for i in str(a + b): if i != '0': cc.append(i) a = int(''.join(map(str, aa))) b = int(''.join(map(str, bb))) c = int(''.join(map(s...
3.969
703
A
Mishka and Game
PROGRAMMING
800
[ "implementation" ]
null
null
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds *n* is defined....
The first line of the input contains single integer *n* *n* (1<=≀<=*n*<=≀<=100)Β β€” the number of game rounds. The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≀<=*m**i*,<=<=*c**i*<=≀<=6)Β β€” values on dice upper face after Mishka's and Chris' throws in *i*-th ...
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
[ "3\n3 5\n2 1\n4 2\n", "2\n6 1\n1 6\n", "3\n1 5\n3 3\n2 2\n" ]
[ "Mishka", "Friendship is magic!^^", "Chris" ]
In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there...
500
[ { "input": "3\n3 5\n2 1\n4 2", "output": "Mishka" }, { "input": "2\n6 1\n1 6", "output": "Friendship is magic!^^" }, { "input": "3\n1 5\n3 3\n2 2", "output": "Chris" }, { "input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1", "output": "Mishka" }, { "input": "8\n2 4\n1 4\n1 ...
1,688,540,514
2,147,483,647
Python 3
OK
TESTS
69
46
0
t=int(input()) s1,s2=0,0 for i in range(t): mc=list(map(int,input().split())) if(mc[0]>mc[1]): s1+=1 elif(mc[0]<mc[1]): s2+=1 if(s1>s2): print("Mishka") elif(s1<s2): print("Chris") else: print("Friendship is magic!^^")
Title: Mishka and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st...
```python t=int(input()) s1,s2=0,0 for i in range(t): mc=list(map(int,input().split())) if(mc[0]>mc[1]): s1+=1 elif(mc[0]<mc[1]): s2+=1 if(s1>s2): print("Mishka") elif(s1<s2): print("Chris") else: print("Friendship is magic!^^") ```
3
608
A
Saitama Destroys Hotel
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special β€” it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor...
The first line of input contains two integers *n* and *s* (1<=≀<=*n*<=≀<=100, 1<=≀<=*s*<=≀<=1000)Β β€” the number of passengers and the number of the top floor respectively. The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≀<=*f**i*<=≀<=*s*, 1<=≀<=*t**i*<=≀<=1000)Β β€” the floor and the tim...
Print a single integerΒ β€” the minimum amount of time in seconds needed to bring all the passengers to floor 0.
[ "3 7\n2 1\n3 8\n5 2\n", "5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n" ]
[ "11\n", "79\n" ]
In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done: 1. Move to floor 5: takes 2 seconds. 2. Pick up passenger 3. 3. Move to floor 3: takes 2 seconds. 4. Wait for passenger 2 to arrive: takes 4 seconds. 5. Pick up passenger 2. 6. Go to floor 2: take...
500
[ { "input": "3 7\n2 1\n3 8\n5 2", "output": "11" }, { "input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64", "output": "79" }, { "input": "1 1000\n1000 1000", "output": "2000" }, { "input": "1 1\n1 1", "output": "2" }, { "input": "1 1000\n1 1", "output": "1000" }, ...
1,455,708,680
2,147,483,647
Python 3
OK
TESTS
39
77
0
n,s = map(int,input().split()) r = s for i in range(n): f,t = map(int,input().split()) r = max(r,t+f) print(r)
Title: Saitama Destroys Hotel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special β€” it starts on the top floor, can only mo...
```python n,s = map(int,input().split()) r = s for i in range(n): f,t = map(int,input().split()) r = max(r,t+f) print(r) ```
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line β€” the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,689,392,084
2,147,483,647
Python 3
OK
TESTS
102
46
0
for i, j in zip(input(), input()): print("0" if i == j else "1", end="")
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python for i, j in zip(input(), input()): print("0" if i == j else "1", end="") ```
3.9885
900
A
Find Extra One
PROGRAMMING
800
[ "geometry", "implementation" ]
null
null
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis.
The first line contains a single positive integer *n* (2<=≀<=*n*<=≀<=105). The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≀<=109, *x**i*<=β‰ <=0). No two points coincide.
Print "Yes" if there is such a point, "No" β€” otherwise. You can print every letter in any case (upper or lower).
[ "3\n1 1\n-1 -1\n2 -1\n", "4\n1 1\n2 2\n-1 1\n-2 2\n", "3\n1 2\n2 1\n4 60\n" ]
[ "Yes", "No", "Yes" ]
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
500
[ { "input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes" }, { "input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No" }, { "input": "3\n1 2\n2 1\n4 60", "output": "Yes" }, { "input": "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1", "output": "Yes" }, { "input": "2\n1...
1,567,708,592
2,147,483,647
PyPy 3
OK
TESTS
71
982
9,523,200
n = int(input()) up = 0 down = 0 for _ in range(n): x, y = map(int, input().split()) if x > 0: up += 1 else: down += 1 if up <= 1 or down <= 1: print("Yes") else: print("No")
Title: Find Extra One Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. Input Specification: The first li...
```python n = int(input()) up = 0 down = 0 for _ in range(n): x, y = map(int, input().split()) if x > 0: up += 1 else: down += 1 if up <= 1 or down <= 1: print("Yes") else: print("No") ```
3
224
A
Parallelepiped
PROGRAMMING
1,100
[ "brute force", "geometry", "math" ]
null
null
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
The first and the single line contains three space-separated integers β€” the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Print a single number β€” the sum of all edges of the parallelepiped.
[ "1 1 1\n", "4 6 6\n" ]
[ "12\n", "28\n" ]
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second oneΒ β€” 2 × 2 × 3.
500
[ { "input": "1 1 1", "output": "12" }, { "input": "4 6 6", "output": "28" }, { "input": "20 10 50", "output": "68" }, { "input": "9 4 36", "output": "56" }, { "input": "324 9 36", "output": "184" }, { "input": "1333 93 129", "output": "308" }, {...
1,595,501,568
2,147,483,647
PyPy 3
OK
TESTS
27
310
20,172,800
import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def rinput(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) a=list(map(int,input().split())) c1=a[2]*a[1]/a[0] c=c1**0.5...
Title: Parallelepiped Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. Input S...
```python import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def rinput(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) a=list(map(int,input().split())) c1=a[2]*a[1]/a[0] ...
3
337
A
Puzzles
PROGRAMMING
900
[ "greedy" ]
null
null
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od...
The first line contains space-separated integers *n* and *m* (2<=≀<=*n*<=≀<=*m*<=≀<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≀<=*f**i*<=≀<=1000) β€” the quantities of pieces in the puzzles sold in the shop.
Print a single integer β€” the least possible difference the teacher can obtain.
[ "4 6\n10 12 10 7 5 22\n" ]
[ "5\n" ]
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t...
500
[ { "input": "4 6\n10 12 10 7 5 22", "output": "5" }, { "input": "2 2\n4 4", "output": "0" }, { "input": "2 10\n4 5 6 7 8 9 10 11 12 12", "output": "0" }, { "input": "4 5\n818 136 713 59 946", "output": "759" }, { "input": "3 20\n446 852 783 313 549 965 40 88 86 617...
1,695,554,770
2,147,483,647
Python 3
OK
TESTS
18
92
0
n, m = map(int,input().split()) A = input().split() for i in range(m): A[i] = int(A[i]) A.sort() B = [] for i in range(m-n+1): B.append(A[i+n-1]-A[i]) print(min(B))
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a...
```python n, m = map(int,input().split()) A = input().split() for i in range(m): A[i] = int(A[i]) A.sort() B = [] for i in range(m-n+1): B.append(A[i+n-1]-A[i]) print(min(B)) ```
3
456
A
Laptops
PROGRAMMING
1,100
[ "sortings" ]
null
null
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ...
The first line contains an integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≀<=*a**i*,<=*b**i*<=≀<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the numb...
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
[ "2\n1 2\n2 1\n" ]
[ "Happy Alex\n" ]
none
500
[ { "input": "2\n1 2\n2 1", "output": "Happy Alex" }, { "input": "2\n1 1\n2 2", "output": "Poor Alex" }, { "input": "3\n2 2\n3 3\n1 1", "output": "Poor Alex" }, { "input": "3\n3 3\n1 2\n2 1", "output": "Happy Alex" }, { "input": "1\n1 1", "output": "Poor Alex" ...
1,695,734,332
2,147,483,647
Python 3
OK
TESTS
46
327
17,715,200
n=int(input()) a=[[int(x) for x in input().split()] for i in range(n)] flag=False a.sort(reverse=True) for i in range(1,n): if a[i][1]>a[0][1]: flag=True break else: a[0][1]=a[i][1] if flag: print("Happy Alex") else: print("Poor Alex")
Title: Laptops Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the...
```python n=int(input()) a=[[int(x) for x in input().split()] for i in range(n)] flag=False a.sort(reverse=True) for i in range(1,n): if a[i][1]>a[0][1]: flag=True break else: a[0][1]=a[i][1] if flag: print("Happy Alex") else: print("Poor Alex") ```
3
955
B
Not simply beatiful strings
PROGRAMMING
1,400
[ "implementation" ]
null
null
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of *a*-s and others β€” a ...
The only line contains *s* (1<=≀<=|*s*|<=≀<=105) consisting of lowercase latin letters.
Print Β«YesΒ» if the string can be split according to the criteria above or Β«NoΒ» otherwise. Each letter can be printed in arbitrary case.
[ "ababa\n", "zzcxx\n", "yeee\n" ]
[ "Yes\n", "Yes\n", "No\n" ]
In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable. There's no suitable partition in sample case three.
1,000
[ { "input": "ababa", "output": "Yes" }, { "input": "zzcxx", "output": "Yes" }, { "input": "yeee", "output": "No" }, { "input": "a", "output": "No" }, { "input": "bbab", "output": "No" }, { "input": "abcd", "output": "Yes" }, { "input": "abc"...
1,521,848,757
2,147,483,647
Python 3
OK
TESTS
56
109
7,270,400
s = {} i = input() for ch in i: if ch in s: s[ch] += 1 else: s[ch] = 1 # s = set(input()) if len(s) > 4: print('No') elif len(s) == 4: print('Yes') elif len(s) == 3: print('Yes' if len(i) > 3 else 'No') elif len(s) == 2: if all((x >= 2 for x in s.values())): ...
Title: Not simply beatiful strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, abab...
```python s = {} i = input() for ch in i: if ch in s: s[ch] += 1 else: s[ch] = 1 # s = set(input()) if len(s) > 4: print('No') elif len(s) == 4: print('Yes') elif len(s) == 3: print('Yes' if len(i) > 3 else 'No') elif len(s) == 2: if all((x >= 2 for x in s.valu...
3
6
A
Triangle
PROGRAMMING
900
[ "brute force", "geometry" ]
A. Triangle
2
64
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo...
The first line of the input contains four space-separated positive integer numbers not exceeding 100 β€” lengthes of the sticks.
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s...
[ "4 2 1 3\n", "7 2 2 4\n", "3 5 9 1\n" ]
[ "TRIANGLE\n", "SEGMENT\n", "IMPOSSIBLE\n" ]
none
0
[ { "input": "4 2 1 3", "output": "TRIANGLE" }, { "input": "7 2 2 4", "output": "SEGMENT" }, { "input": "3 5 9 1", "output": "IMPOSSIBLE" }, { "input": "3 1 5 1", "output": "IMPOSSIBLE" }, { "input": "10 10 10 10", "output": "TRIANGLE" }, { "input": "11 ...
1,628,819,443
2,147,483,647
Python 3
OK
TESTS
83
154
6,963,200
i = input().split(" ") a = int(i[0]) b = int(i[1]) c = int(i[2]) d = int(i[3]) l = [] l.append(a) l.append(b) l.append(c) l.append(d) l.sort() a = l[0] b = l[1] c = l[2] d = l[3] if a+b > c or b+c > d: print("TRIANGLE") elif a+b == c or b+c == d: print("SEGMENT") else: print...
Title: Triangle Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o...
```python i = input().split(" ") a = int(i[0]) b = int(i[1]) c = int(i[2]) d = int(i[3]) l = [] l.append(a) l.append(b) l.append(c) l.append(d) l.sort() a = l[0] b = l[1] c = l[2] d = l[3] if a+b > c or b+c > d: print("TRIANGLE") elif a+b == c or b+c == d: print("SEGMENT") else: ...
3.90962
659
A
Round House
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th...
The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≀<=*n*<=≀<=100,<=1<=≀<=*a*<=≀<=*n*,<=<=-<=100<=≀<=*b*<=≀<=100)Β β€” the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.
Print a single integer *k* (1<=≀<=*k*<=≀<=*n*)Β β€” the number of the entrance where Vasya will be at the end of his walk.
[ "6 2 -5\n", "5 1 3\n", "3 2 7\n" ]
[ "3\n", "4\n", "3\n" ]
The first example is illustrated by the picture in the statements.
500
[ { "input": "6 2 -5", "output": "3" }, { "input": "5 1 3", "output": "4" }, { "input": "3 2 7", "output": "3" }, { "input": "1 1 0", "output": "1" }, { "input": "1 1 -1", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "100 ...
1,556,444,150
2,147,483,647
Python 3
OK
TESTS
50
124
0
n,a,b = list(map(int,input().split())) ans = (n+a+b)%n; if ans == 0: print(n) else: print(ans)
Title: Round House Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in e...
```python n,a,b = list(map(int,input().split())) ans = (n+a+b)%n; if ans == 0: print(n) else: print(ans) ```
3
378
A
Playing with Dice
PROGRAMMING
800
[ "brute force" ]
null
null
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many w...
The single line contains two integers *a* and *b* (1<=≀<=*a*,<=*b*<=≀<=6)Β β€” the numbers written on the paper by the first and second player, correspondingly.
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
[ "2 5\n", "2 4\n" ]
[ "3 0 3\n", "2 1 3\n" ]
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
500
[ { "input": "2 5", "output": "3 0 3" }, { "input": "2 4", "output": "2 1 3" }, { "input": "5 3", "output": "2 1 3" }, { "input": "1 6", "output": "3 0 3" }, { "input": "5 1", "output": "3 1 2" }, { "input": "6 3", "output": "2 0 4" }, { "inp...
1,573,044,969
2,147,483,647
PyPy 3
OK
TESTS
38
140
0
from sys import stdin raw_input = stdin.readline().split() a = int(raw_input[0]) b = int(raw_input[1]) listA = [abs(a - i) for i in range(1, 7)] listB = [abs(b - i) for i in range(1, 7)] result = [0] * 3 for i in range(0, 6): if listA[i] < listB[i]: result[0] += 1 elif listA[i] == list...
Title: Playing with Dice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff...
```python from sys import stdin raw_input = stdin.readline().split() a = int(raw_input[0]) b = int(raw_input[1]) listA = [abs(a - i) for i in range(1, 7)] listB = [abs(b - i) for i in range(1, 7)] result = [0] * 3 for i in range(0, 6): if listA[i] < listB[i]: result[0] += 1 elif listA[...
3
110
A
Nearly Lucky Number
PROGRAMMING
800
[ "implementation" ]
A. Nearly Lucky Number
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
The only line contains an integer *n* (1<=≀<=*n*<=≀<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
500
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { ...
1,695,630,106
2,147,483,647
Python 3
OK
TESTS
34
92
0
number = input() lucky_number = number.count('4') + number.count('7') if lucky_number == 4 or lucky_number == 7: print("YES") else: print("NO")
Title: Nearly Lucky Number Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python number = input() lucky_number = number.count('4') + number.count('7') if lucky_number == 4 or lucky_number == 7: print("YES") else: print("NO") ```
3.977
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,664,162,396
2,147,483,647
Python 3
OK
TESTS
30
46
0
a ,b=input().split() a=int(a) b=int(b) max=max(a,b) min=min(a,b) mix,same=0,0 if a==b: mix=a same=0 else: mix=min same=(max-min)//2 print(mix ,same)
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=input().split() a=int(a) b=int(b) max=max(a,b) min=min(a,b) mix,same=0,0 if a==b: mix=a same=0 else: mix=min same=(max-min)//2 print(mix ,same) ```
3
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as Β«.Β», 1 as Β«-.Β» and 2 as Β«--Β». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "1000022...
1,593,183,018
2,147,483,647
Python 3
OK
TESTS
30
218
6,758,400
s=input() n=len(s) i=0 while(i<n): if(s[i]=='.'): print(0,end='') else: if(s[i+1]=='-'): print(2,end='') else: print(1,end='') i+=1 i+=1
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as Β«.Β», 1 as Β«-.Β» and 2 as Β«--Β». You are to decode the Borze code, i.e. to find out the ternary ...
```python s=input() n=len(s) i=0 while(i<n): if(s[i]=='.'): print(0,end='') else: if(s[i+1]=='-'): print(2,end='') else: print(1,end='') i+=1 i+=1 ```
3.932911
877
B
Nikita and string
PROGRAMMING
1,500
[ "brute force", "dp" ]
null
null
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b".
Print a single integerΒ β€” the maximum possible size of beautiful string Nikita can get.
[ "abba\n", "bab\n" ]
[ "4", "2" ]
It the first sample the string is already beautiful. In the second sample he needs to delete one of "b" to make it beautiful.
1,000
[ { "input": "abba", "output": "4" }, { "input": "bab", "output": "2" }, { "input": "bbabbbaabbbb", "output": "9" }, { "input": "bbabbbbbaaba", "output": "10" }, { "input": "bbabbbababaa", "output": "9" }, { "input": "aabbaababbab", "output": "8" }...
1,616,401,591
2,147,483,647
PyPy 3
OK
TESTS
46
124
1,638,400
s=input() a,ab,aba=0,0,0 for i in s: if i=='a': a+=1 aba=max(ab,aba)+1 else: ab=max(a,ab)+1 print(max(aba,ab,a))
Title: Nikita and string Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st ...
```python s=input() a,ab,aba=0,0,0 for i in s: if i=='a': a+=1 aba=max(ab,aba)+1 else: ab=max(a,ab)+1 print(max(aba,ab,a)) ```
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,667,991,796
2,147,483,647
Python 3
OK
TESTS
30
420
12,083,200
A=dict() n,m=map(int,input().split());Answer=[0]*(n+1);B=[] lis=list(map(int,input().split()));liss=set(lis);l=len(liss) for x in lis: A[x]=0 for i in range(n): A[lis[i]]+=1 Answer[0]=l for j in range(1,n+1): Answer[j]=Answer[j-1] A[lis[j-1]]-=1 if A[lis[j-1]]==0: Answer[j]-=1 f...
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 A=dict() n,m=map(int,input().split());Answer=[0]*(n+1);B=[] lis=list(map(int,input().split()));liss=set(lis);l=len(liss) for x in lis: A[x]=0 for i in range(n): A[lis[i]]+=1 Answer[0]=l for j in range(1,n+1): Answer[j]=Answer[j-1] A[lis[j-1]]-=1 if A[lis[j-1]]==0: Answe...
3
282
A
Bit++
PROGRAMMING
800
[ "implementation" ]
null
null
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=150) β€” the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter Β«XΒ»). Thus, there are no empty statements. The operation and th...
Print a single integer β€” the final value of *x*.
[ "1\n++X\n", "2\nX++\n--X\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "1\n++X", "output": "1" }, { "input": "2\nX++\n--X", "output": "0" }, { "input": "3\n++X\n++X\n++X", "output": "3" }, { "input": "2\n--X\n--X", "output": "-2" }, { "input": "5\n++X\n--X\n++X\n--X\n--X", "output": "-1" }, { "input": "28\nX--\...
1,696,961,543
2,147,483,647
Python 3
OK
TESTS
36
31
0
n = int(input("")) count = 0 for i in range(n): s = input("") if s[1] == "+": count = count + 1 if s[1] == "-": count = count - 1 print(count)
Title: Bit++ Time Limit: None seconds Memory Limit: None megabytes Problem Description: The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ incre...
```python n = int(input("")) count = 0 for i in range(n): s = input("") if s[1] == "+": count = count + 1 if s[1] == "-": count = count - 1 print(count) ```
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,695,563,947
2,147,483,647
Python 3
OK
TESTS
40
46
0
#23n2300011853 zhuangchuyue ccme targ="hello" k=0 flag=1 s=input() for i in range(len(s)): if(s[i]==targ[k]): k+=1 if(k==5): print("YES") flag=0 break if(flag): print("NO")
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 #23n2300011853 zhuangchuyue ccme targ="hello" k=0 flag=1 s=input() for i in range(len(s)): if(s[i]==targ[k]): k+=1 if(k==5): print("YES") flag=0 break if(flag): print("NO") ```
3.977
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100)Β β€” the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i...
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" ...
1,658,911,060
2,147,483,647
Python 3
OK
TESTS
50
46
0
n, m = map(int, input().split()) flag = False for _ in range(n): colors = set(input().split()) for color in colors: if 'W' != color and 'B' != color and 'G' != color: flag = True break if flag: break if ...
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the...
```python n, m = map(int, input().split()) flag = False for _ in range(n): colors = set(input().split()) for color in colors: if 'W' != color and 'B' != color and 'G' != color: flag = True break if flag: break ...
3
926
B
Add Points
PROGRAMMING
1,800
[]
null
null
There are *n* points on a straight line, and the *i*-th point among them is located at *x**i*. All these coordinates are distinct. Determine the number *m* β€” the smallest number of points you should add on the line to make the distances between all neighboring points equal.
The first line contains a single integer *n* (3<=≀<=*n*<=≀<=100<=000) β€” the number of points. The second line contains a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≀<=*x**i*<=≀<=109) β€” the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Print a single integer *m* β€” the smallest number of points you should add on the line to make the distances between all neighboring points equal.
[ "3\n-5 10 5\n", "6\n100 200 400 300 600 500\n", "4\n10 9 0 -1\n" ]
[ "1\n", "0\n", "8\n" ]
In the first example you can add one point with coordinate 0. In the second example the distances between all neighboring points are already equal, so you shouldn't add anything.
0
[ { "input": "3\n-5 10 5", "output": "1" }, { "input": "6\n100 200 400 300 600 500", "output": "0" }, { "input": "4\n10 9 0 -1", "output": "8" }, { "input": "3\n1 4 7", "output": "0" }, { "input": "3\n1 4 6", "output": "3" }, { "input": "3\n1 2 6", "...
1,521,304,079
3,179
Python 3
OK
TESTS
134
311
15,667,200
def nod(a, b): while a!=0 and b!=0: if a > b: a = a % b else: b = b % a return (a+b) n = int(input()) a = list(map(int, input().split())) a.sort() d = nod(a[1] - a[0], a[2] - a[1]) for i in range(2, n - 1): d = nod(a[i + 1] - a[i], d) count = 0 for i in ...
Title: Add Points Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* points on a straight line, and the *i*-th point among them is located at *x**i*. All these coordinates are distinct. Determine the number *m* β€” the smallest number of points you should add on the line to make ...
```python def nod(a, b): while a!=0 and b!=0: if a > b: a = a % b else: b = b % a return (a+b) n = int(input()) a = list(map(int, input().split())) a.sort() d = nod(a[1] - a[0], a[2] - a[1]) for i in range(2, n - 1): d = nod(a[i + 1] - a[i], d) count = 0 ...
3
334
A
Candy Bags
PROGRAMMING
1,000
[ "implementation" ]
null
null
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies. Help him give *n* bags of candies to each b...
The single line contains a single integer *n* (*n* is even, 2<=≀<=*n*<=≀<=100) β€” the number of Gerald's brothers.
Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers β€” the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ...
[ "2\n" ]
[ "1 4\n2 3\n" ]
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
500
[ { "input": "2", "output": "1 4\n2 3" }, { "input": "4", "output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9" }, { "input": "6", "output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19" }, { "input": "8", "output"...
1,524,842,752
2,147,483,647
Python 3
OK
TESTS
21
216
7,270,400
n = int(input()) x=1 for i in range(n): for j in range(n//2): print(x, n*n-x+1,end=' ') x+=1 print()
Title: Candy Bags Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ...
```python n = int(input()) x=1 for i in range(n): for j in range(n//2): print(x, n*n-x+1,end=' ') x+=1 print() ```
3
378
A
Playing with Dice
PROGRAMMING
800
[ "brute force" ]
null
null
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many w...
The single line contains two integers *a* and *b* (1<=≀<=*a*,<=*b*<=≀<=6)Β β€” the numbers written on the paper by the first and second player, correspondingly.
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
[ "2 5\n", "2 4\n" ]
[ "3 0 3\n", "2 1 3\n" ]
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
500
[ { "input": "2 5", "output": "3 0 3" }, { "input": "2 4", "output": "2 1 3" }, { "input": "5 3", "output": "2 1 3" }, { "input": "1 6", "output": "3 0 3" }, { "input": "5 1", "output": "3 1 2" }, { "input": "6 3", "output": "2 0 4" }, { "inp...
1,620,063,900
2,147,483,647
PyPy 3
OK
TESTS
38
93
0
a,b=map(int,input().split()) l=[(i+1) for i in range(6)] u=[] v=[] for i in range(len(l)): u.append(abs(l[i]-a)) v.append(abs(l[i]-b)) r1=0 r2=0 r3=0 for i in range(len(u)): if(u[i]>v[i]): r1=r1+1 elif(u[i]<v[i]): r2=r2+1 else: r3=r3+1 print(r2,r3,r1)
Title: Playing with Dice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff...
```python a,b=map(int,input().split()) l=[(i+1) for i in range(6)] u=[] v=[] for i in range(len(l)): u.append(abs(l[i]-a)) v.append(abs(l[i]-b)) r1=0 r2=0 r3=0 for i in range(len(u)): if(u[i]>v[i]): r1=r1+1 elif(u[i]<v[i]): r2=r2+1 else: r3=r3+1 print(r2,r3,r...
3
887
C
Solution for Cube
PROGRAMMING
1,500
[ "brute force", "implementation" ]
null
null
During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2. It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation...
In first line given a sequence of 24 integers *a**i* (1<=≀<=*a**i*<=≀<=6), where *a**i* denotes color of *i*-th square. There are exactly 4 occurrences of all colors in this sequence.
Print Β«YESΒ» (without quotes) if it's possible to solve cube using one rotation and Β«NOΒ» (without quotes) otherwise.
[ "2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4\n", "5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3\n" ]
[ "NO", "YES" ]
In first test case cube looks like this: In second test case cube looks like this: It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.
1,500
[ { "input": "2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4", "output": "NO" }, { "input": "5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3", "output": "YES" }, { "input": "2 6 3 3 5 5 2 6 1 1 6 4 4 4 2 4 6 5 3 1 2 5 3 1", "output": "NO" }, { "input": "3 4 2 3 5 5 6 6 4 5 4 6...
1,644,703,503
2,147,483,647
PyPy 3-64
OK
TESTS
48
78
512,000
def check(a): if all([a[i:i + 4].count(a[i]) == 4 for i in range(0, 24, 4)]): exit(print('YES')) a = [int(x) for x in input().split()] rot = [[1, 3, 5, 7, 9, 11, 24, 22], [2, 4, 6, 8, 10, 12, 23, 21], [13, 14, 5, 6, 17, 18, 21, 22], [15, 16, 7, 8, 19, 20, 23, 24], [1, 2, 18, 20, 12, 11, 15, ...
Title: Solution for Cube Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2. It's too hard to learn to solve Rubik's cube instantly,...
```python def check(a): if all([a[i:i + 4].count(a[i]) == 4 for i in range(0, 24, 4)]): exit(print('YES')) a = [int(x) for x in input().split()] rot = [[1, 3, 5, 7, 9, 11, 24, 22], [2, 4, 6, 8, 10, 12, 23, 21], [13, 14, 5, 6, 17, 18, 21, 22], [15, 16, 7, 8, 19, 20, 23, 24], [1, 2, 18, 20, 12...
3
567
A
Lineland Mail
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* β€” a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c...
The first line of the input contains integer *n* (2<=≀<=*n*<=≀<=105) β€” the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≀<=*x**i*<=≀<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo...
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
[ "4\n-5 -2 2 7\n", "2\n-1 1\n" ]
[ "3 12\n3 9\n4 7\n5 12\n", "2 2\n2 2\n" ]
none
500
[ { "input": "4\n-5 -2 2 7", "output": "3 12\n3 9\n4 7\n5 12" }, { "input": "2\n-1 1", "output": "2 2\n2 2" }, { "input": "3\n-1 0 1", "output": "1 2\n1 1\n1 2" }, { "input": "4\n-1 0 1 3", "output": "1 4\n1 3\n1 2\n2 4" }, { "input": "3\n-1000000000 0 1000000000", ...
1,650,245,959
2,147,483,647
Python 3
OK
TESTS
54
499
10,854,400
n = int(input()) Xs = list(map(int, input().split())) # will contains (min, max) out = [] for i in range(n): current_city = Xs[i] max_ = max(abs(current_city-Xs[0]), abs(current_city-Xs[-1])) if i == 0: min_ = abs(current_city-Xs[1]) elif i == n-1: min_ = abs(current_city-Xs[...
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()) Xs = list(map(int, input().split())) # will contains (min, max) out = [] for i in range(n): current_city = Xs[i] max_ = max(abs(current_city-Xs[0]), abs(current_city-Xs[-1])) if i == 0: min_ = abs(current_city-Xs[1]) elif i == n-1: min_ = abs(curren...
3
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,653,206,512
2,147,483,647
PyPy 3-64
OK
TESTS
62
77
2,662,400
n, m = map(int, input().split()) c = [0]*n for i in range(m): l = list(map(int, input().split())) c[(l.index(max(l)))] += 1 print(c.index(max(c)) + 1)
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 n, m = map(int, input().split()) c = [0]*n for i in range(m): l = list(map(int, input().split())) c[(l.index(max(l)))] += 1 print(c.index(max(c)) + 1) ```
3
267
A
Subtractions
PROGRAMMING
900
[ "math", "number theory" ]
null
null
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some num...
The first line contains the number of pairs *n* (1<=<=≀<=<=*n*<=<=≀<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≀<=<=*a**i*,<=<=*b**i*<=<=≀<=<=109).
Print the sought number of operations for each pair on a single line.
[ "2\n4 17\n7 987654321\n" ]
[ "8\n141093479\n" ]
none
500
[ { "input": "2\n4 17\n7 987654321", "output": "8\n141093479" }, { "input": "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321", "output": "141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479...
1,647,258,190
2,147,483,647
PyPy 3-64
OK
TESTS
35
93
3,788,800
import sys def file_io(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') def RL(): return [int(x) for x in sys.stdin.readline().split()] def RI(): return int(sys.stdin.readline()) def RS(): return sys.stdin.readline().strip() def print(*s, end='\n'): ...
Title: Subtractions Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one o...
```python import sys def file_io(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') def RL(): return [int(x) for x in sys.stdin.readline().split()] def RI(): return int(sys.stdin.readline()) def RS(): return sys.stdin.readline().strip() def print(*s, end='...
3
977
A
Wrong Subtraction
PROGRAMMING
800
[ "implementation" ]
null
null
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,...
The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) β€” the number from which Tanya will subtract and the number of subtractions correspondingly.
Print one integer number β€” the result of the decreasing $n$ by one $k$ times. It is guaranteed that the result will be positive integer number.
[ "512 4\n", "1000000000 9\n" ]
[ "50\n", "1\n" ]
The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$.
0
[ { "input": "512 4", "output": "50" }, { "input": "1000000000 9", "output": "1" }, { "input": "131203 11", "output": "12" }, { "input": "999999999 50", "output": "9999" }, { "input": "999999999 49", "output": "99990" }, { "input": "131203 9", "outpu...
1,696,888,583
2,147,483,647
Python 3
OK
TESTS
11
31
0
input = input() input = [int(input.split(' ')[0]), int(input.split(' ')[1])] numb = input[0] for i in range(input[1]): zero = numb % 10 if zero == 0: numb = numb/10 else: numb = numb-1 print(int(numb))
Title: Wrong Subtraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit ...
```python input = input() input = [int(input.split(' ')[0]), int(input.split(' ')[1])] numb = input[0] for i in range(input[1]): zero = numb % 10 if zero == 0: numb = numb/10 else: numb = numb-1 print(int(numb)) ```
3
644
A
Parliament of Berland
PROGRAMMING
1,000
[ "*special", "constructive algorithms" ]
null
null
There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans. New parliament assembly hall is a rectangle consisting of *a*<=Γ—<=*b* chairsΒ β€” *a* rows of *b* chair...
The first line of the input contains three integers *n*, *a* and *b* (1<=≀<=*n*<=≀<=10<=000, 1<=≀<=*a*,<=*b*<=≀<=100)Β β€” the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.
If there is no way to assigns seats to parliamentarians in a proper way print -1. Otherwise print the solution in *a* lines, each containing *b* integers. The *j*-th integer of the *i*-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multi...
[ "3 2 2\n", "8 4 3\n", "10 2 2\n" ]
[ "0 3\n1 2\n", "7 8 3\n0 1 4\n6 0 5\n0 2 0\n", "-1\n" ]
In the first sample there are many other possible solutions. For example, and The following assignment is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.
500
[ { "input": "3 2 2", "output": "1 2 \n0 3 " }, { "input": "8 4 3", "output": "1 2 3 \n4 5 6 \n7 8 0 \n0 0 0 " }, { "input": "10 2 2", "output": "-1" }, { "input": "1 1 1", "output": "1 " }, { "input": "8 3 3", "output": "1 2 3 \n4 5 6 \n7 8 0 " }, { "in...
1,627,281,110
2,147,483,647
Python 3
OK
TESTS
85
93
7,270,400
n, a, b = map(int, input().split()) if n > a * b: print(-1) else: c = [[0 for j in range(b)] for i in range(a)] p = 1 i = 0 j = 0 while p <= n: if i % 2 == 0: for j in range(b): if p > n: break c[i][j] = p ...
Title: Parliament of Berland Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republi...
```python n, a, b = map(int, input().split()) if n > a * b: print(-1) else: c = [[0 for j in range(b)] for i in range(a)] p = 1 i = 0 j = 0 while p <= n: if i % 2 == 0: for j in range(b): if p > n: break c[i][j]...
3
540
A
Combination Lock
PROGRAMMING
800
[ "implementation" ]
null
null
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=1000)Β β€” the number of disks on the combination lock. The second line contains a string of *n* digitsΒ β€” the original state of the disks. The third line contains a string of *n* digitsΒ β€” Scrooge McDuck's combination that opens the lock.
Print a single integerΒ β€” the minimum number of moves Scrooge McDuck needs to open the lock.
[ "5\n82195\n64723\n" ]
[ "13\n" ]
In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32...
500
[ { "input": "5\n82195\n64723", "output": "13" }, { "input": "12\n102021090898\n010212908089", "output": "16" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "10\n0728592530\n1362615763", "output": "27" }, { ...
1,628,211,717
2,147,483,647
Python 3
OK
TESTS
43
77
6,758,400
n,a,b,num = int(input()),input().strip(),input().strip(),0 for i in range(n): q = abs(int(a[i]) - int(b[i])) num += 10 - q if q > 5 else q print(num)
Title: Combination Lock Time Limit: None seconds Memory Limit: None megabytes Problem Description: Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is ...
```python n,a,b,num = int(input()),input().strip(),input().strip(),0 for i in range(n): q = abs(int(a[i]) - int(b[i])) num += 10 - q if q > 5 else q print(num) ```
3
35
A
Shell Game
PROGRAMMING
1,000
[ "implementation" ]
A. Shell Game
2
64
Today the Β«ZΒ» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so ...
The first input line contains an integer from 1 to 3 β€” index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 β€” indexes of the cups which the performer shuffled this time. The cups are numbered...
In the first line output an integer from 1 to 3 β€” index of the cup which will have the ball after all the shuffles.
[ "1\n1 2\n2 1\n2 1\n", "1\n2 1\n3 1\n1 3\n" ]
[ "2\n", "2\n" ]
none
500
[ { "input": "1\n1 2\n2 1\n2 1", "output": "2" }, { "input": "1\n2 1\n3 1\n1 3", "output": "2" }, { "input": "3\n3 1\n2 1\n1 2", "output": "1" }, { "input": "1\n1 3\n1 2\n2 3", "output": "2" }, { "input": "3\n3 2\n3 1\n3 1", "output": "2" }, { "input": "...
1,560,509,435
2,147,483,647
Python 3
OK
TESTS
20
218
0
with open('input.txt', 'r') as fr: result = int(fr.readline()) for i in range(3): a,b = [int(x) for x in fr.readline().split()] if a == result: result = b elif b == result: result = a with open('output.txt', 'w') as fw: fw.write(str(result))
Title: Shell Game Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Today the Β«ZΒ» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly put...
```python with open('input.txt', 'r') as fr: result = int(fr.readline()) for i in range(3): a,b = [int(x) for x in fr.readline().split()] if a == result: result = b elif b == result: result = a with open('output.txt', 'w') as fw: fw.write(str(result...
3.9455
793
A
Oleg and shares
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. ...
The first line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=105,<=1<=≀<=*k*<=≀<=109)Β β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109)Β β€” the initial prices.
Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible.
[ "3 3\n12 9 15\n", "2 2\n10 9\n", "4 1\n1 1000000000 1000000000 1000000000\n" ]
[ "3", "-1", "2999999997" ]
Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. Ther...
500
[ { "input": "3 3\n12 9 15", "output": "3" }, { "input": "2 2\n10 9", "output": "-1" }, { "input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997" }, { "input": "1 11\n123", "output": "0" }, { "input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50...
1,493,045,431
2,147,483,647
Python 3
OK
TESTS
88
170
14,336,000
n, k = map(int, input().split()) a = [int(elem) for elem in input().split()] mi = min(a) cou = 0 b = [] st = 0 for i in a: if st != 0: continue if i != mi: if (i - mi) % k == 0: cou += (i - mi) // k else: st = 1 cou = -1 print(cou)
Title: Oleg and shares Time Limit: None seconds Memory Limit: None megabytes Problem Description: Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly o...
```python n, k = map(int, input().split()) a = [int(elem) for elem in input().split()] mi = min(a) cou = 0 b = [] st = 0 for i in a: if st != 0: continue if i != mi: if (i - mi) % k == 0: cou += (i - mi) // k else: st = 1 cou = -1 prin...
3
673
A
Bear and Game
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=......
The first line of the input contains one integer *n* (1<=≀<=*n*<=≀<=90)Β β€” the number of interesting minutes. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≀<=*t*1<=&lt;<=*t*2<=&lt;<=... *t**n*<=≀<=90), given in the increasing order.
Print the number of minutes Limak will watch the game.
[ "3\n7 20 88\n", "9\n16 20 30 40 50 60 70 80 90\n", "9\n15 20 30 40 50 60 70 80 90\n" ]
[ "35\n", "15\n", "90\n" ]
In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the w...
500
[ { "input": "3\n7 20 88", "output": "35" }, { "input": "9\n16 20 30 40 50 60 70 80 90", "output": "15" }, { "input": "9\n15 20 30 40 50 60 70 80 90", "output": "90" }, { "input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88", ...
1,698,484,971
2,147,483,647
Python 3
OK
TESTS
34
46
0
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) if a[0] > 15: print(15) exit() for i in range(n - 1): if a[i] + 15 < a[i + 1]: print(a[i] + 15) exit() print(min(a[-1] + 15, 90))
Title: Bear and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Lim...
```python import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) if a[0] > 15: print(15) exit() for i in range(n - 1): if a[i] + 15 < a[i + 1]: print(a[i] + 15) exit() print(min(a[-1] + 15, 90)) ```
3
483
A
Counterexample
PROGRAMMING
1,100
[ "brute force", "implementation", "math", "number theory" ]
null
null
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i...
The single line contains two positive space-separated integers *l*, *r* (1<=≀<=*l*<=≀<=*r*<=≀<=1018; *r*<=-<=*l*<=≀<=50).
Print three positive space-separated integers *a*, *b*, *c*Β β€” three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order. If the counterexample does not exist, print the single number -1.
[ "2 4\n", "10 11\n", "900000000000000009 900000000000000029\n" ]
[ "2 3 4\n", "-1\n", "900000000000000009 900000000000000010 900000000000000021\n" ]
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
500
[ { "input": "2 4", "output": "2 3 4" }, { "input": "10 11", "output": "-1" }, { "input": "900000000000000009 900000000000000029", "output": "900000000000000009 900000000000000010 900000000000000021" }, { "input": "640097987171091791 640097987171091835", "output": "64009798...
1,610,023,042
2,147,483,647
Python 3
OK
TESTS
42
124
0
l,r = [int(x) for x in input().split()] if l==r or l+1==r: print(-1) elif l%2==0: print(l,l+1,l+2) elif l%2!=0 and r-l+1>3: print(l+1,l+2,l+3) else: print(-1)
Title: Counterexample Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one. Your friend often comes up with different st...
```python l,r = [int(x) for x in input().split()] if l==r or l+1==r: print(-1) elif l%2==0: print(l,l+1,l+2) elif l%2!=0 and r-l+1>3: print(l+1,l+2,l+3) else: print(-1) ```
3
678
B
The Same Calendar
PROGRAMMING
1,600
[ "implementation" ]
null
null
The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after *y* when the calendar will be exactly the same. Help ...
The only line contains integer *y* (1000<=≀<=*y*<=&lt;<=100'000) β€” the year of the calendar.
Print the only integer *y*' β€” the next year after *y* when the calendar will be the same. Note that you should find the first year after *y* with the same calendar.
[ "2016\n", "2000\n", "50501\n" ]
[ "2044\n", "2028\n", "50507\n" ]
Today is Monday, the 13th of June, 2016.
0
[ { "input": "2016", "output": "2044" }, { "input": "2000", "output": "2028" }, { "input": "50501", "output": "50507" }, { "input": "1000", "output": "1006" }, { "input": "1900", "output": "1906" }, { "input": "1899", "output": "1905" }, { "i...
1,531,656,615
2,147,483,647
Python 3
OK
TESTS
40
109
0
y = int(input()) y-=1 tot = 365*y + (y//4 - y//100 + y//400) rem = tot%7 pv = 0 if (y+1)%4 == 0 and ( (y+1)%100 != 0 or (y+1)%400 == 0): pv = 1 y+=1 for i in range(y, 1000000): if i%4 == 0 and (i%100 != 0 or i%400 == 0): tot += 366 else: tot += 365 cur = 0 if (i+1)%4 == 0 and ( (i+1)%100 != 0 o...
Title: The Same Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful t...
```python y = int(input()) y-=1 tot = 365*y + (y//4 - y//100 + y//400) rem = tot%7 pv = 0 if (y+1)%4 == 0 and ( (y+1)%100 != 0 or (y+1)%400 == 0): pv = 1 y+=1 for i in range(y, 1000000): if i%4 == 0 and (i%100 != 0 or i%400 == 0): tot += 366 else: tot += 365 cur = 0 if (i+1)%4 == 0 and ( (i+1)%...
3
287
A
IQ Test
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=Γ—<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the...
Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black.
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
[ "####\n.#..\n####\n....\n", "####\n....\n####\n....\n" ]
[ "YES\n", "NO\n" ]
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
500
[ { "input": "###.\n...#\n###.\n...#", "output": "NO" }, { "input": ".##.\n#..#\n.##.\n#..#", "output": "NO" }, { "input": ".#.#\n#.#.\n.#.#\n#.#.", "output": "NO" }, { "input": "##..\n..##\n##..\n..##", "output": "NO" }, { "input": "#.#.\n#.#.\n.#.#\n.#.#", "ou...
1,667,902,526
2,147,483,647
PyPy 3-64
OK
TESTS
30
46
0
p = [input() for i in range(4)] def check_arr(arr): for a in range(3): for b in range(3): s = 0 s += int(arr[a][b] == '.') + int(arr[a][b+1] == '.') + int(arr[a+1][b] == '.') + int(arr[a+1][b+1] == '.') if s != 2: return 'YES' return 'NO' pr...
Title: IQ Test Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=Γ—<=4 square painted on it. Some of the square's cells are painted black and o...
```python p = [input() for i in range(4)] def check_arr(arr): for a in range(3): for b in range(3): s = 0 s += int(arr[a][b] == '.') + int(arr[a][b+1] == '.') + int(arr[a+1][b] == '.') + int(arr[a+1][b+1] == '.') if s != 2: return 'YES' retur...
3
520
A
Pangram
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=100)Β β€” the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output "YES", if the string is a pangram and "NO" otherwise.
[ "12\ntoosmallword\n", "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "12\ntoosmallword", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog", "output": "YES" }, { "input": "1\na", "output": "NO" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "YES" }, { "input": "26\nABCDEFGHIJKLMNOPQRSTUVWXY...
1,696,402,277
2,147,483,647
Python 3
OK
TESTS
59
46
0
n=int(input()) n1=input() n1=n1.lower() l1=[] for i in range(97,123): l1.append(chr(i)) count=0 for i in l1: if i in n1: count+=1 if count==26: print("YES") else: print("NO")
Title: Pangram Time Limit: None seconds Memory Limit: None megabytes Problem Description: A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. ...
```python n=int(input()) n1=input() n1=n1.lower() l1=[] for i in range(97,123): l1.append(chr(i)) count=0 for i in l1: if i in n1: count+=1 if count==26: print("YES") else: print("NO") ```
3
595
A
Vitaly and Night
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a building of *n* floors and 2Β·*m* windows on each floor. On each floor there are *m* flats num...
The first line of the input contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100)Β β€” the number of floors in the house and the number of flats on each floor respectively. Next *n* lines describe the floors from top to bottom and contain 2Β·*m* characters each. If the *i*-th window of the given floor has lights on,...
Print a single integerΒ β€” the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
[ "2 2\n0 0 0 1\n1 0 1 1\n", "1 3\n1 1 0 1 0 0\n" ]
[ "3\n", "2\n" ]
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off. In the second test case the house has one floor and the first floor has three flats. The ligh...
500
[ { "input": "2 2\n0 0 0 1\n1 0 1 1", "output": "3" }, { "input": "1 3\n1 1 0 1 0 0", "output": "2" }, { "input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1", "output": "8" }, { "input": "1 5\n1 0 1 1 1 0 1 1 1 1", "output": "5" }, { "input": "1 100\n1 1 1 1 1 1 1 ...
1,587,198,430
2,147,483,647
Python 3
OK
TESTS
36
124
307,200
n, m = map(int, input().split()) l = [list(map(int, input().split())) for _ in range(n)] ans = 0 for i in range(n): for j in range(m): if 1 in l[i][2 * j :2 * (j + 1)]: ans += 1 print(ans)
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, m = map(int, input().split()) l = [list(map(int, input().split())) for _ in range(n)] ans = 0 for i in range(n): for j in range(m): if 1 in l[i][2 * j :2 * (j + 1)]: ans += 1 print(ans) ```
3
157
B
Trace
PROGRAMMING
1,000
[ "geometry", "sortings" ]
null
null
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,...
The first line contains the single integer *n* (1<=≀<=*n*<=≀<=100). The second line contains *n* space-separated integers *r**i* (1<=≀<=*r**i*<=≀<=1000) β€” the circles' radii. It is guaranteed that all circles are different.
Print the single real number β€” total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4.
[ "1\n1\n", "3\n1 4 2\n" ]
[ "3.1415926536\n", "40.8407044967\n" ]
In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π. In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon...
1,000
[ { "input": "1\n1", "output": "3.1415926536" }, { "input": "3\n1 4 2", "output": "40.8407044967" }, { "input": "4\n4 1 3 2", "output": "31.4159265359" }, { "input": "4\n100 10 2 1", "output": "31111.1920484997" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output"...
1,492,340,939
2,147,483,647
Python 3
OK
TESTS
44
124
5,529,600
'''input 1 1 ''' from math import pi n = int(input()) r = sorted(map(int, input().split())) a = 0 if n % 2 == 1: a += r.pop(0)**2 while r: x, y = r.pop(0), r.pop(0) a += (y - x)*(y + x) print(a*pi)
Title: Trace Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in...
```python '''input 1 1 ''' from math import pi n = int(input()) r = sorted(map(int, input().split())) a = 0 if n % 2 == 1: a += r.pop(0)**2 while r: x, y = r.pop(0), r.pop(0) a += (y - x)*(y + x) print(a*pi) ```
3
47
B
Coins
PROGRAMMING
1,200
[ "implementation" ]
B. Coins
2
256
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul...
The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters Β«AΒ», Β«BΒ» and Β«CΒ». Each result is a line that appears as (letter)(&gt; or &lt; sign)(letter). For example, if coin "A" proved lighter t...
It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters Β«AΒ», Β«BΒ» and Β«CΒ» which represent the coins in the increasing order of their weights.
[ "A&gt;B\nC&lt;B\nA&gt;C\n", "A&lt;B\nB&gt;C\nC&gt;A\n" ]
[ "CBA", "ACB" ]
none
1,000
[ { "input": "A>B\nC<B\nA>C", "output": "CBA" }, { "input": "A<B\nB>C\nC>A", "output": "ACB" }, { "input": "A<C\nB<A\nB>C", "output": "Impossible" }, { "input": "A<B\nA<C\nB>C", "output": "ACB" }, { "input": "B>A\nC<B\nC>A", "output": "ACB" }, { "input":...
1,553,598,347
2,147,483,647
Python 3
OK
TESTS
50
218
307,200
def add(left, right, word): if word[1] == ">": right[word[0]] += 1 left[word[2]] += 1 else: left[word[0]] += 1 right[word[2]] += 1 return left, right first = input() secon = input() third = input() left = {'A':0, 'B':0, 'C':0} right = {'A':0, 'B':0, 'C':0} left, right = ad...
Title: Coins Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ...
```python def add(left, right, word): if word[1] == ">": right[word[0]] += 1 left[word[2]] += 1 else: left[word[0]] += 1 right[word[2]] += 1 return left, right first = input() secon = input() third = input() left = {'A':0, 'B':0, 'C':0} right = {'A':0, 'B':0, 'C':0} left, ...
3.944928
897
A
Scarborough Fair
PROGRAMMING
800
[ "implementation" ]
null
null
Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Althou...
The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100). The second line contains a string *s* of length *n*, consisting of lowercase English letters. Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≀<=*l*<=≀<=*r*<=≀<=*n*, *c*1,<=*c*2 are lowercase English letters), ...
Output string *s* after performing *m* operations described above.
[ "3 1\nioi\n1 1 i n\n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n" ]
[ "noi", "gaaak" ]
For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak.
500
[ { "input": "3 1\nioi\n1 1 i n", "output": "noi" }, { "input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g", "output": "gaaak" }, { "input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n...
1,676,518,644
2,147,483,647
Python 3
OK
TESTS
47
46
0
# Rating: 800, Problem 897 A n, m = [int(i) for i in input().strip().split()] s = input().strip() data = [] for i in range(m): r, l, c1, c2 = input().strip().split() data.append([r,l,c1,c2]) array = [] for i in range(n): array.append(s[i]) for change in data: for j in range(int(change[0])-1, int(ch...
Title: Scarborough Fair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get ...
```python # Rating: 800, Problem 897 A n, m = [int(i) for i in input().strip().split()] s = input().strip() data = [] for i in range(m): r, l, c1, c2 = input().strip().split() data.append([r,l,c1,c2]) array = [] for i in range(n): array.append(s[i]) for change in data: for j in range(int(change[0])...
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line β€” the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,613,928,285
2,147,483,647
Python 3
OK
TESTS
102
62
0
n1 = list(input()) n2 = list(input()) ans =[] for i in range(len(n1)): if n1[i]==n2[i]: ans.append('0') else: ans.append('1') print(''.join(ans))
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 n1 = list(input()) n2 = list(input()) ans =[] for i in range(len(n1)): if n1[i]==n2[i]: ans.append('0') else: ans.append('1') print(''.join(ans)) ```
3.9845
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≀<=*x**i*,<=*y**i*,<=*z**i*<=≀<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,662,297,605
2,147,483,647
PyPy 3
OK
TESTS
81
218
409,600
# cook your dish here import io import os import sys import collections as clts import math import heapq MOD = 10**9 + 7 def gcd(x,y): if y == 0: return x else: return gcd(y,x%y) def lcm(x,y): return int(x/gcd(x,y)*y) FAST = False if FAST: INP = io.BytesIO(os.read(0,os.fstat(0...
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python # cook your dish here import io import os import sys import collections as clts import math import heapq MOD = 10**9 + 7 def gcd(x,y): if y == 0: return x else: return gcd(y,x%y) def lcm(x,y): return int(x/gcd(x,y)*y) FAST = False if FAST: INP = io.BytesIO(os.read(0,...
3.944737
979
B
Treasure Hunt
PROGRAMMING
1,800
[ "greedy" ]
null
null
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her. The three friends are very smart so they passed all the challenges very quickly and finally reached the destination...
The first line contains an integer $n$ ($0 \leq n \leq 10^{9}$)Β β€” the number of turns. Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $10^{5}$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the lengt...
Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".
[ "3\nKuroo\nShiro\nKatie\n", "7\ntreasurehunt\nthreefriends\nhiCodeforces\n", "1\nabcabc\ncbabac\nababca\n", "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE\n" ]
[ "Kuro\n", "Shiro\n", "Katie\n", "Draw\n" ]
In the first example, after $3$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $5$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $4$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Th...
1,000
[ { "input": "3\nKuroo\nShiro\nKatie", "output": "Kuro" }, { "input": "7\ntreasurehunt\nthreefriends\nhiCodeforces", "output": "Shiro" }, { "input": "1\nabcabc\ncbabac\nababca", "output": "Katie" }, { "input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE", "output": "Draw" }, {...
1,526,387,225
2,147,483,647
Python 3
OK
TESTS
184
280
8,499,200
n = int(input()) a = input() b = input() c = input() aa = 26*[0] ab = 26*[0] ac = 26*[0] ba = 26*[0] bb = 26*[0] bc = 26*[0] r = len(a) for i in range(r): if 'a'<=a[i]<='z': aa[ord(a[i])%97]+=1 else: ba[ord(a[i])%65]+=1 if 'a'<=b[i]<='z': ab[ord(b[i])%97]+=1 else: bb[ord(b[i])%65]+=1 ...
Title: Treasure Hunt Time Limit: None seconds Memory Limit: None megabytes Problem Description: After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her. The three friend...
```python n = int(input()) a = input() b = input() c = input() aa = 26*[0] ab = 26*[0] ac = 26*[0] ba = 26*[0] bb = 26*[0] bc = 26*[0] r = len(a) for i in range(r): if 'a'<=a[i]<='z': aa[ord(a[i])%97]+=1 else: ba[ord(a[i])%65]+=1 if 'a'<=b[i]<='z': ab[ord(b[i])%97]+=1 else: bb[ord(b[i])%6...
3
985
B
Switches and Lamps
PROGRAMMING
1,200
[ "implementation" ]
null
null
You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th switch turns on the *j*-th lamp and *a**i*,<=*j*<==<=0 if the *i*-th switch is not connected to the *j*...
The first line of the input contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=2000) β€” the number of the switches and the number of the lamps. The following *n* lines contain *m* characters each. The character *a**i*,<=*j* is equal to '1' if the *i*-th switch turns on the *j*-th lamp and '0' otherwise. It is guar...
Print "YES" if there is a switch that if you will ignore it and press all the other *n*<=-<=1 switches then all *m* lamps will be turned on. Print "NO" if there is no such switch.
[ "4 5\n10101\n01000\n00111\n10000\n", "4 5\n10100\n01000\n00110\n00101\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "4 5\n10101\n01000\n00111\n10000", "output": "YES" }, { "input": "4 5\n10100\n01000\n00110\n00101", "output": "NO" }, { "input": "1 5\n11111", "output": "NO" }, { "input": "10 1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n1", "output": "YES" }, { "input": "1 1\n1", ...
1,596,092,618
2,147,483,647
PyPy 3
OK
TESTS
67
1,294
29,900,800
switchCount,lampCount = tuple(map(int,input().split())) switches = [] for i in range(switchCount): switches.append(int(input(),2)) def canSwitchOnWithout(index): bitwiseOr = 0 for i in range(switchCount): if i !=index: bitwiseOr = bitwiseOr | switches[i] return bitwiseOr la...
Title: Switches and Lamps Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th...
```python switchCount,lampCount = tuple(map(int,input().split())) switches = [] for i in range(switchCount): switches.append(int(input(),2)) def canSwitchOnWithout(index): bitwiseOr = 0 for i in range(switchCount): if i !=index: bitwiseOr = bitwiseOr | switches[i] return bit...
3
523
C
Name Quest
PROGRAMMING
1,400
[ "*special", "greedy" ]
null
null
A Martian boy is named *s* β€” he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by removing zero or more letters (at that, the remaining letters remain in the same order), he gets hap...
The first line contains string *s*, consisting of lowercase English letters. The length of string *s* is from 1 to 1000 letters. The second line contains string *t*, that also consists of lowercase English letters. The length of string *t* is from 1 to 106 letters.
Print the sought number of ways to cut string *t* in two so that each part made *s* happy.
[ "aba\nbaobababbah\n", "mars\nsunvenusearthmarsjupitersaturnuranusneptune\n" ]
[ "2\n", "0\n" ]
none
1,500
[ { "input": "aba\nbaobababbah", "output": "2" }, { "input": "mars\nsunvenusearthmarsjupitersaturnuranusneptune", "output": "0" }, { "input": "rry\nsorrymercuryismissedabove", "output": "3" }, { "input": "a\naaaaaaaaaaaaaa", "output": "13" }, { "input": "abcaba\nabc...
1,626,222,124
2,147,483,647
PyPy 3
OK
TESTS
21
187
27,033,600
name = input() t = input() i = 0 j = 0 while i < len(name) and j < len(t): if name[i] == t[j]: i += 1 j += 1 leftIndex = j - 1 if j < len(t) else 0 i = len(name) - 1 j = len(t) - 1 while i >= 0 and j >= 0: if name[i] == t[j]: i -= 1 j -= 1 rightIndex = j + 1 if j >= 0 els...
Title: Name Quest Time Limit: None seconds Memory Limit: None megabytes Problem Description: A Martian boy is named *s* β€” he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by remo...
```python name = input() t = input() i = 0 j = 0 while i < len(name) and j < len(t): if name[i] == t[j]: i += 1 j += 1 leftIndex = j - 1 if j < len(t) else 0 i = len(name) - 1 j = len(t) - 1 while i >= 0 and j >= 0: if name[i] == t[j]: i -= 1 j -= 1 rightIndex = j + 1 if ...
3
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E...
The first line contains an integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of lines in the description. Then follow *n* lines β€” for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di...
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", ...
1,580,940,561
2,147,483,647
Python 3
OK
TESTS
34
218
307,200
if __name__=="__main__": x=int(input()) list1=[] temp=[] dic1={} for i in range(0,x): temp=input() if temp in dic1: dic1[temp]+=1 else: dic1[temp]=1 maxi=max(dic1.values()) for i in dic1: if dic1[i]==maxi: prin...
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process...
```python if __name__=="__main__": x=int(input()) list1=[] temp=[] dic1={} for i in range(0,x): temp=input() if temp in dic1: dic1[temp]+=1 else: dic1[temp]=1 maxi=max(dic1.values()) for i in dic1: if dic1[i]==maxi: ...
3.944928
961
B
Lecture Sleep
PROGRAMMING
1,200
[ "data structures", "dp", "implementation", "two pointers" ]
null
null
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute. Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during ...
The first line of the input contains two integer numbers *n* and *k* (1<=≀<=*k*<=≀<=*n*<=≀<=105) β€” the duration of the lecture in minutes and the number of minutes you can keep Mishka awake. The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≀<=*a**i*<=≀<=104) β€” the number of theore...
Print only one integer β€” the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
[ "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n" ]
[ "16\n" ]
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.
0
[ { "input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0", "output": "16" }, { "input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0", "output": "30000" }, { "input": "3 3\n10 10 10\n1 1 0", "output": "30" }, { "input": "1 1\n423\n0", "output": "423" }, { "input": "6 6\n1 3 5 2 5 4...
1,545,394,214
2,147,483,647
PyPy 3
OK
TESTS
37
202
12,083,200
n,k=map(int,input().split()) a=list(map(int,input().split())) t=list(map(int,input().split())) cnt=0 for i in range(n): if t[i]==1: cnt+=a[i] ans=0 for i in range(k): if t[i]==0: ans+=a[i] su=ans for i in range(1,n-k+1): ans=ans-(not t[i-1])*a[i-1]+(not t[i+k-1])*a[i+k-1] s...
Title: Lecture Sleep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute. Mishka is really interested in calculus, though it is so hard to stay awake for al...
```python n,k=map(int,input().split()) a=list(map(int,input().split())) t=list(map(int,input().split())) cnt=0 for i in range(n): if t[i]==1: cnt+=a[i] ans=0 for i in range(k): if t[i]==0: ans+=a[i] su=ans for i in range(1,n-k+1): ans=ans-(not t[i-1])*a[i-1]+(not t[i+k-1])*a[i+k...
3
841
A
Generous Kefa
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* β€” lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his...
The first line contains two integers *n* and *k* (1<=≀<=*n*,<=*k*<=≀<=100) β€” the number of baloons and friends. Next line contains string *s* β€” colors of baloons.
Answer to the task β€” Β«YESΒ» or Β«NOΒ» in a single line. You can choose the case (lower or upper) for each letter arbitrary.
[ "4 2\naabb\n", "6 3\naacaab\n" ]
[ "YES\n", "NO\n" ]
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second. In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is Β«NOΒ».
500
[ { "input": "4 2\naabb", "output": "YES" }, { "input": "6 3\naacaab", "output": "NO" }, { "input": "2 2\nlu", "output": "YES" }, { "input": "5 3\novvoo", "output": "YES" }, { "input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf", "output": "YES" }, { "...
1,619,153,692
2,147,483,647
PyPy 3
OK
TESTS
114
109
0
n, k = map(int, input().split()) has = dict() daf = list(input()) for i in range(n): if daf[i] in has.keys(): has[daf[i]] += 1 else: has[daf[i]] = 1 for x in has.values(): if x > k: print('NO') break else: print('YES')
Title: Generous Kefa Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* β€” lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same colo...
```python n, k = map(int, input().split()) has = dict() daf = list(input()) for i in range(n): if daf[i] in has.keys(): has[daf[i]] += 1 else: has[daf[i]] = 1 for x in has.values(): if x > k: print('NO') break else: print('YES') ```
3
378
A
Playing with Dice
PROGRAMMING
800
[ "brute force" ]
null
null
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many w...
The single line contains two integers *a* and *b* (1<=≀<=*a*,<=*b*<=≀<=6)Β β€” the numbers written on the paper by the first and second player, correspondingly.
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
[ "2 5\n", "2 4\n" ]
[ "3 0 3\n", "2 1 3\n" ]
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
500
[ { "input": "2 5", "output": "3 0 3" }, { "input": "2 4", "output": "2 1 3" }, { "input": "5 3", "output": "2 1 3" }, { "input": "1 6", "output": "3 0 3" }, { "input": "5 1", "output": "3 1 2" }, { "input": "6 3", "output": "2 0 4" }, { "inp...
1,580,729,968
2,147,483,647
PyPy 3
OK
TESTS
38
140
0
list = [int(x) for x in input().split(" ")] player_1 = 0 player_2 = 0 draw = 0 for i in range(1,7): if abs(list[0]-i)<abs(list[1]-i): player_1+=1 elif abs(list[0]-i)>abs(list[1]-i): player_2+=1 else: draw+=1 print(player_1, draw, player_2)
Title: Playing with Dice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff...
```python list = [int(x) for x in input().split(" ")] player_1 = 0 player_2 = 0 draw = 0 for i in range(1,7): if abs(list[0]-i)<abs(list[1]-i): player_1+=1 elif abs(list[0]-i)>abs(list[1]-i): player_2+=1 else: draw+=1 print(player_1, draw, player_2) ```
3
471
A
MUH and Sticks
PROGRAMMING
1,100
[ "implementation" ]
null
null
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: -...
The single line contains six space-separated integers *l**i* (1<=≀<=*l**i*<=≀<=9) β€” the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wΔ±thout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
[ "4 2 5 4 4 4\n", "4 4 5 4 4 5\n", "1 2 3 4 5 6\n" ]
[ "Bear", "Elephant", "Alien" ]
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.
500
[ { "input": "4 2 5 4 4 4", "output": "Bear" }, { "input": "4 4 5 4 4 5", "output": "Elephant" }, { "input": "1 2 3 4 5 6", "output": "Alien" }, { "input": "5 5 5 5 5 5", "output": "Elephant" }, { "input": "1 1 1 2 3 5", "output": "Alien" }, { "input": "...
1,426,689,326
2,147,483,647
Python 3
OK
TESTS
29
61
0
a = list(map(int,input().split())) x = set(a) z = 0 for i in x: if(a.count(i) > z): z = a.count(i) if(z < 4): print("Alien") else: for i in x: y = a.count(i) if(y != 4): if(y == 2 or y == 6): print("Elephant") break else: print("Bear") break
Title: MUH and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an...
```python a = list(map(int,input().split())) x = set(a) z = 0 for i in x: if(a.count(i) > z): z = a.count(i) if(z < 4): print("Alien") else: for i in x: y = a.count(i) if(y != 4): if(y == 2 or y == 6): print("Elephant") break else: print("Bear") break ```
3
115
A
Party
PROGRAMMING
900
[ "dfs and similar", "graphs", "trees" ]
null
null
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true: - Employee *A* is the immedi...
The first line contains integer *n* (1<=≀<=*n*<=≀<=2000) β€” the number of employees. The next *n* lines contain the integers *p**i* (1<=≀<=*p**i*<=≀<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate...
Print a single integer denoting the minimum number of groups that will be formed in the party.
[ "5\n-1\n1\n2\n1\n-1\n" ]
[ "3\n" ]
For the first example, three groups are sufficient, for example: - Employee 1 - Employees 2 and 4 - Employees 3 and 5
500
[ { "input": "5\n-1\n1\n2\n1\n-1", "output": "3" }, { "input": "4\n-1\n1\n2\n3", "output": "4" }, { "input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11", "output": "4" }, { "input": "6\n-1\n-1\n2\n3\n1\n1", "output": "3" }, { "input": "3\n-1\n1\n1", "output": ...
1,665,416,739
2,147,483,647
Python 3
OK
TESTS
106
124
512,000
from collections import defaultdict, deque n = int(input()) adj = defaultdict(list) for i in range(n): adj[int(input())].append(i+1) q = deque() q.append(-1) grp = 0 visited = set() #print(adj) while q: for _ in range(len(q)): root = q.popleft() visited.add(root) for nei i...
Title: Party Time Limit: None seconds Memory Limit: None megabytes Problem Description: A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an...
```python from collections import defaultdict, deque n = int(input()) adj = defaultdict(list) for i in range(n): adj[int(input())].append(i+1) q = deque() q.append(-1) grp = 0 visited = set() #print(adj) while q: for _ in range(len(q)): root = q.popleft() visited.add(root) ...
3
268
A
Games
PROGRAMMING
800
[ "brute force" ]
null
null
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ...
The first line contains an integer *n* (2<=≀<=*n*<=≀<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≀<=*h**i*,<=*a**i*<=≀<=100) β€” the colors of the *i*-th team's home and guest uniforms, respectively.
In a single line print the number of games where the host team is going to play in the guest uniform.
[ "3\n1 2\n2 4\n3 4\n", "4\n100 42\n42 100\n5 42\n100 5\n", "2\n1 2\n1 2\n" ]
[ "1\n", "5\n", "0\n" ]
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea...
500
[ { "input": "3\n1 2\n2 4\n3 4", "output": "1" }, { "input": "4\n100 42\n42 100\n5 42\n100 5", "output": "5" }, { "input": "2\n1 2\n1 2", "output": "0" }, { "input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52", "output": "6" }, { "input": "10\n68 42\n1 35\n25 70\n...
1,695,222,218
2,147,483,647
Python 3
OK
TESTS
31
92
0
count = 0 n = int(input()) lista = [list(map(int, input().split())) for i in range(n)] for i in range(n): for j in range(n): if lista[i][0] == lista[j][1]: # the benefit of j: to not let the program replace the same value of i in everytime count += 1 print(count)
Title: Games Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W...
```python count = 0 n = int(input()) lista = [list(map(int, input().split())) for i in range(n)] for i in range(n): for j in range(n): if lista[i][0] == lista[j][1]: # the benefit of j: to not let the program replace the same value of i in everytime count += 1 print(count) ```
3
499
B
Lecture
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi...
The first line contains two integers, *n* and *m* (1<=≀<=*n*<=≀<=3000, 1<=≀<=*m*<=≀<=3000) β€” the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel...
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
[ "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n" ]
[ "codeforces round letter round\n", "hbnyiyc joll joll un joll\n" ]
none
500
[ { "input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "output": "codeforces round letter round" }, { "input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll", "output": "hbnyiyc joll joll un joll" }, { "input"...
1,644,067,484
2,147,483,647
PyPy 3-64
OK
TESTS
37
170
8,192,000
n,m=input().split(); n,m=int(n),int(m) l={} for i in range(m): a,b=input().split() l[a]=b c=input().split() for i in range(len(c)): x=c[i] if len(l[x])<len(x): c[i]=l[x] print(*c)
Title: Lecture Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first ...
```python n,m=input().split(); n,m=int(n),int(m) l={} for i in range(m): a,b=input().split() l[a]=b c=input().split() for i in range(len(c)): x=c[i] if len(l[x])<len(x): c[i]=l[x] print(*c) ```
3
877
B
Nikita and string
PROGRAMMING
1,500
[ "brute force", "dp" ]
null
null
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b".
Print a single integerΒ β€” the maximum possible size of beautiful string Nikita can get.
[ "abba\n", "bab\n" ]
[ "4", "2" ]
It the first sample the string is already beautiful. In the second sample he needs to delete one of "b" to make it beautiful.
1,000
[ { "input": "abba", "output": "4" }, { "input": "bab", "output": "2" }, { "input": "bbabbbaabbbb", "output": "9" }, { "input": "bbabbbbbaaba", "output": "10" }, { "input": "bbabbbababaa", "output": "9" }, { "input": "aabbaababbab", "output": "8" }...
1,683,376,574
2,147,483,647
Python 3
OK
TESTS
46
31
0
num_a = 0 dp = {'a': 0, 'b': 0} for c in input(): if c == 'a': num_a += 1 dp['a'] = max(dp.values()) + 1 else: dp['b'] = max(num_a, dp['b']) + 1 print(max(dp['a'], dp['b']))
Title: Nikita and string Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st ...
```python num_a = 0 dp = {'a': 0, 'b': 0} for c in input(): if c == 'a': num_a += 1 dp['a'] = max(dp.values()) + 1 else: dp['b'] = max(num_a, dp['b']) + 1 print(max(dp['a'], dp['b'])) ```
3
276
A
Lunch Rush
PROGRAMMING
900
[ "implementation" ]
null
null
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break. The Rabbits have a list of *n* restaurants to lunch in: the *i*-th restaurant is characterized by two integers *f**i* and *t**i*. Value *t**i* shows the time the Rab...
The first line contains two space-separated integers β€” *n* (1<=≀<=*n*<=≀<=104) and *k* (1<=≀<=*k*<=≀<=109) β€” the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next *n* lines contains two space-separated integers β€” *f**i* (1<=≀<=*f**i*<=≀<=109) an...
In a single line print a single integer β€” the maximum joy value that the Rabbits will get from the lunch.
[ "2 5\n3 3\n4 5\n", "4 6\n5 8\n3 6\n2 3\n2 2\n", "1 5\n1 7\n" ]
[ "4\n", "3\n", "-1\n" ]
none
500
[ { "input": "2 5\n3 3\n4 5", "output": "4" }, { "input": "4 6\n5 8\n3 6\n2 3\n2 2", "output": "3" }, { "input": "1 5\n1 7", "output": "-1" }, { "input": "4 9\n10 13\n4 18\n13 3\n10 6", "output": "13" }, { "input": "1 1\n1 1000000000", "output": "-999999998" }...
1,659,290,500
2,147,483,647
PyPy 3
OK
TESTS
35
374
3,891,200
n, k = map(int, input().split()) j = [] for i in range(n): fi, ti = map(int, input().split()) j.append(fi + (k - ti) if ti > k else fi) print(max(j))
Title: Lunch Rush Time Limit: None seconds Memory Limit: None megabytes Problem Description: Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break. The Rabbits have a list of *n* restaurants to lunch in: the *i*-th re...
```python n, k = map(int, input().split()) j = [] for i in range(n): fi, ti = map(int, input().split()) j.append(fi + (k - ti) if ti > k else fi) print(max(j)) ```
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,568,116,347
2,147,483,647
Python 3
OK
TESTS
40
124
0
p=input() r=0 a=0 a=p.find('h') if a==-1: a=a+1 else: r=10 s=p.rfind('o')+1 if s==0: a = a + 1 else: r=r+10 p=p[a:s] w=p.find('e') if w!=-1: r=r+10 else: a = a + 1 p=p[w:s] e=p.find('l') if e==-1: a = a + 1 else: r=r+10 o=e+1 p=p[o:s] l=p.find('l') if l=...
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 p=input() r=0 a=0 a=p.find('h') if a==-1: a=a+1 else: r=10 s=p.rfind('o')+1 if s==0: a = a + 1 else: r=r+10 p=p[a:s] w=p.find('e') if w!=-1: r=r+10 else: a = a + 1 p=p[w:s] e=p.find('l') if e==-1: a = a + 1 else: r=r+10 o=e+1 p=p[o:s] l=p.find('...
3.938
658
A
Bear and Reverse Radewoosh
PROGRAMMING
800
[ "implementation" ]
null
null
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order. There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by diff...
The first line contains two integers *n* and *c* (1<=≀<=*n*<=≀<=50,<=1<=≀<=*c*<=≀<=1000)Β β€” the number of problems and the constant representing the speed of loosing points. The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≀<=*p**i*<=≀<=1000,<=*p**i*<=&lt;<=*p**i*<=+<=1)Β β€” initial scores. The third...
Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points.
[ "3 2\n50 85 250\n10 15 25\n", "3 6\n50 85 250\n10 15 25\n", "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n" ]
[ "Limak\n", "Radewoosh\n", "Tie\n" ]
In the first sample, there are 3 problems. Limak solves them as follows: 1. Limak spends 10 minutes on the 1-st problem and he gets 50 - *c*Β·10 = 50 - 2Β·10 = 30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85...
500
[ { "input": "3 2\n50 85 250\n10 15 25", "output": "Limak" }, { "input": "3 6\n50 85 250\n10 15 25", "output": "Radewoosh" }, { "input": "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76", "output": "Tie" }, { "input": "4 1\n3 5 6 9\n1 2 4 8", "output": "Limak" }, {...
1,459,183,526
626
Python 3
OK
TESTS
29
62
4,608,000
n, c = [int(x) for x in input().split(" ")] P = [int(x) for x in input().split(" ")] T = [int(x) for x in input().split(" ")] def score(P, T, c): s = 0 x = 0 for p, t in zip(P, T): x += t s += max(0, p - c * x) return s Limak = score(P, T, c) Radewoosh = score(reversed(P), reversed(T)...
Title: Bear and Reverse Radewoosh Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order. There will be *n* problems. The *i*-...
```python n, c = [int(x) for x in input().split(" ")] P = [int(x) for x in input().split(" ")] T = [int(x) for x in input().split(" ")] def score(P, T, c): s = 0 x = 0 for p, t in zip(P, T): x += t s += max(0, p - c * x) return s Limak = score(P, T, c) Radewoosh = score(reversed(P), r...
3
977
A
Wrong Subtraction
PROGRAMMING
800
[ "implementation" ]
null
null
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,...
The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) β€” the number from which Tanya will subtract and the number of subtractions correspondingly.
Print one integer number β€” the result of the decreasing $n$ by one $k$ times. It is guaranteed that the result will be positive integer number.
[ "512 4\n", "1000000000 9\n" ]
[ "50\n", "1\n" ]
The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$.
0
[ { "input": "512 4", "output": "50" }, { "input": "1000000000 9", "output": "1" }, { "input": "131203 11", "output": "12" }, { "input": "999999999 50", "output": "9999" }, { "input": "999999999 49", "output": "99990" }, { "input": "131203 9", "outpu...
1,699,194,751
2,147,483,647
Python 3
OK
TESTS
11
31
0
inp=input() n,k=map(int,inp.split()) while(k>0): k=k-1 # print(n) s=str(n) if(s[-1]=='0'): n=int(n/10) else: n=n-1 print(n)
Title: Wrong Subtraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit ...
```python inp=input() n,k=map(int,inp.split()) while(k>0): k=k-1 # print(n) s=str(n) if(s[-1]=='0'): n=int(n/10) else: n=n-1 print(n) ```
3
356
A
Knight Tournament
PROGRAMMING
1,500
[ "data structures", "dsu" ]
null
null
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event. As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tourname...
The first line contains two integers *n*, *m* (2<=≀<=*n*<=≀<=3Β·105;Β 1<=≀<=*m*<=≀<=3Β·105) β€” the number of knights and the number of fights. Each of the following *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≀<=*l**i*<=&lt;<=*r**i*<=≀<=*n*;Β *l**i*<=≀<=*x**i*<=≀<=*r**i*) β€” the description of the *i*-th f...
Print *n* integers. If the *i*-th knight lost, then the *i*-th number should equal the number of the knight that beat the knight number *i*. If the *i*-th knight is the winner, then the *i*-th number must equal 0.
[ "4 3\n1 2 1\n1 3 3\n1 4 4\n", "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1\n" ]
[ "3 1 4 0 ", "0 8 4 6 4 8 6 1 " ]
Consider the first test case. Knights 1 and 2 fought the first fight and knight 1 won. Knights 1 and 3 fought the second fight and knight 3 won. The last fight was between knights 3 and 4, knight 4 won.
500
[ { "input": "4 3\n1 2 1\n1 3 3\n1 4 4", "output": "3 1 4 0 " }, { "input": "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1", "output": "0 8 4 6 4 8 6 1 " }, { "input": "2 1\n1 2 1", "output": "0 1 " }, { "input": "2 1\n1 2 2", "output": "2 0 " }, { "input": "3 1\n1 3 1", "out...
1,607,860,560
2,147,483,647
PyPy 3
OK
TESTS
63
2,698
25,907,200
n, m = map(int, input().split()) res = ['0'] * n arr = [i for i in range(n)] for _ in range(m): l, r, x = map(int,input().split()) idx, max_idx, path = l - 1, r, [] while idx < r: while idx < n and arr[idx] != idx: path.append(idx) idx = arr[idx] if idx < r ...
Title: Knight Tournament Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event. As for you, you're j...
```python n, m = map(int, input().split()) res = ['0'] * n arr = [i for i in range(n)] for _ in range(m): l, r, x = map(int,input().split()) idx, max_idx, path = l - 1, r, [] while idx < r: while idx < n and arr[idx] != idx: path.append(idx) idx = arr[idx] i...
3
195
B
After Training
PROGRAMMING
1,300
[ "data structures", "implementation", "math" ]
null
null
After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to *m*, correspondingly...
The first line contains two space-separated integers *n*, *m* (1<=≀<=*n*,<=*m*<=≀<=105) β€” the number of balls and baskets, correspondingly.
Print *n* numbers, one per line. The *i*-th line must contain the number of the basket for the *i*-th ball.
[ "4 3\n", "3 1\n" ]
[ "2\n1\n3\n2\n", "1\n1\n1\n" ]
none
1,000
[ { "input": "4 3", "output": "2\n1\n3\n2" }, { "input": "3 1", "output": "1\n1\n1" }, { "input": "10 3", "output": "2\n1\n3\n2\n1\n3\n2\n1\n3\n2" }, { "input": "6 5", "output": "3\n2\n4\n1\n5\n3" }, { "input": "2 6", "output": "3\n4" }, { "input": "5 2"...
1,586,444,303
2,147,483,647
PyPy 3
OK
TESTS
44
372
8,601,600
# -*- coding: utf-8 -*- # Baqir Khan # Software Engineer (Backend) from sys import stdin inp = stdin.readline n, m = map(int, inp().split()) ans = [] if m & 1: mid = m // 2 + 1 ans.append(str(int(mid))) k = 1 n -= 1 while True: if n == 0: break if mid - k < 1: ...
Title: After Training Time Limit: None seconds Memory Limit: None megabytes Problem Description: After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are posi...
```python # -*- coding: utf-8 -*- # Baqir Khan # Software Engineer (Backend) from sys import stdin inp = stdin.readline n, m = map(int, inp().split()) ans = [] if m & 1: mid = m // 2 + 1 ans.append(str(int(mid))) k = 1 n -= 1 while True: if n == 0: break if mid - k <...
3
467
A
George and Accommodation
PROGRAMMING
800
[ "implementation" ]
null
null
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of rooms. The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≀<=*p**i*<=≀<=*q**i*<=≀<=100) β€” the number of people who already live in the *i*-th room and the room's capacity.
Print a single integer β€” the number of rooms where George and Alex can move in.
[ "3\n1 1\n2 2\n3 3\n", "3\n1 10\n0 10\n10 10\n" ]
[ "0\n", "2\n" ]
none
500
[ { "input": "3\n1 1\n2 2\n3 3", "output": "0" }, { "input": "3\n1 10\n0 10\n10 10", "output": "2" }, { "input": "2\n36 67\n61 69", "output": "2" }, { "input": "3\n21 71\n10 88\n43 62", "output": "3" }, { "input": "3\n1 2\n2 3\n3 4", "output": "0" }, { "...
1,696,810,273
2,147,483,647
PyPy 3-64
OK
TESTS
27
61
0
def solve(): x = int(input()) ans = 0 for _ in range(x): p, q = map(int, input().split()) ans += q-p >= 2 print(ans) # t = int(input()) t = 1 while t: solve() t -= 1
Title: George and Accommodation Time Limit: None seconds Memory Limit: None megabytes Problem Description: George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want ...
```python def solve(): x = int(input()) ans = 0 for _ in range(x): p, q = map(int, input().split()) ans += q-p >= 2 print(ans) # t = int(input()) t = 1 while t: solve() t -= 1 ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* β€” it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,680,069,583
2,147,483,647
Python 3
OK
TESTS
30
92
0
x=input() l=0 l1=0 for i in x: if i.islower() : l+=1 else: l1+=1 if l1<=l: print(x.lower()) else: print(x.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 x=input() l=0 l1=0 for i in x: if i.islower() : l+=1 else: l1+=1 if l1<=l: print(x.lower()) else: print(x.upper()) ```
3.977