contestId
int64
0
1.01k
index
stringclasses
57 values
name
stringlengths
2
58
type
stringclasses
2 values
rating
int64
0
3.5k
tags
listlengths
0
11
title
stringclasses
522 values
time-limit
stringclasses
8 values
memory-limit
stringclasses
8 values
problem-description
stringlengths
0
7.15k
input-specification
stringlengths
0
2.05k
output-specification
stringlengths
0
1.5k
demo-input
listlengths
0
7
demo-output
listlengths
0
7
note
stringlengths
0
5.24k
points
float64
0
425k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
14 values
testset
stringclasses
12 values
passedTestCount
int64
0
1k
timeConsumedMillis
int64
0
15k
memoryConsumedBytes
int64
0
805M
code
stringlengths
3
65.5k
prompt
stringlengths
262
8.2k
response
stringlengths
17
65.5k
score
float64
-1
3.99
591
A
Wizards' Duel
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and...
The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ...
Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer ...
[ "100\n50\n50\n", "199\n60\n40\n" ]
[ "50\n", "119.4\n" ]
In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
500
[ { "input": "100\n50\n50", "output": "50" }, { "input": "199\n60\n40", "output": "119.4" }, { "input": "1\n1\n1", "output": "0.5" }, { "input": "1\n1\n500", "output": "0.001996007984" }, { "input": "1\n500\n1", "output": "0.998003992" }, { "input": "1\n...
1,658,675,794
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
l = int(input()) q = int(input()) p = int(input()) mqp = min(q,p) xqp = max(q,p) i = 0 while (i < l): l -= p i += q sub =(i-l)/2 + l if sub - int(sub) > 0: print(sub-0.1) else: print(int(sub))
Title: Wizards' Duel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en...
```python l = int(input()) q = int(input()) p = int(input()) mqp = min(q,p) xqp = max(q,p) i = 0 while (i < l): l -= p i += q sub =(i-l)/2 + l if sub - int(sub) > 0: print(sub-0.1) else: print(int(sub)) ```
0
845
C
Two TVs
PROGRAMMING
1,500
[ "data structures", "greedy", "sortings" ]
null
null
Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*. Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at a...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of shows. Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=109) — starting and ending time of *i*-th show.
If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).
[ "3\n1 2\n2 3\n4 5\n", "4\n1 2\n2 3\n2 3\n1 2\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "3\n1 2\n2 3\n4 5", "output": "YES" }, { "input": "4\n1 2\n2 3\n2 3\n1 2", "output": "NO" }, { "input": "4\n0 1\n1 2\n2 3\n3 4", "output": "YES" }, { "input": "3\n1 2\n2 3\n2 4", "output": "NO" }, { "input": "3\n0 100\n0 100\n0 100", "output": "NO" ...
1,553,981,093
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
109
0
n = int(input()) tv1 = set() tv2 = set() can_watch = True for i in range(n): start, end = input().split(" ") if not start in tv1 and not end in tv1: tv1.add(start) tv1.add(end) elif not start in tv2 and not end in tv2: tv2.add(start) tv2.add(end) else: can_wat...
Title: Two TVs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*. Polycarp owns two TVs. He ...
```python n = int(input()) tv1 = set() tv2 = set() can_watch = True for i in range(n): start, end = input().split(" ") if not start in tv1 and not end in tv1: tv1.add(start) tv1.add(end) elif not start in tv2 and not end in tv2: tv2.add(start) tv2.add(end) else: ...
0
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,641,374,065
2,147,483,647
Python 3
OK
TESTS
35
92
0
x = list(map(int,input().strip().split())) a = x[0] b = x[1] if a%2==0 or b%2==0: print(int(a*b/2)) if a%2!=0 and b%2!=0: print(int(((a-1)*b/2)+(b-1)/2))
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python x = list(map(int,input().strip().split())) a = x[0] b = x[1] if a%2==0 or b%2==0: print(int(a*b/2)) if a%2!=0 and b%2!=0: print(int(((a-1)*b/2)+(b-1)/2)) ```
3.977
288
B
Polo the Penguin and Houses
PROGRAMMING
1,500
[ "combinatorics" ]
null
null
Little penguin Polo loves his home village. The village has *n* houses, indexed by integers from 1 to *n*. Each house has a plaque containing an integer, the *i*-th house has a plaque containing integer *p**i* (1<=≤<=*p**i*<=≤<=*n*). Little penguin Polo loves walking around this village. The walk looks like that. Firs...
The single line contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(8,<=*n*)) — the number of the houses and the number *k* from the statement.
In a single line print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7).
[ "5 2\n", "7 4\n" ]
[ "54\n", "1728\n" ]
none
1,000
[ { "input": "5 2", "output": "54" }, { "input": "7 4", "output": "1728" }, { "input": "8 5", "output": "16875" }, { "input": "8 1", "output": "823543" }, { "input": "10 7", "output": "3176523" }, { "input": "12 8", "output": "536870912" }, { ...
1,594,794,427
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
217
22,323,200
nk=input().split() n=int(nk[0]) k=int(nk[1]) p=1e9+7 a=pow(k,k-1,p) b=pow(n-k,n-k,p) print((a*b)%p)
Title: Polo the Penguin and Houses Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little penguin Polo loves his home village. The village has *n* houses, indexed by integers from 1 to *n*. Each house has a plaque containing an integer, the *i*-th house has a plaque containing integer *p*...
```python nk=input().split() n=int(nk[0]) k=int(nk[1]) p=1e9+7 a=pow(k,k-1,p) b=pow(n-k,n-k,p) print((a*b)%p) ```
-1
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,692,899,006
2,147,483,647
Python 3
OK
TESTS
27
46
0
n = int(input()) count = 0 for i in range(n): string = input().split() p, q = int(string[0]), int(string[1]) if q - p >= 2: count += 1 else: continue print(count)
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 n = int(input()) count = 0 for i in range(n): string = input().split() p, q = int(string[0]), int(string[1]) if q - p >= 2: count += 1 else: continue print(count) ```
3
429
D
Tricky Function
PROGRAMMING
2,200
[ "data structures", "divide and conquer", "geometry" ]
null
null
Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the problem before the contest. Because he wants to make sure Iahub will be t...
The first line of input contains a single integer *n* (2<=≤<=*n*<=≤<=100000). Next line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (<=-<=104<=≤<=*a*[*i*]<=≤<=104).
Output a single integer — the value of *min**i*<=≠<=*j*  *f*(*i*,<=*j*).
[ "4\n1 0 0 -1\n", "2\n1 -1\n" ]
[ "1\n", "2\n" ]
none
2,000
[ { "input": "4\n1 0 0 -1", "output": "1" }, { "input": "2\n1 -1", "output": "2" }, { "input": "100\n-57 -64 83 76 80 27 60 76 -80 -56 52 72 -17 92 -96 87 41 -88 94 89 12 42 36 34 -100 -43 -42 62 3 87 -69 -6 -27 -59 -7 5 -90 -23 63 -87 -60 -92 -40 54 -16 -47 67 -64 10 33 -19 53 -7 -62 16 -...
1,617,009,939
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
17
2,000
17,817,600
from sys import stdin, stdout INF = int(1e9) class Point: def __init__(self, x=0, y=0): self.x = x self.y = y def distance(p1, p2): x = p1.x - p2.x y = p1.y - p2.y return x*x + y*y def bruteForce(point_set, left, right): min_dist = INF for i in ra...
Title: Tricky Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub,...
```python from sys import stdin, stdout INF = int(1e9) class Point: def __init__(self, x=0, y=0): self.x = x self.y = y def distance(p1, p2): x = p1.x - p2.x y = p1.y - p2.y return x*x + y*y def bruteForce(point_set, left, right): min_dist = INF f...
0
863
A
Quasi-palindrome
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String *t* is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to str...
The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes.
Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes).
[ "131\n", "320\n", "2010200\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
0
[ { "input": "131", "output": "YES" }, { "input": "320", "output": "NO" }, { "input": "2010200", "output": "YES" }, { "input": "1", "output": "YES" }, { "input": "1000000000", "output": "YES" }, { "input": "999999999", "output": "YES" }, { "i...
1,588,940,786
2,147,483,647
Python 3
OK
TESTS
44
109
6,656,000
#ROUNIAUDI string1=input().strip().strip("0") str1=string1[::-1] print("YES" if str1==string1 else "NO")
Title: Quasi-palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String *t* is called a palindrome, if it reads the same from left to right and from righ...
```python #ROUNIAUDI string1=input().strip().strip("0") str1=string1[::-1] print("YES" if str1==string1 else "NO") ```
3
46
D
Parking Lot
PROGRAMMING
1,800
[ "data structures", "implementation" ]
D. Parking Lot
2
256
Nowadays it is becoming increasingly difficult to park a car in cities successfully. Let's imagine a segment of a street as long as *L* meters along which a parking lot is located. Drivers should park their cars strictly parallel to the pavement on the right side of the street (remember that in the country the authors ...
The first line contains three integers *L*, *b* и *f* (10<=≤<=*L*<=≤<=100000,<=1<=≤<=*b*,<=*f*<=≤<=100). The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) that indicates the number of requests the program has got. Every request is described on a single line and is given by two numbers. The first number repres...
For every request of the 1 type print number -1 on the single line if the corresponding car couldn't find place to park along the street. Otherwise, print a single number equal to the distance between the back of the car in its parked position and the beginning of the parking lot zone.
[ "30 1 2\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4\n", "30 1 1\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4\n", "10 1 1\n1\n1 12\n" ]
[ "0\n6\n11\n17\n23\n", "0\n6\n11\n17\n6\n", "-1\n" ]
none
0
[ { "input": "30 1 2\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4", "output": "0\n6\n11\n17\n23" }, { "input": "30 1 1\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4", "output": "0\n6\n11\n17\n6" }, { "input": "10 1 1\n1\n1 12", "output": "-1" }, { "input": "10 1 1\n1\n1 9", "output": "0" }, { ...
1,617,534,563
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
16
248
2,252,800
l,b,f=list(map(int,input().split())) n=int(input()) a=[] z=0 for j in range(n): d,c=list(map(int,input().split())) if d==1: x=-1 y=0 for i in range(z): if a[i][0]+a[i][1]+b+c<=l and (i==z-1 or a[i][0]+a[i][1]+b+c<=a[i+1][0]-f): x=a[i][0]+a[i][1]+b ...
Title: Parking Lot Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Nowadays it is becoming increasingly difficult to park a car in cities successfully. Let's imagine a segment of a street as long as *L* meters along which a parking lot is located. Drivers should park their cars strictly parall...
```python l,b,f=list(map(int,input().split())) n=int(input()) a=[] z=0 for j in range(n): d,c=list(map(int,input().split())) if d==1: x=-1 y=0 for i in range(z): if a[i][0]+a[i][1]+b+c<=l and (i==z-1 or a[i][0]+a[i][1]+b+c<=a[i+1][0]-f): x=a[i][0]+a...
-1
676
A
Nicholas and Permutation
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize th...
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation. The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position.
Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
[ "5\n4 5 1 3 2\n", "7\n1 6 5 3 4 7 2\n", "6\n6 5 4 3 2 1\n" ]
[ "3\n", "6\n", "5\n" ]
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2. In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2. In the third sample, the distance between the minimum and the maximum elements is already maximum possib...
500
[ { "input": "5\n4 5 1 3 2", "output": "3" }, { "input": "7\n1 6 5 3 4 7 2", "output": "6" }, { "input": "6\n6 5 4 3 2 1", "output": "5" }, { "input": "2\n1 2", "output": "1" }, { "input": "2\n2 1", "output": "1" }, { "input": "3\n2 3 1", "output": "...
1,676,206,737
2,147,483,647
Python 3
OK
TESTS
159
46
0
def max_dist(n,a): minpos = a.index(min(a)) maxpos = a.index(max(a)) if minpos<maxpos: ldist=minpos rdist = n-maxpos-1 if ldist>rdist: dist=maxpos else: dist=n-minpos-1 else: ldist=maxpos rdist=n-minpos-1 if ldi...
Title: Nicholas and Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integ...
```python def max_dist(n,a): minpos = a.index(min(a)) maxpos = a.index(max(a)) if minpos<maxpos: ldist=minpos rdist = n-maxpos-1 if ldist>rdist: dist=maxpos else: dist=n-minpos-1 else: ldist=maxpos rdist=n-minpos-1 ...
3
894
A
QAQ
PROGRAMMING
800
[ "brute force", "dp" ]
null
null
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are...
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Print a single integer — the number of subsequences "QAQ" in the string.
[ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n" ]
[ "4\n", "3\n" ]
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
500
[ { "input": "QAQAQYSYIOIWIN", "output": "4" }, { "input": "QAQQQZZYNOIWIN", "output": "3" }, { "input": "QA", "output": "0" }, { "input": "IAQVAQZLQBQVQFTQQQADAQJA", "output": "24" }, { "input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ", "output": "378" }, { ...
1,651,871,410
2,147,483,647
Python 3
OK
TESTS
43
46
0
#If I read a Q i need to create a sequence AND # see if I have a sequence with QA, if I have + 1 QAQ #If I read an A I need to add it to create a new seq QA for each seq Q that exists listOfQAQ = [] text = input() totalQAQ = 0 for i in range(len(text)): if(text[i] == 'Q'): #See if I have a seq ...
Title: QAQ Time Limit: None seconds Memory Limit: None megabytes Problem Description: "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"...
```python #If I read a Q i need to create a sequence AND # see if I have a sequence with QA, if I have + 1 QAQ #If I read an A I need to add it to create a new seq QA for each seq Q that exists listOfQAQ = [] text = input() totalQAQ = 0 for i in range(len(text)): if(text[i] == 'Q'): #See if I have a se...
3
1,008
A
Romaji
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant...
The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters.
Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower).
[ "sumimasen\n", "ninja\n", "codeforces\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese. In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.
500
[ { "input": "sumimasen", "output": "YES" }, { "input": "ninja", "output": "YES" }, { "input": "codeforces", "output": "NO" }, { "input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen", "output": "YES" }, { "in...
1,646,250,729
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "ROMAJI", "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", ...
Title: Romaji Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after eve...
```python { "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "ROMAJI", "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "co...
0
478
B
Random Teams
PROGRAMMING
1,300
[ "combinatorics", "constructive algorithms", "greedy", "math" ]
null
null
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that coul...
The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively.
The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.
[ "5 1\n", "3 2\n", "6 3\n" ]
[ "10 10\n", "1 1\n", "3 6\n" ]
In the first sample all the participants get into one team, so there will be exactly ten pairs of friends. In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one. ...
1,000
[ { "input": "5 1", "output": "10 10" }, { "input": "3 2", "output": "1 1" }, { "input": "6 3", "output": "3 6" }, { "input": "5 3", "output": "2 3" }, { "input": "10 2", "output": "20 36" }, { "input": "10 6", "output": "4 10" }, { "input": ...
1,686,337,561
2,147,483,647
PyPy 3-64
OK
TESTS
26
77
716,800
# Solution here def solve(tt): n, m = __list(int) mx = nc2(n-m+1) mn = (n % m) * nc2(n//m + 1) + (m - n % m) * nc2(n//m) print(mn, mx) def nc2(x): return x*(x-1)//2 def main(): t = 1 # t = __int() for tt in range(1, t + 1): solve(f"{tt}: -------------") return class Int...
Title: Random Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is ...
```python # Solution here def solve(tt): n, m = __list(int) mx = nc2(n-m+1) mn = (n % m) * nc2(n//m + 1) + (m - n % m) * nc2(n//m) print(mn, mx) def nc2(x): return x*(x-1)//2 def main(): t = 1 # t = __int() for tt in range(1, t + 1): solve(f"{tt}: -------------") return ...
3
0
none
none
none
0
[ "none" ]
null
null
You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones. Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$. You can apply the following operations any number of times: - Choose some substring of string $a$ (for examp...
The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $a$ of length $n$, consist...
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations.
[ "5 1 10\n01000\n", "5 10 1\n01000\n", "7 2 3\n1111111\n" ]
[ "11\n", "2\n", "0\n" ]
In the first sample, at first you need to reverse substring $[1 \dots 2]$, and then you need to invert substring $[2 \dots 5]$. Then the string was changed as follows: «01000» $\to$ «10000» $\to$ «11111». The total cost of operations is $1 + 10 = 11$. In the second sample, at first you need to invert substring $[1...
0
[ { "input": "5 1 10\n01000", "output": "11" }, { "input": "5 10 1\n01000", "output": "2" }, { "input": "7 2 3\n1111111", "output": "0" }, { "input": "1 60754033 959739508\n0", "output": "959739508" }, { "input": "1 431963980 493041212\n1", "output": "0" }, ...
1,530,459,092
5,192
Python 3
WRONG_ANSWER
PRETESTS
3
139
1,024,000
n,x,y = map(int,input().split()) s = input() l = [] for i in range(n): if(s[i]=='1'): l.append(i) if(len(l)==1): print(min(2*y,x+y)) exit(0) c = 0 if(len(l)==n): print(0) exit(0) for i in range(len(l)-1): if(l[i]+1!=l[i+1]): c+=1 ans = 2*c*y for i in range(1,c+1)...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones. Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$. You can apply the fo...
```python n,x,y = map(int,input().split()) s = input() l = [] for i in range(n): if(s[i]=='1'): l.append(i) if(len(l)==1): print(min(2*y,x+y)) exit(0) c = 0 if(len(l)==n): print(0) exit(0) for i in range(len(l)-1): if(l[i]+1!=l[i+1]): c+=1 ans = 2*c*y for i in ra...
0
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,586,449,465
2,147,483,647
Python 3
OK
TESTS
29
109
307,200
n,c=map(int,input().split()) p=list(map(int,input().split())) t=list(map(int,input().split())) points_limak=0 points_rade=0 time=0 for i in range(n): time+=t[i] points_limak+=max(0,p[i] - c * time) time=0 for i in range(n-1,-1,-1): time+=t[i] points_rade+=max(0,p[i] - c * time) if point...
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=map(int,input().split()) p=list(map(int,input().split())) t=list(map(int,input().split())) points_limak=0 points_rade=0 time=0 for i in range(n): time+=t[i] points_limak+=max(0,p[i] - c * time) time=0 for i in range(n-1,-1,-1): time+=t[i] points_rade+=max(0,p[i] - c * time)...
3
716
A
Crazy Computer
PROGRAMMING
800
[ "implementation" ]
null
null
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear! More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<...
The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=...<=&lt;<=*t**n*<=≤<=109), where *t**i* denote...
Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*.
[ "6 5\n1 3 8 14 19 20\n", "6 1\n1 3 5 7 9 10\n" ]
[ "3", "2" ]
The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be...
500
[ { "input": "6 5\n1 3 8 14 19 20", "output": "3" }, { "input": "6 1\n1 3 5 7 9 10", "output": "2" }, { "input": "1 1\n1000000000", "output": "1" }, { "input": "5 5\n1 7 12 13 14", "output": "4" }, { "input": "2 1000000000\n1 1000000000", "output": "2" }, { ...
1,632,073,167
2,147,483,647
Python 3
OK
TESTS
81
155
15,155,200
temp = input().split(" ") n = int(temp[0]) c = int(temp[1]) x=0 temp2 = input().split(" ") sec = [] for i in range(0,n): sec.append(int(temp2[i])) for i in range (1,n) : diff = sec[i] - sec[i-1] if(diff <= c): x=x+1 else : x=0 x=x+1 print(x,"\n")
Title: Crazy Computer Time Limit: None seconds Memory Limit: None megabytes Problem Description: ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear! More formally, if you typed a word at second *a* and then the next word at second *...
```python temp = input().split(" ") n = int(temp[0]) c = int(temp[1]) x=0 temp2 = input().split(" ") sec = [] for i in range(0,n): sec.append(int(temp2[i])) for i in range (1,n) : diff = sec[i] - sec[i-1] if(diff <= c): x=x+1 else : x=0 x=x+1 print(x,"\n") ```
3
363
A
Soroban
PROGRAMMING
800
[ "implementation" ]
null
null
You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban — an abacus developed in Japan. This phenomenon has its reasons, of course, but we are not going to speak about ...
The first line contains a single integer *n* (0<=≤<=*n*<=&lt;<=109).
Print the description of the decimal digits of number *n* from the last one to the first one (as mentioned on the picture in the statement), one per line. Print the beads as large English letters 'O', rod pieces as character '-' and the reckoning bar as '|'. Print as many rods, as many digits are in the decimal represe...
[ "2\n", "13\n", "720\n" ]
[ "O-|OO-OO\n", "O-|OOO-O\nO-|O-OOO\n", "O-|-OOOO\nO-|OO-OO\n-O|OO-OO\n" ]
none
500
[ { "input": "2", "output": "O-|OO-OO" }, { "input": "13", "output": "O-|OOO-O\nO-|O-OOO" }, { "input": "720", "output": "O-|-OOOO\nO-|OO-OO\n-O|OO-OO" }, { "input": "0", "output": "O-|-OOOO" }, { "input": "1", "output": "O-|O-OOO" }, { "input": "3", ...
1,678,370,285
2,147,483,647
Python 3
OK
TESTS
36
46
0
n = input() l = ["O-|-OOOO" , "O-|O-OOO" ,"O-|OO-OO" ,"O-|OOO-O","O-|OOOO-", "-O|-OOOO","-O|O-OOO","-O|OO-OO","-O|OOO-O","-O|OOOO-" ] for i in n[::-1] : print(l[int(i)])
Title: Soroban Time Limit: None seconds Memory Limit: None megabytes Problem Description: You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban — an abacus develop...
```python n = input() l = ["O-|-OOOO" , "O-|O-OOO" ,"O-|OO-OO" ,"O-|OOO-O","O-|OOOO-", "-O|-OOOO","-O|O-OOO","-O|OO-OO","-O|OOO-O","-O|OOOO-" ] for i in n[::-1] : print(l[int(i)]) ```
3
732
A
Buy a Shovel
PROGRAMMING
800
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<...
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e...
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
[ "117 3\n", "237 7\n", "15 2\n" ]
[ "9\n", "1\n", "2\n" ]
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels ...
500
[ { "input": "117 3", "output": "9" }, { "input": "237 7", "output": "1" }, { "input": "15 2", "output": "2" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "1000 3", "output": "1" }, { "input": "1000 1", ...
1,692,940,198
2,147,483,647
PyPy 3-64
OK
TESTS
54
62
0
k, r = map(int, input().split()) for ans in range(1, 11): if (k * ans - r) % 10 == 0 or (k * ans) % 10 == 0: print(ans) break
Title: Buy a Shovel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his ...
```python k, r = map(int, input().split()) for ans in range(1, 11): if (k * ans - r) % 10 == 0 or (k * ans) % 10 == 0: print(ans) break ```
3
136
A
Presents
PROGRAMMING
800
[ "implementation" ]
null
null
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift....
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
[ "4\n2 3 4 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "4 1 2 3\n", "1 3 2\n", "1 2\n" ]
none
500
[ { "input": "4\n2 3 4 1", "output": "4 1 2 3" }, { "input": "3\n1 3 2", "output": "1 3 2" }, { "input": "2\n1 2", "output": "1 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10" }, { "input"...
1,680,687,915
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
n =int(input()) p = list(map(int, input().split())) total = [0] * n for i in range(n): res = p.index(p[i]) + 1 total[p[i]-1] = res print(total)
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t...
```python n =int(input()) p = list(map(int, input().split())) total = [0] * n for i in range(n): res = p.index(p[i]) + 1 total[p[i]-1] = res print(total) ```
0
633
B
A Trivial Problem
PROGRAMMING
1,300
[ "brute force", "constructive algorithms", "math", "number theory" ]
null
null
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem?
The only line of input contains an integer *m* (1<=≤<=*m*<=≤<=100<=000) — the required number of trailing zeroes in factorial.
First print *k* — the number of values of *n* such that the factorial of *n* ends with *m* zeroes. Then print these *k* integers in increasing order.
[ "1\n", "5\n" ]
[ "5\n5 6 7 8 9 ", "0" ]
The factorial of *n* is equal to the product of all integers from 1 to *n* inclusive, that is *n*! = 1·2·3·...·*n*. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
500
[ { "input": "1", "output": "5\n5 6 7 8 9 " }, { "input": "5", "output": "0" }, { "input": "2", "output": "5\n10 11 12 13 14 " }, { "input": "3", "output": "5\n15 16 17 18 19 " }, { "input": "7", "output": "5\n30 31 32 33 34 " }, { "input": "12", "ou...
1,619,953,459
2,147,483,647
Python 3
OK
TESTS
68
171
6,553,600
#n,m,k = map(int, input().strip().split(' ')) m=int(input()) #a = list(map(int, input().strip().split(' '))) l=[1] i=1 l1=[i] l2=0 #building the array while(i<100000): i+=1 l2=5*i c=0 while(l2%5==0): l2=l2//5 c+=1 l.append(l[-1]+c) l1.append(i) #print(l) if m no...
Title: A Trivial Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zer...
```python #n,m,k = map(int, input().strip().split(' ')) m=int(input()) #a = list(map(int, input().strip().split(' '))) l=[1] i=1 l1=[i] l2=0 #building the array while(i<100000): i+=1 l2=5*i c=0 while(l2%5==0): l2=l2//5 c+=1 l.append(l[-1]+c) l1.append(i) #print(l...
3
486
A
Calculating Function
PROGRAMMING
800
[ "implementation", "math" ]
null
null
For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*.
The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015).
Print *f*(*n*) in a single line.
[ "4\n", "5\n" ]
[ "2\n", "-3\n" ]
*f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
500
[ { "input": "4", "output": "2" }, { "input": "5", "output": "-3" }, { "input": "1000000000", "output": "500000000" }, { "input": "1000000001", "output": "-500000001" }, { "input": "1000000000000000", "output": "500000000000000" }, { "input": "100", ...
1,696,102,605
2,147,483,647
Python 3
OK
TESTS
39
46
0
n = int(input()) if n%2 != 0: val = -(n + 1) / 2 else: val = n/2 print(int(val))
Title: Calculating Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*. Input Specification: The single line...
```python n = int(input()) if n%2 != 0: val = -(n + 1) / 2 else: val = n/2 print(int(val)) ```
3
676
A
Nicholas and Permutation
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize th...
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation. The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position.
Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
[ "5\n4 5 1 3 2\n", "7\n1 6 5 3 4 7 2\n", "6\n6 5 4 3 2 1\n" ]
[ "3\n", "6\n", "5\n" ]
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2. In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2. In the third sample, the distance between the minimum and the maximum elements is already maximum possib...
500
[ { "input": "5\n4 5 1 3 2", "output": "3" }, { "input": "7\n1 6 5 3 4 7 2", "output": "6" }, { "input": "6\n6 5 4 3 2 1", "output": "5" }, { "input": "2\n1 2", "output": "1" }, { "input": "2\n2 1", "output": "1" }, { "input": "3\n2 3 1", "output": "...
1,616,261,176
2,147,483,647
Python 3
OK
TESTS
159
62
0
import sys input = sys.stdin.readline n = int(input()) a = [int(i) for i in input().split()] x, y = a.index(1), a.index(n) ans = max(x, y, n - x - 1, n - y - 1) print(ans)
Title: Nicholas and Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integ...
```python import sys input = sys.stdin.readline n = int(input()) a = [int(i) for i in input().split()] x, y = a.index(1), a.index(n) ans = max(x, y, n - x - 1, n - y - 1) print(ans) ```
3
552
B
Vanya and Books
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers. Vanya wants to know how many digits he will have to write down as he labels th...
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
Print the number of digits needed to number all the books.
[ "13\n", "4\n" ]
[ "17\n", "4\n" ]
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits. Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
1,000
[ { "input": "13", "output": "17" }, { "input": "4", "output": "4" }, { "input": "100", "output": "192" }, { "input": "99", "output": "189" }, { "input": "1000000000", "output": "8888888899" }, { "input": "1000000", "output": "5888896" }, { "...
1,535,824,492
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
input numberofbooks totlength=length(numberofbooks) nonlast=int(right(numberofbooks,1)) digits=(length-1)*10+nonlast print digits
Title: Vanya and Books Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assig...
```python input numberofbooks totlength=length(numberofbooks) nonlast=int(right(numberofbooks,1)) digits=(length-1)*10+nonlast print digits ```
-1
748
B
Santa Claus and Keyboard Check
PROGRAMMING
1,500
[ "implementation", "strings" ]
null
null
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. ...
The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k...
[ "helloworld\nehoolwlroz\n", "hastalavistababy\nhastalavistababy\n", "merrychristmas\nchristmasmerry\n" ]
[ "3\nh e\nl o\nd z\n", "0\n", "-1\n" ]
none
1,000
[ { "input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z" }, { "input": "hastalavistababy\nhastalavistababy", "output": "0" }, { "input": "merrychristmas\nchristmasmerry", "output": "-1" }, { "input": "kusyvdgccw\nkusyvdgccw", "output": "0" }, { "input": "...
1,485,021,984
2,147,483,647
Python 3
OK
TESTS
86
77
4,608,000
dict = {} l = [] o = input() s = input() for i in range(len(o)): if o[i]==s[i]: if o[i] not in l: if o[i] not in dict.keys() and o[i] not in dict.values(): l.append(o[i]) else: print("-1") exit() else: if o[i] i...
Title: Santa Claus and Keyboard Check Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each ke...
```python dict = {} l = [] o = input() s = input() for i in range(len(o)): if o[i]==s[i]: if o[i] not in l: if o[i] not in dict.keys() and o[i] not in dict.values(): l.append(o[i]) else: print("-1") exit() else: ...
3
279
B
Books
PROGRAMMING
1,400
[ "binary search", "brute force", "implementation", "two pointers" ]
null
null
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to...
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n...
Print a single integer — the maximum number of books Valera can read.
[ "4 5\n3 1 2 1\n", "3 3\n2 2 3\n" ]
[ "3\n", "1\n" ]
none
1,000
[ { "input": "4 5\n3 1 2 1", "output": "3" }, { "input": "3 3\n2 2 3", "output": "1" }, { "input": "1 3\n5", "output": "0" }, { "input": "1 10\n4", "output": "1" }, { "input": "2 10\n6 4", "output": "2" }, { "input": "6 10\n2 3 4 2 1 1", "output": "4...
1,697,756,760
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
92
0
n, t = map(int, input().split()) a = list(map(int, input().split())) b = a + a ans = 0 lptr = 0 rptr = 0 total = 0 while True: while rptr < 2 * n and total + b[rptr] <= t: total += b[rptr] rptr += 1 ans = max(ans, rptr - lptr) if rptr == 2 * n: break total -= b[...
Title: Books Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t...
```python n, t = map(int, input().split()) a = list(map(int, input().split())) b = a + a ans = 0 lptr = 0 rptr = 0 total = 0 while True: while rptr < 2 * n and total + b[rptr] <= t: total += b[rptr] rptr += 1 ans = max(ans, rptr - lptr) if rptr == 2 * n: break t...
0
6
C
Alice, Bob and Chocolate
PROGRAMMING
1,200
[ "greedy", "two pointers" ]
C. Alice, Bob and Chocolate
2
64
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them wi...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right).
Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob.
[ "5\n2 9 8 2 7\n" ]
[ "2 3\n" ]
none
0
[ { "input": "5\n2 9 8 2 7", "output": "2 3" }, { "input": "1\n1", "output": "1 0" }, { "input": "2\n1 1", "output": "1 1" }, { "input": "3\n1 1 1", "output": "2 1" }, { "input": "4\n1 1 1 1", "output": "2 2" }, { "input": "1\n6", "output": "1 0" }...
1,672,912,720
2,147,483,647
Python 3
OK
TESTS
40
218
6,860,800
# LUOGU_RID: 98755200 n = int(input()) lst = list(map(int,input().split())) l,r = 0,n-1 sl,sr = 0,0 cntl,cntr=0,0 while l<=r: if sl<=sr: cntl+=1 sl += lst[l] l+=1 else: cntr+=1 sr += lst[r] r-=1 print("%d %d"%(cntl,cntr))
Title: Alice, Bob and Chocolate Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. Fo...
```python # LUOGU_RID: 98755200 n = int(input()) lst = list(map(int,input().split())) l,r = 0,n-1 sl,sr = 0,0 cntl,cntr=0,0 while l<=r: if sl<=sr: cntl+=1 sl += lst[l] l+=1 else: cntr+=1 sr += lst[r] r-=1 print("%d %d"%(cntl,cntr)) ```
3.894383
294
A
Shaass and Oskols
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*...
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i...
On the *i*-th line of the output print the number of birds on the *i*-th wire.
[ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n" ]
[ "0\n12\n5\n0\n16\n", "3\n0\n3\n" ]
none
500
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16" }, { "input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "output": "0\n66\n57\n7\n0" }, { "input": "10\n48 53 10 28 91 56 8...
1,649,926,642
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
26
154
3,379,200
n = int(input()) l = list(map(int,input().split())) m = int(input()) for i in range(m): x,y = map(int,input().split()) if x==1 and n>1: l[x] += l[x-1]-y elif x==n and n>1: l[x-2] += y-1 else: l[x] += l[x-1]-y l[x-2] += y-1 l[x-1]=0 for val in l: prin...
Title: Shaass and Oskols Time Limit: None seconds Memory Limit: None megabytes Problem Description: Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each...
```python n = int(input()) l = list(map(int,input().split())) m = int(input()) for i in range(m): x,y = map(int,input().split()) if x==1 and n>1: l[x] += l[x-1]-y elif x==n and n>1: l[x-2] += y-1 else: l[x] += l[x-1]-y l[x-2] += y-1 l[x-1]=0 for val in l:...
-1
108
A
Palindromic Times
PROGRAMMING
1,000
[ "implementation", "strings" ]
A. Palindromic Times
2
256
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on th...
The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits.
Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.
[ "12:21\n", "23:59\n" ]
[ "13:31\n", "00:00\n" ]
none
500
[ { "input": "12:21", "output": "13:31" }, { "input": "23:59", "output": "00:00" }, { "input": "15:51", "output": "20:02" }, { "input": "10:44", "output": "11:11" }, { "input": "04:02", "output": "04:40" }, { "input": "02:11", "output": "02:20" }, ...
1,586,000,808
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
186
307,200
s = input() a = [x for x in s.split(":")] temp = "" f = -1 if(int(a[0])+1==24): temp ="00"+":"+"00" f = 0 for i in range(1,24-int(a[0])): k = str(a[0]) if(int(k[::-1]) > int(a[1]) and int(k[::-1]) < 59 and f!=0): temp= k + ":" +k[::-1] f = 0 break else: ...
Title: Palindromic Times Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling...
```python s = input() a = [x for x in s.split(":")] temp = "" f = -1 if(int(a[0])+1==24): temp ="00"+":"+"00" f = 0 for i in range(1,24-int(a[0])): k = str(a[0]) if(int(k[::-1]) > int(a[1]) and int(k[::-1]) < 59 and f!=0): temp= k + ":" +k[::-1] f = 0 break else...
0
478
B
Random Teams
PROGRAMMING
1,300
[ "combinatorics", "constructive algorithms", "greedy", "math" ]
null
null
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that coul...
The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively.
The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.
[ "5 1\n", "3 2\n", "6 3\n" ]
[ "10 10\n", "1 1\n", "3 6\n" ]
In the first sample all the participants get into one team, so there will be exactly ten pairs of friends. In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one. ...
1,000
[ { "input": "5 1", "output": "10 10" }, { "input": "3 2", "output": "1 1" }, { "input": "6 3", "output": "3 6" }, { "input": "5 3", "output": "2 3" }, { "input": "10 2", "output": "20 36" }, { "input": "10 6", "output": "4 10" }, { "input": ...
1,684,767,935
2,147,483,647
PyPy 3-64
OK
TESTS
26
62
0
n, m = map(int, input().split()) a = n // m b = n % m maksa = n - m + 1 ans1 = maksa*(maksa - 1) // 2 ans2 = b * (a+1)*a // 2 + (m-b)*a*(a-1) // 2 print(ans2, ans1)
Title: Random Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is ...
```python n, m = map(int, input().split()) a = n // m b = n % m maksa = n - m + 1 ans1 = maksa*(maksa - 1) // 2 ans2 = b * (a+1)*a // 2 + (m-b)*a*(a-1) // 2 print(ans2, ans1) ```
3
677
A
Vanya and Fence
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ...
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Print a single integer — the minimum possible valid width of the road.
[ "3 7\n4 5 14\n", "6 1\n1 1 1 1 1 1\n", "6 5\n7 6 8 9 10 5\n" ]
[ "4\n", "6\n", "11\n" ]
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required m...
500
[ { "input": "3 7\n4 5 14", "output": "4" }, { "input": "6 1\n1 1 1 1 1 1", "output": "6" }, { "input": "6 5\n7 6 8 9 10 5", "output": "11" }, { "input": "10 420\n214 614 297 675 82 740 174 23 255 15", "output": "13" }, { "input": "10 561\n657 23 1096 487 785 66 481...
1,693,052,775
2,147,483,647
PyPy 3-64
OK
TESTS
29
61
0
count_h = str(input()) count_h = count_h.split(" ") height = int(count_h[1]) friends = str(input()) friends = friends.split(" ") reuslt = 0 for friend in friends: if(int(friend) <= height): reuslt = reuslt + 1 else: reuslt = reuslt + 2 print(reuslt)
Title: Vanya and Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers...
```python count_h = str(input()) count_h = count_h.split(" ") height = int(count_h[1]) friends = str(input()) friends = friends.split(" ") reuslt = 0 for friend in friends: if(int(friend) <= height): reuslt = reuslt + 1 else: reuslt = reuslt + 2 print(reuslt) ```
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,686,514,744
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); typedef long long int lli; using namespace std; #define debug(x) cout << #x << '=' << x << endl; void printArr(vector<int>arr) { for(int i:arr) cout << i << ' '; } int maxArr(vector<int> arr) { int m=arr[0]...
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 #include <bits/stdc++.h> #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); typedef long long int lli; using namespace std; #define debug(x) cout << #x << '=' << x << endl; void printArr(vector<int>arr) { for(int i:arr) cout << i << ' '; } int maxArr(vector<int> arr) { in...
-1
199
A
Hexadecimal's theorem
PROGRAMMING
900
[ "brute force", "constructive algorithms", "implementation", "number theory" ]
null
null
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F...
The input contains of a single integer *n* (0<=≤<=*n*<=&lt;<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number.
Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them.
[ "3\n", "13\n" ]
[ "1 1 1\n", "2 3 8\n" ]
none
500
[ { "input": "3", "output": "1 1 1" }, { "input": "13", "output": "2 3 8" }, { "input": "0", "output": "0 0 0" }, { "input": "1", "output": "1 0 0" }, { "input": "2", "output": "1 1 0" }, { "input": "1597", "output": "233 377 987" }, { "input...
1,629,501,471
2,147,483,647
Python 3
OK
TESTS
54
156
6,758,400
# Nome: Matheus de Souza Oliveira RA: 203407 fibonacciNumber = int(input()) print(f"0 0 {fibonacciNumber}")
Title: Hexadecimal's theorem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let'...
```python # Nome: Matheus de Souza Oliveira RA: 203407 fibonacciNumber = int(input()) print(f"0 0 {fibonacciNumber}") ```
3
923
D
Picking Strings
PROGRAMMING
2,500
[ "constructive algorithms", "implementation", "strings" ]
null
null
Alice has a string consisting of characters 'A', 'B' and 'C'. Bob can use the following transitions on any substring of our string in any order any number of times: - A BC - B AC - C AB - AAA empty string Note that a substring is one or more consecutive characters. For given queries, determine whether it is ...
The first line contains a string *S* (1<=≤<=|*S*|<=≤<=105). The second line contains a string *T* (1<=≤<=|*T*|<=≤<=105), each of these strings consists only of uppercase English letters 'A', 'B' and 'C'. The third line contains the number of queries *Q* (1<=≤<=*Q*<=≤<=105). The following *Q* lines describe queries. T...
Print a string of *Q* characters, where the *i*-th character is '1' if the answer to the *i*-th query is positive, and '0' otherwise.
[ "AABCCBAAB\nABCB\n5\n1 3 1 2\n2 2 2 4\n7 9 1 1\n3 4 2 3\n4 5 1 3\n" ]
[ "10011\n" ]
In the first query we can achieve the result, for instance, by using transitions <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/2c164f8b6e335aa51b97bbd019ca0d7326927314.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The third query asks for changing AAB to A — but in this case we a...
1,750
[ { "input": "AABCCBAAB\nABCB\n5\n1 3 1 2\n2 2 2 4\n7 9 1 1\n3 4 2 3\n4 5 1 3", "output": "10011" }, { "input": "AAAAAA\nAAAAAA\n30\n3 4 1 2\n3 3 4 4\n5 6 3 4\n3 3 2 3\n6 6 1 5\n2 4 4 6\n1 6 2 5\n6 6 3 4\n3 5 1 4\n4 5 3 6\n2 3 2 4\n3 4 4 4\n6 6 4 6\n3 3 2 5\n1 5 3 3\n4 6 1 2\n6 6 6 6\n3 3 3 4\n6 6 6 6...
1,680,538,015
2,147,483,647
PyPy 3-64
OK
TESTS
109
1,512
15,052,800
a = input() b = input() w = [0] x = [0] for i in a: if i == 'A': w.append(w[-1]+1) x.append(x[-1]) else: w.append(0) x.append(x[-1]+1) y = [0] z = [0] for i in b: if i == 'A': y.append(y[-1]+1) z.append(z[-1]) else: y.append(0) ...
Title: Picking Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice has a string consisting of characters 'A', 'B' and 'C'. Bob can use the following transitions on any substring of our string in any order any number of times: - A BC - B AC - C AB - AAA empty string Not...
```python a = input() b = input() w = [0] x = [0] for i in a: if i == 'A': w.append(w[-1]+1) x.append(x[-1]) else: w.append(0) x.append(x[-1]+1) y = [0] z = [0] for i in b: if i == 'A': y.append(y[-1]+1) z.append(z[-1]) else: y....
3
807
A
Is it rated?
PROGRAMMING
900
[ "implementation", "sortings" ]
null
null
Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ...
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants. Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order...
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
[ "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n", "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n", "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n" ]
[ "rated\n", "unrated\n", "maybe\n" ]
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som...
500
[ { "input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884", "output": "rated" }, { "input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699", "output": "maybe" }, { ...
1,494,234,780
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
61
0
n = int(input()) a = b = [0] * n ans = "maybe" for i in range(n): a[i], b[i] = map(int, input().split()) if i > 0 and b[i - 1] < b[i]: ans = "unrated" for i in range(n): if a[i] != b[i]: ans = "rated" break print(ans)
Title: Is it rated? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number ...
```python n = int(input()) a = b = [0] * n ans = "maybe" for i in range(n): a[i], b[i] = map(int, input().split()) if i > 0 and b[i - 1] < b[i]: ans = "unrated" for i in range(n): if a[i] != b[i]: ans = "rated" break print(ans) ```
0
359
A
Table
PROGRAMMING
1,000
[ "constructive algorithms", "greedy", "implementation" ]
null
null
Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the *x*-th row and the *y*-th column as a pair of numbers (*x*,<=*y*). The table corners are...
The first line contains exactly two integers *n*, *m* (3<=≤<=*n*,<=*m*<=≤<=50). Next *n* lines contain the description of the table cells. Specifically, the *i*-th line contains *m* space-separated integers *a**i*1,<=*a**i*2,<=...,<=*a**im*. If *a**ij* equals zero, then cell (*i*,<=*j*) isn't good. Otherwise *a**ij* e...
Print a single number — the minimum number of operations Simon needs to carry out his idea.
[ "3 3\n0 0 0\n0 1 0\n0 0 0\n", "4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0\n" ]
[ "4\n", "2\n" ]
In the first sample, the sequence of operations can be like this: - For the first time you need to choose cell (2, 2) and corner (1, 1). - For the second time you need to choose cell (2, 2) and corner (3, 3). - For the third time you need to choose cell (2, 2) and corner (3, 1). - For the fourth time you need to c...
500
[ { "input": "3 3\n0 0 0\n0 1 0\n0 0 0", "output": "4" }, { "input": "4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0", "output": "2" }, { "input": "50 4\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0...
1,453,500,158
2,147,483,647
PyPy 3
OK
TESTS
37
109
204,800
n, m = map(int, input().split()) matrix = [[] for i in range(n)] for i in range(n): matrix[i] = list(map(int, input().split())) flag = 0 for i in range(n): for j in range(m): if matrix[i][j] == 1: if i == 0 or i == n - 1 or j == 0 or j == m - 1: flag = 1 if flag...
Title: Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on t...
```python n, m = map(int, input().split()) matrix = [[] for i in range(n)] for i in range(n): matrix[i] = list(map(int, input().split())) flag = 0 for i in range(n): for j in range(m): if matrix[i][j] == 1: if i == 0 or i == n - 1 or j == 0 or j == m - 1: flag = 1 ...
3
965
B
Battleship
PROGRAMMING
1,300
[ "implementation" ]
null
null
Arkady is playing Battleship. The rules of this game aren't really important. There is a field of $n \times n$ cells. There should be exactly one $k$-decker on the field, i. e. a ship that is $k$ cells long oriented either horizontally or vertically. However, Arkady doesn't know where it is located. For each cell Arka...
The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the size of the field and the size of the ship. The next $n$ lines contain the field. Each line contains $n$ characters, each of which is either '#' (denotes a definitely empty cell) or '.' (denotes a cell that can belong to the ship).
Output two integers — the row and the column of a cell that belongs to the maximum possible number of different locations of the ship. If there are multiple answers, output any of them. In particular, if no ship can be placed on the field, you can output any cell.
[ "4 3\n#..#\n#.#.\n....\n.###\n", "10 4\n#....##...\n.#...#....\n..#..#..#.\n...#.#....\n.#..##.#..\n.....#...#\n...#.##...\n.#...#.#..\n.....#..#.\n...#.#...#\n", "19 6\n##..............###\n#......#####.....##\n.....#########.....\n....###########....\n...#############...\n..###############..\n.###############...
[ "3 2\n", "6 1\n", "1 8\n" ]
The picture below shows the three possible locations of the ship that contain the cell $(3, 2)$ in the first sample.
1,000
[ { "input": "4 3\n#..#\n#.#.\n....\n.###", "output": "3 2" }, { "input": "10 4\n#....##...\n.#...#....\n..#..#..#.\n...#.#....\n.#..##.#..\n.....#...#\n...#.##...\n.#...#.#..\n.....#..#.\n...#.#...#", "output": "6 1" }, { "input": "19 6\n##..............###\n#......#####.....##\n.....####...
1,526,498,182
2,147,483,647
Python 3
OK
TESTS
39
842
7,065,600
n, k = [int(x) for x in input().split()] a = [] for i in range(n): s = input() a.append(s) mx, I, J = 0, 0, 0 for i in range(n): for j in range(n): if a[i][j] == '#': continue iup, ido = i, i jup, jdo = j, j while iup >= 0 and a[iup][j] == '.': ...
Title: Battleship Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arkady is playing Battleship. The rules of this game aren't really important. There is a field of $n \times n$ cells. There should be exactly one $k$-decker on the field, i. e. a ship that is $k$ cells long oriented either ...
```python n, k = [int(x) for x in input().split()] a = [] for i in range(n): s = input() a.append(s) mx, I, J = 0, 0, 0 for i in range(n): for j in range(n): if a[i][j] == '#': continue iup, ido = i, i jup, jdo = j, j while iup >= 0 and a[iup][j] == '....
3
285
B
Find Marble
PROGRAMMING
1,200
[ "implementation" ]
null
null
Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not. First Petya puts a marble under the glass in position *s*. Then he performs som...
The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaran...
If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1.
[ "4 2 1\n2 3 4 1\n", "4 3 3\n4 1 3 2\n", "4 3 4\n1 2 3 4\n", "3 1 3\n2 1 3\n" ]
[ "3\n", "0\n", "-1\n", "-1\n" ]
none
1,000
[ { "input": "4 2 1\n2 3 4 1", "output": "3" }, { "input": "4 3 3\n4 1 3 2", "output": "0" }, { "input": "4 3 4\n1 2 3 4", "output": "-1" }, { "input": "3 1 3\n2 1 3", "output": "-1" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "10 6 7\n10 7 8 1...
1,482,495,295
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <utility> #include <string> #include <set> #include <limits> #include <map> #include <stack> #include <queue> #include <cstring> #include <cctype> #define ul unsigned long int #define ull unsigned long long int #define ll long long i...
Title: Find Marble Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the ...
```python #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <utility> #include <string> #include <set> #include <limits> #include <map> #include <stack> #include <queue> #include <cstring> #include <cctype> #define ul unsigned long int #define ull unsigned long long int #define ll l...
-1
74
C
Chessboard Billiard
PROGRAMMING
2,100
[ "dfs and similar", "dsu", "graphs", "number theory" ]
C. Chessboard Billiard
2
256
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving. More formally, first one of four diagonal directions is chosen and the billiard ball moves ...
The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=106).
Print a single number, the maximum possible number of billiard balls that do not pairwise beat each other. Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is preferred to use cin (also you may use the %I64d specificator).
[ "3 4\n", "3 3\n" ]
[ "2", "3" ]
none
1,500
[ { "input": "3 4", "output": "2" }, { "input": "3 3", "output": "3" }, { "input": "2 2", "output": "2" }, { "input": "4 3", "output": "2" }, { "input": "2 3", "output": "2" }, { "input": "4 4", "output": "4" }, { "input": "4 6", "output"...
1,605,279,863
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
25
218
614,400
n, m = map(int, input().split()) def answer(n, m): if n == m: return n if n > m: n, m = m, n return answer(n, m - n + 1) print(answer(n, m))
Title: Chessboard Billiard Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue...
```python n, m = map(int, input().split()) def answer(n, m): if n == m: return n if n > m: n, m = m, n return answer(n, m - n + 1) print(answer(n, m)) ```
-1
202
A
LLPS
PROGRAMMING
800
[ "binary search", "bitmasks", "brute force", "greedy", "implementation", "strings" ]
null
null
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*...
The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10.
Print the lexicographically largest palindromic subsequence of string *s*.
[ "radar\n", "bowwowwow\n", "codeforces\n", "mississipp\n" ]
[ "rr\n", "wwwww\n", "s\n", "ssss\n" ]
Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".
500
[ { "input": "radar", "output": "rr" }, { "input": "bowwowwow", "output": "wwwww" }, { "input": "codeforces", "output": "s" }, { "input": "mississipp", "output": "ssss" }, { "input": "tourist", "output": "u" }, { "input": "romka", "output": "r" }, ...
1,643,261,049
2,147,483,647
Python 3
OK
TESTS
54
92
0
s = input() ans = sorted(s) ans = ans[::-1] res = "" if (ans.count(ans[0]) == 1): print(ans[0]) else: print(ans[0]*ans.count(ans[0]))
Title: LLPS Time Limit: None seconds Memory Limit: None megabytes Problem Description: This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ...
```python s = input() ans = sorted(s) ans = ans[::-1] res = "" if (ans.count(ans[0]) == 1): print(ans[0]) else: print(ans[0]*ans.count(ans[0])) ```
3
438
D
The Child and Sequence
PROGRAMMING
2,300
[ "data structures", "math" ]
null
null
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite sequence of Picks. Fortunately, Picks remembers how to repair the sequence. Initially he should create an integer array *a*[1],<=*a*[2],<=...,<=*a*[*n...
The first line of input contains two integer: *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers, separated by space: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109) — initial value of array elements. Each of the next *m* lines begins with a number *type* . - If *type*<==<=1, there...
For each operation 1, please print a line containing the answer. Notice that the answer may exceed the 32-bit integer.
[ "5 5\n1 2 3 4 5\n2 3 5 4\n3 3 5\n1 2 5\n2 1 3 3\n1 1 3\n", "10 10\n6 9 6 7 6 1 10 10 9 5\n1 3 9\n2 7 10 9\n2 5 10 8\n1 4 7\n3 3 7\n2 7 9 9\n1 2 4\n1 6 6\n1 5 9\n3 1 10\n" ]
[ "8\n5\n", "49\n15\n23\n1\n9\n" ]
Consider the first testcase: - At first, *a* = {1, 2, 3, 4, 5}. - After operation 1, *a* = {1, 2, 3, 0, 1}. - After operation 2, *a* = {1, 2, 5, 0, 1}. - At operation 3, 2 + 5 + 0 + 1 = 8. - After operation 4, *a* = {1, 2, 2, 0, 1}. <li> At operation 5, 1 + 2 + 2 = 5. <ul>
2,000
[ { "input": "5 5\n1 2 3 4 5\n2 3 5 4\n3 3 5\n1 2 5\n2 1 3 3\n1 1 3", "output": "8\n5" }, { "input": "10 10\n6 9 6 7 6 1 10 10 9 5\n1 3 9\n2 7 10 9\n2 5 10 8\n1 4 7\n3 3 7\n2 7 9 9\n1 2 4\n1 6 6\n1 5 9\n3 1 10", "output": "49\n15\n23\n1\n9" }, { "input": "1 1\n1\n1 1 1", "output": "1" ...
1,674,068,282
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
3
4,000
13,516,800
n, m = map(int, input().split()) a = list(map(int, input().split())) for q in range(m): t = list(map(int, input().split())) if t[0] == 1: l, r = t[1], t[2] l -= 1 r -= 1 s = 0 for i in range(l, r + 1): s += a[i] print(s) elif t[0] == 2:...
Title: The Child and Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite sequence of Picks. Fortunately, Picks reme...
```python n, m = map(int, input().split()) a = list(map(int, input().split())) for q in range(m): t = list(map(int, input().split())) if t[0] == 1: l, r = t[1], t[2] l -= 1 r -= 1 s = 0 for i in range(l, r + 1): s += a[i] print(s) elif ...
0
0
none
none
none
0
[ "none" ]
null
null
Ivan had string *s* consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string *s*. Ivan preferred making a new string to finding the old one. Ivan knows some information about the string *s*. Namely, he remembers, that string *t**i* occurs in string *s* at least *k**...
The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of strings Ivan remembers. The next *n* lines contain information about the strings. The *i*-th of these lines contains non-empty string *t**i*, then positive integer *k**i*, which equal to the number of times the string *t**i* occurs in strin...
Print lexicographically minimal string that fits all the information Ivan remembers.
[ "3\na 4 1 3 5 7\nab 2 1 5\nca 1 4\n", "1\na 1 3\n", "3\nab 1 1\naba 1 3\nab 2 3 5\n" ]
[ "abacaba\n", "aaa\n", "ababab\n" ]
none
0
[ { "input": "3\na 4 1 3 5 7\nab 2 1 5\nca 1 4", "output": "abacaba" }, { "input": "1\na 1 3", "output": "aaa" }, { "input": "3\nab 1 1\naba 1 3\nab 2 3 5", "output": "ababab" }, { "input": "6\nba 2 16 18\na 1 12\nb 3 4 13 20\nbb 2 6 8\nababbbbbaab 1 3\nabababbbbb 1 1", "ou...
1,533,730,649
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
7
2,000
143,974,400
n=int(input()) ans=[] mk=-1 from sys import * stk=[] for j in range(0,n): val=stdin.readline().split() st=val[0] k=int(val[1]) for i in range(0,k): #print i,len(val),k mk=max(mk,int(val[2+i])+len(st)-1) ans.append((-len(st),val[2+i],j)) stk.append(st) ans.sort() #print ans b=["*"...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan had string *s* consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string *s*. Ivan preferred making a new string to finding the old one. Ivan knows some information about t...
```python n=int(input()) ans=[] mk=-1 from sys import * stk=[] for j in range(0,n): val=stdin.readline().split() st=val[0] k=int(val[1]) for i in range(0,k): #print i,len(val),k mk=max(mk,int(val[2+i])+len(st)-1) ans.append((-len(st),val[2+i],j)) stk.append(st) ans.sort() #print a...
0
678
D
Iterated Linear Function
PROGRAMMING
1,700
[ "math", "number theory" ]
null
null
Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=&gt;<=0. For the given integer values *A*, *B*, *n* and *x* find the value of *g*(*n*)(*x*) modulo 109<=+<=7.
The only line contains four integers *A*, *B*, *n* and *x* (1<=≤<=*A*,<=*B*,<=*x*<=≤<=109,<=1<=≤<=*n*<=≤<=1018) — the parameters from the problem statement. Note that the given value *n* can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you c...
Print the only integer *s* — the value *g*(*n*)(*x*) modulo 109<=+<=7.
[ "3 4 1 1\n", "3 4 2 1\n", "3 4 3 1\n" ]
[ "7\n", "25\n", "79\n" ]
none
0
[ { "input": "3 4 1 1", "output": "7" }, { "input": "3 4 2 1", "output": "25" }, { "input": "3 4 3 1", "output": "79" }, { "input": "1 1 1 1", "output": "2" }, { "input": "3 10 723 6", "output": "443623217" }, { "input": "14 81 51 82", "output": "908...
1,689,648,685
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689648685.0296812")# 1689648685.029703
Title: Iterated Linear Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=&gt;<=0. For the given integer values *A*, *B*, *n* and *x* find th...
```python print("_RANDOM_GUESS_1689648685.0296812")# 1689648685.029703 ```
0
777
A
Shell Game
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "math" ]
null
null
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator. The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements.
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
[ "4\n2\n", "1\n1\n" ]
[ "1\n", "0\n" ]
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements. 1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. Th...
500
[ { "input": "4\n2", "output": "1" }, { "input": "1\n1", "output": "0" }, { "input": "2\n2", "output": "0" }, { "input": "3\n1", "output": "1" }, { "input": "3\n2", "output": "0" }, { "input": "3\n0", "output": "2" }, { "input": "2000000000\n...
1,603,552,171
2,147,483,647
PyPy 3
OK
TESTS
68
187
0
l = '122100' m = '001221' r = '210012' n = int(input()) b = input() n = n%6-1 if l[n]==b: print(0) elif m[n]==b: print(1) elif r[n]==b: print(2)
Title: Shell Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball ben...
```python l = '122100' m = '001221' r = '210012' n = int(input()) b = input() n = n%6-1 if l[n]==b: print(0) elif m[n]==b: print(1) elif r[n]==b: print(2) ```
3
559
A
Gerald's Hexagon
PROGRAMMING
1,600
[ "brute force", "geometry", "math" ]
null
null
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it. He pain...
The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides ex...
Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.
[ "1 1 1 1 1 1\n", "1 2 1 2 1 2\n" ]
[ "6\n", "13\n" ]
This is what Gerald's hexagon looks like in the first sample: <img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/> And that's what it looks like in the second sample: <img class="tex-graphics" src="https://espress...
500
[ { "input": "1 1 1 1 1 1", "output": "6" }, { "input": "1 2 1 2 1 2", "output": "13" }, { "input": "2 4 5 3 3 6", "output": "83" }, { "input": "45 19 48 18 46 21", "output": "6099" }, { "input": "66 6 65 6 66 5", "output": "5832" }, { "input": "7 5 4 8 ...
1,650,174,786
2,147,483,647
PyPy 3-64
OK
TESTS
26
62
0
a = list(map(int, input().split(' '))) x = (a[0] + a[1] + a[2])**2 y = a[0]**2 + a[2]**2 + a[4]**2 print(x - y)
Title: Gerald's Hexagon Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer numbe...
```python a = list(map(int, input().split(' '))) x = (a[0] + a[1] + a[2])**2 y = a[0]**2 + a[2]**2 + a[4]**2 print(x - y) ```
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,684,483,025
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
list_str = input().split() number_words = int(list_str[0]) print(list_str[1]) print(list_str[2]) print(list_str[3])
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python list_str = input().split() number_words = int(list_str[0]) print(list_str[1]) print(list_str[2]) print(list_str[3]) ```
-1
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,601,486,356
2,147,483,647
PyPy 3
OK
TESTS
42
140
0
def main(): n, m = map(int, input().split()) if n % 2 == 1: n += 1 if m - n < 2: print(-1) else: print(n, n + 1, n + 2) if __name__ == '__main__': main()
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 def main(): n, m = map(int, input().split()) if n % 2 == 1: n += 1 if m - n < 2: print(-1) else: print(n, n + 1, n + 2) if __name__ == '__main__': main() ```
3
919
A
Supermarket
PROGRAMMING
800
[ "brute force", "greedy", "implementation" ]
null
null
We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (You don't need to care about what "yuan" is), the same as $a/b$ yuan for a kilo. Now imagine you'd...
The first line contains two positive integers $n$ and $m$ ($1 \leq n \leq 5\,000$, $1 \leq m \leq 100$), denoting that there are $n$ supermarkets and you want to buy $m$ kilos of apples. The following $n$ lines describe the information of the supermarkets. Each line contains two positive integers $a, b$ ($1 \leq a, b ...
The only line, denoting the minimum cost for $m$ kilos of apples. Please make sure that the absolute or relative error between your answer and the correct answer won't exceed $10^{-6}$. Formally, let your answer be $x$, and the jury's answer be $y$. Your answer is considered correct if $\frac{|x - y|}{\max{(1, |y|)}} ...
[ "3 5\n1 2\n3 4\n1 3\n", "2 1\n99 100\n98 99\n" ]
[ "1.66666667\n", "0.98989899\n" ]
In the first sample, you are supposed to buy $5$ kilos of apples in supermarket $3$. The cost is $5/3$ yuan. In the second sample, you are supposed to buy $1$ kilo of apples in supermarket $2$. The cost is $98/99$ yuan.
500
[ { "input": "3 5\n1 2\n3 4\n1 3", "output": "1.66666667" }, { "input": "2 1\n99 100\n98 99", "output": "0.98989899" }, { "input": "50 37\n78 49\n96 4\n86 62\n28 4\n19 2\n79 43\n79 92\n95 35\n33 60\n54 84\n90 25\n2 25\n53 21\n86 52\n72 25\n6 78\n41 46\n3 68\n42 89\n33 35\n57 43\n99 45\n1 8...
1,630,835,876
2,147,483,647
Python 3
OK
TESTS
43
77
6,758,400
N, M = map(int,input().split()) minCost = float('inf') for i in range(N): A, B = map(int,input().split()) minCost = min(M*A/B, minCost) print(minCost)
Title: Supermarket Time Limit: None seconds Memory Limit: None megabytes Problem Description: We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (Yo...
```python N, M = map(int,input().split()) minCost = float('inf') for i in range(N): A, B = map(int,input().split()) minCost = min(M*A/B, minCost) print(minCost) ```
3
510
A
Fox And Snake
PROGRAMMING
800
[ "implementation" ]
null
null
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ...
The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50). *n* is an odd number.
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
[ "3 3\n", "3 4\n", "5 3\n", "9 9\n" ]
[ "###\n..#\n###\n", "####\n...#\n####\n", "###\n..#\n###\n#..\n###\n", "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n" ]
none
500
[ { "input": "3 3", "output": "###\n..#\n###" }, { "input": "3 4", "output": "####\n...#\n####" }, { "input": "5 3", "output": "###\n..#\n###\n#..\n###" }, { "input": "9 9", "output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#...
1,695,555,957
2,147,483,647
Python 3
OK
TESTS
28
46
0
height,length=map(int,input().split()) side=1 for i in range(height): if i%2==0: print('#'*length) elif side: print('.'*(length-1),'#',sep='') side=0 else: print('#','.'*(length-1),sep='') side=1
Title: Fox And Snake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*...
```python height,length=map(int,input().split()) side=1 for i in range(height): if i%2==0: print('#'*length) elif side: print('.'*(length-1),'#',sep='') side=0 else: print('#','.'*(length-1),sep='') side=1 ```
3
447
A
DZY Loves Hash
PROGRAMMING
800
[ "implementation" ]
null
null
DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==...
The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109).
Output a single integer — the answer to the problem.
[ "10 5\n0\n21\n53\n41\n53\n", "5 5\n0\n1\n2\n3\n4\n" ]
[ "4\n", "-1\n" ]
none
500
[ { "input": "10 5\n0\n21\n53\n41\n53", "output": "4" }, { "input": "5 5\n0\n1\n2\n3\n4", "output": "-1" }, { "input": "10 6\n811966798\n734823552\n790326404\n929189974\n414343256\n560346537", "output": "4" }, { "input": "2 2\n788371161\n801743052", "output": "-1" }, { ...
1,685,466,131
2,147,483,647
PyPy 3-64
OK
TESTS
29
46
0
s = set() p, n = map(int, input().split()) for k in range(n): buc = int(input()) % p if buc in s: print(k+1) break else: s.add(buc) else: print(-1)
Title: DZY Loves Hash Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbere...
```python s = set() p, n = map(int, input().split()) for k in range(n): buc = int(input()) % p if buc in s: print(k+1) break else: s.add(buc) else: print(-1) ```
3
134
A
Average Numbers
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Find all such indices *i*, that the *i*-th element equals the arithmetic mean of all other elements (that is all elements except for this one).
The first line contains the integer *n* (2<=≤<=*n*<=≤<=2·105). The second line contains elements of the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). All the elements are positive integers.
Print on the first line the number of the sought indices. Print on the second line the sought indices in the increasing order. All indices are integers from 1 to *n*. If the sought elements do not exist, then the first output line should contain number 0. In this case you may either not print the second line or print ...
[ "5\n1 2 3 4 5\n", "4\n50 50 50 50\n" ]
[ "1\n3 ", "4\n1 2 3 4 " ]
none
500
[ { "input": "5\n1 2 3 4 5", "output": "1\n3 " }, { "input": "4\n50 50 50 50", "output": "4\n1 2 3 4 " }, { "input": "3\n2 3 1", "output": "1\n1 " }, { "input": "2\n4 2", "output": "0" }, { "input": "2\n1 1", "output": "2\n1 2 " }, { "input": "10\n3 3 3 ...
1,459,305,575
2,147,483,647
Python 3
OK
TESTS
58
233
24,268,800
n, t = int(input()), list(map(int, input().split())) s = sum(t) temp = [i + 1 for i in range(n) if t[i] * n == s] print(len(temp)) print(' '.join(map(str, temp)))
Title: Average Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Find all such indices *i*, that the *i*-th element equals the arithmetic mean of all other elements (that is all elements except for this one). ...
```python n, t = int(input()), list(map(int, input().split())) s = sum(t) temp = [i + 1 for i in range(n) if t[i] * n == s] print(len(temp)) print(' '.join(map(str, temp))) ```
3
78
A
Haiku
PROGRAMMING
800
[ "implementation", "strings" ]
A. Haiku
2
256
Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll...
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailin...
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
[ "on codeforces \nbeta round is running\n a rustling of keys \n", "how many gallons\nof edo s rain did you drink\n cuckoo\n" ]
[ "YES", "NO" ]
none
500
[ { "input": "on codeforces \nbeta round is running\n a rustling of keys ", "output": "YES" }, { "input": "how many gallons\nof edo s rain did you drink\n cuckoo", "output": "NO" }, { "input": " hatsu shigure\n saru mo komino wo\nhoshige nari", ...
1,636,364,049
2,147,483,647
Python 3
OK
TESTS
40
92
4,505,600
def countVowel(s): res=0 for i in s: if i in ('a','e','i','o','u'): res+=1 return res s1=input() s2=input() s3=input() if countVowel(s1)==5 and countVowel(s2)==7 and countVowel(s3)==5: print('YES') else: print('NO')
Title: Haiku Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase...
```python def countVowel(s): res=0 for i in s: if i in ('a','e','i','o','u'): res+=1 return res s1=input() s2=input() s3=input() if countVowel(s1)==5 and countVowel(s2)==7 and countVowel(s3)==5: print('YES') else: print('NO') ```
3.968608
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,669,833,719
2,147,483,647
Python 3
OK
TESTS
18
92
0
def intmaker(list1): for i in range(len(list1)): list1[i]=int(list1[i]) return list1 nm=input().split(' ') n,m=intmaker(nm) list_puzzle=input().split(' ') puzzle=intmaker(list_puzzle) puzzle=sorted(puzzle) min=puzzle[n-1]-puzzle[0] for i in range(1,(m-n)+1,1): if puzzle[i+n-1] - puzzle[i]...
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 def intmaker(list1): for i in range(len(list1)): list1[i]=int(list1[i]) return list1 nm=input().split(' ') n,m=intmaker(nm) list_puzzle=input().split(' ') puzzle=intmaker(list_puzzle) puzzle=sorted(puzzle) min=puzzle[n-1]-puzzle[0] for i in range(1,(m-n)+1,1): if puzzle[i+n-1] -...
3
490
A
Team Olympiad
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at prog...
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
In the first line output integer *w* — the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to...
[ "7\n1 3 1 3 2 1 2\n", "4\n2 1 1 2\n" ]
[ "2\n3 5 2\n6 7 4\n", "0\n" ]
none
500
[ { "input": "7\n1 3 1 3 2 1 2", "output": "2\n3 5 2\n6 7 4" }, { "input": "4\n2 1 1 2", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "2\n3 1", "output": "0" }, { "input": "3\n2 1 2", "output": "0" }, { "input": "3\n1 2 3", "output...
1,668,766,868
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
77
2,867,200
n=int(input()) for i in range(n): a=int(input()) L[i]=a k1,k2,k3=0,0,0 for i in range(len(L)): if L[i]==1: k1+=1 elif L[i]==2: k2+=1 else: k3+=1 x=min(k1,k2,k3) print(x) for _ in range(x): i1,i2,i3=L.index(1),L.index(2),L.index(3) print(i1+1,i2+1,i3+1)...
Title: Team Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)...
```python n=int(input()) for i in range(n): a=int(input()) L[i]=a k1,k2,k3=0,0,0 for i in range(len(L)): if L[i]==1: k1+=1 elif L[i]==2: k2+=1 else: k3+=1 x=min(k1,k2,k3) print(x) for _ in range(x): i1,i2,i3=L.index(1),L.index(2),L.index(3) print(i1+1,...
-1
584
A
Olesya and Rodion
PROGRAMMING
1,000
[ "math" ]
null
null
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-...
The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by.
Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
[ "3 2\n" ]
[ "712" ]
none
500
[ { "input": "3 2", "output": "222" }, { "input": "2 2", "output": "22" }, { "input": "4 3", "output": "3333" }, { "input": "5 3", "output": "33333" }, { "input": "10 7", "output": "7777777777" }, { "input": "2 9", "output": "99" }, { "input"...
1,689,129,616
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
https://codeforces.com/problemset/problem/584/A
Title: Olesya and Rodion Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larg...
```python https://codeforces.com/problemset/problem/584/A ```
-1
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,586,479,933
2,147,483,647
Python 3
OK
TESTS
114
124
0
ballons, friends = map(int, input().split()) color = input() lencolor = len(color) x = 0 count = [0] * 26 # букв всего 26б значит и индекс не мсжет быть болше 26 # tkcb кол-во одного цвета больше чем друзейб кто-то получит два одного цвета for i in color: nomer = ord(i) - 97 count[nomer] += 1 # индекс...
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 ballons, friends = map(int, input().split()) color = input() lencolor = len(color) x = 0 count = [0] * 26 # букв всего 26б значит и индекс не мсжет быть болше 26 # tkcb кол-во одного цвета больше чем друзейб кто-то получит два одного цвета for i in color: nomer = ord(i) - 97 count[nomer] += 1...
3
801
B
Valued Keys
PROGRAMMING
900
[ "constructive algorithms", "greedy", "strings" ]
null
null
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th cha...
The first line of input contains the string *x*. The second line of input contains the string *y*. Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100.
If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1. Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters.
[ "ab\naa\n", "nzwzl\nniwel\n", "ab\nba\n" ]
[ "ba\n", "xiyez\n", "-1\n" ]
The first case is from the statement. Another solution for the second case is "zizez" There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) =  "ba".
1,000
[ { "input": "ab\naa", "output": "ba" }, { "input": "nzwzl\nniwel", "output": "xiyez" }, { "input": "ab\nba", "output": "-1" }, { "input": "r\nl", "output": "l" }, { "input": "d\ny", "output": "-1" }, { "input": "yvowz\ncajav", "output": "cajav" },...
1,613,719,790
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
62
307,200
x = input() y = input() z = "" for i in range(len(x)): if ord(x[i])<ord(y[i]): print(-1) break elif x[i]==y[i]=="z": print(-1) break else: if ord(x[i])==ord(y[i]): z+=chr(ord(x[i])+1) else: z+=y[i] else: print(z)
Title: Valued Keys Time Limit: None seconds Memory Limit: None megabytes Problem Description: You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string...
```python x = input() y = input() z = "" for i in range(len(x)): if ord(x[i])<ord(y[i]): print(-1) break elif x[i]==y[i]=="z": print(-1) break else: if ord(x[i])==ord(y[i]): z+=chr(ord(x[i])+1) else: z+=y[i] else: print(z) ```
0
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,620,226,393
2,147,483,647
Python 3
OK
TESTS
30
124
0
s = input() low = 0 up = 0 for i in range(0, len(s)): if s[i].islower(): low += 1 elif s[i].isupper(): up += 1 if low < up: s = s.upper() elif low > up: s = s.lower() elif low == up: s = s.lower() print(s)
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 s = input() low = 0 up = 0 for i in range(0, len(s)): if s[i].islower(): low += 1 elif s[i].isupper(): up += 1 if low < up: s = s.upper() elif low > up: s = s.lower() elif low == up: s = s.lower() print(s) ```
3.969
764
A
Taymyr is calling you
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,...
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
[ "1 1 10\n", "1 2 5\n", "2 3 9\n" ]
[ "10\n", "2\n", "1\n" ]
Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
500
[ { "input": "1 1 10", "output": "10" }, { "input": "1 2 5", "output": "2" }, { "input": "2 3 9", "output": "1" }, { "input": "4 8 9", "output": "1" }, { "input": "7 9 2", "output": "0" }, { "input": "10000 10000 10000", "output": "1" }, { "i...
1,595,260,893
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
21
1,000
7,270,400
n,m,z=map(int,input().split()) a,b,c=n,m,0 l=[] k=[] for i in range(1,z+1): if(n*i<=z): l.append(n*i) if(m*i<=z): k.append(m*i) for i in range(1,z+1): if i in l: if i in k: c=c+1 print(c)
Title: Taymyr is calling you Time Limit: None seconds Memory Limit: None megabytes Problem Description: Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists com...
```python n,m,z=map(int,input().split()) a,b,c=n,m,0 l=[] k=[] for i in range(1,z+1): if(n*i<=z): l.append(n*i) if(m*i<=z): k.append(m*i) for i in range(1,z+1): if i in l: if i in k: c=c+1 print(c) ```
0
777
A
Shell Game
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "math" ]
null
null
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator. The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements.
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
[ "4\n2\n", "1\n1\n" ]
[ "1\n", "0\n" ]
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements. 1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. Th...
500
[ { "input": "4\n2", "output": "1" }, { "input": "1\n1", "output": "0" }, { "input": "2\n2", "output": "0" }, { "input": "3\n1", "output": "1" }, { "input": "3\n2", "output": "0" }, { "input": "3\n0", "output": "2" }, { "input": "2000000000\n...
1,617,808,857
2,147,483,647
PyPy 3
OK
TESTS
68
109
0
a = [1 , 2 , 2 , 1 , 0 , 0] b = [0 , 0 , 1 , 2 , 2 , 1] c = [2 , 1 , 0 , 0 , 1 , 2] n = int(input()) n = n%6 if not n: n = 6 x = int(input()) if a[n-1] == x: print(0) elif b[n-1] ==x: print(1) else: print(2)
Title: Shell Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball ben...
```python a = [1 , 2 , 2 , 1 , 0 , 0] b = [0 , 0 , 1 , 2 , 2 , 1] c = [2 , 1 , 0 , 0 , 1 , 2] n = int(input()) n = n%6 if not n: n = 6 x = int(input()) if a[n-1] == x: print(0) elif b[n-1] ==x: print(1) else: print(2) ```
3
369
C
Valera and Elections
PROGRAMMING
1,600
[ "dfs and similar", "graphs", "trees" ]
null
null
The city Valera lives in is going to hold elections to the city Parliament. The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, fo...
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of districts in the city. Then *n*<=-<=1 lines follow. Each line contains the description of a city road as three positive integers *x**i*, *y**i*, *t**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 1<=≤<=*t**i*<=≤<=2) — the districts connected by the *...
In the first line print a single non-negative number *k* — the minimum size of the required subset of candidates. Then on the second line print *k* space-separated integers *a*1,<=*a*2,<=... *a**k* — the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print a...
[ "5\n1 2 2\n2 3 2\n3 4 2\n4 5 2\n", "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1\n", "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2\n" ]
[ "1\n5 \n", "1\n3 \n", "4\n5 4 3 2 \n" ]
none
1,500
[ { "input": "5\n1 2 2\n2 3 2\n3 4 2\n4 5 2", "output": "1\n5 " }, { "input": "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1", "output": "1\n3 " }, { "input": "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2", "output": "4\n5 4 3 2 " }, { "input": "5\n1 5 1\n5 4 2\n4 3 1\n3 2 2", "output": "1\n2 " }, { ...
1,465,392,751
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
1,000
19,660,800
from collections import defaultdict,deque,Counter,OrderedDict import sys sys.setrecursionlimit(20000) def main(): n = int(input()) adj = [ [] for i in range(n)] white = [0]*n d = [0]*n for i in range(n-1): a,b,c = map(int,input().split()) a,b = a-1,b-1 adj[a].appen...
Title: Valera and Elections Time Limit: None seconds Memory Limit: None megabytes Problem Description: The city Valera lives in is going to hold elections to the city Parliament. The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other...
```python from collections import defaultdict,deque,Counter,OrderedDict import sys sys.setrecursionlimit(20000) def main(): n = int(input()) adj = [ [] for i in range(n)] white = [0]*n d = [0]*n for i in range(n-1): a,b,c = map(int,input().split()) a,b = a-1,b-1 ad...
0
365
A
Good Number
PROGRAMMING
1,100
[ "implementation" ]
null
null
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*).
The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109).
Print a single integer — the number of *k*-good numbers in *a*.
[ "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n", "2 1\n1\n10\n" ]
[ "10\n", "1\n" ]
none
500
[ { "input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560", "output": "10" }, { "input": "2 1\n1\n10", "output": "1" }, { "input": "1 0\n1000000000", "output": "1" }, { "input": "1 1\n1000000000", "output": "1" }, { ...
1,690,506,525
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1690506524.9195805")# 1690506524.9196017
Title: Good Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve...
```python print("_RANDOM_GUESS_1690506524.9195805")# 1690506524.9196017 ```
0
263
A
Beautiful Matrix
PROGRAMMING
800
[ "implementation" ]
null
null
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1....
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
[ "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 0 0 0 0...
1,696,590,791
2,147,483,647
Python 3
OK
TESTS
25
92
0
arr=[] for i in range(5): temp=list(map(int,input().split())) for j in range(len(temp)): if temp[j]==1: cell=[i,j] tar=[2,2] print(abs(cell[0]-tar[0])+abs(cell[1]-tar[1]))
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 arr=[] for i in range(5): temp=list(map(int,input().split())) for j in range(len(temp)): if temp[j]==1: cell=[i,j] tar=[2,2] print(abs(cell[0]-tar[0])+abs(cell[1]-tar[1])) ```
3
617
A
Elephant
PROGRAMMING
800
[ "math" ]
null
null
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ...
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
[ "5\n", "12\n" ]
[ "1\n", "3\n" ]
In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
500
[ { "input": "5", "output": "1" }, { "input": "12", "output": "3" }, { "input": "999999", "output": "200000" }, { "input": "41", "output": "9" }, { "input": "1000000", "output": "200000" }, { "input": "1", "output": "1" }, { "input": "2", ...
1,699,462,130
2,147,483,647
Python 3
OK
TESTS
34
46
0
x=int(input('')) if x%5==0: steps=x//5 print(steps) else: steps=(int((x/5)))+1 print(steps)
Title: Elephant Time Limit: None seconds Memory Limit: None megabytes Problem Description: An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2...
```python x=int(input('')) if x%5==0: steps=x//5 print(steps) else: steps=(int((x/5)))+1 print(steps) ```
3
125
B
Simple XML
PROGRAMMING
1,000
[ "implementation" ]
null
null
Let's define a string &lt;x&gt; as an opening tag, where *x* is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type &lt;/x&gt;, where *x* is the same letter. Tegs can be nested into each other: in this case one opening and closing tag pair is located inside another pair. Let's d...
The input data consists on the only non-empty string — the XML-text, its length does not exceed 1000 characters. It is guaranteed that the text is valid. The text contains no spaces.
Print the given XML-text according to the above-given rules.
[ "&lt;a&gt;&lt;b&gt;&lt;c&gt;&lt;/c&gt;&lt;/b&gt;&lt;/a&gt;\n", "&lt;a&gt;&lt;b&gt;&lt;/b&gt;&lt;d&gt;&lt;c&gt;&lt;/c&gt;&lt;/d&gt;&lt;/a&gt;\n" ]
[ "&lt;a&gt;\n &lt;b&gt;\n &lt;c&gt;\n &lt;/c&gt;\n &lt;/b&gt;\n&lt;/a&gt;\n", "&lt;a&gt;\n &lt;b&gt;\n &lt;/b&gt;\n &lt;d&gt;\n &lt;c&gt;\n &lt;/c&gt;\n &lt;/d&gt;\n&lt;/a&gt;\n" ]
none
1,500
[ { "input": "<a><b><c></c></b></a>", "output": "<a>\n <b>\n <c>\n </c>\n </b>\n</a>" }, { "input": "<a><b></b><d><c></c></d></a>", "output": "<a>\n <b>\n </b>\n <d>\n <c>\n </c>\n </d>\n</a>" }, { "input": "<z></z>", "output": "<z>\n</z>" }, { "input": "<u><d...
1,591,200,115
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
216
307,200
a =[] s ="" b = 0 c = [] for x in input(): if x == "<" or x == ">" :pass elif x =="/":s = "/" else: a.append(s + x) s = "" for x in range(len(a)): for y in a[:x]: if len(a[x]) == 2:b = c[a.index(a[x][-1])] elif len(y) == 1:b+= 1 else:b -= 1 c.append(b) b = 0 for x in range(len(a)): print(" "*(c[x]*2) +...
Title: Simple XML Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's define a string &lt;x&gt; as an opening tag, where *x* is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type &lt;/x&gt;, where *x* is the same letter. Tegs can be nested into ea...
```python a =[] s ="" b = 0 c = [] for x in input(): if x == "<" or x == ">" :pass elif x =="/":s = "/" else: a.append(s + x) s = "" for x in range(len(a)): for y in a[:x]: if len(a[x]) == 2:b = c[a.index(a[x][-1])] elif len(y) == 1:b+= 1 else:b -= 1 c.append(b) b = 0 for x in range(len(a)): print(" "*...
0
262
A
Roma and Lucky Numbers
PROGRAMMING
800
[ "implementation" ]
null
null
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integer...
The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has. The numbers in the lines are separated by single spaces.
In a single line print a single integer — the answer to the problem.
[ "3 4\n1 2 4\n", "3 2\n447 44 77\n" ]
[ "3\n", "2\n" ]
In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
500
[ { "input": "3 4\n1 2 4", "output": "3" }, { "input": "3 2\n447 44 77", "output": "2" }, { "input": "2 2\n507978501 180480073", "output": "2" }, { "input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089", "output": "9" }, { ...
1,623,517,677
2,147,483,647
Python 3
OK
TESTS
34
124
0
n,k=map(int,input().split()) cnt=0 for a in input().split(): cnt+=a.count('4')+a.count('7')<=k print(cnt)
Title: Roma and Lucky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits...
```python n,k=map(int,input().split()) cnt=0 for a in input().split(): cnt+=a.count('4')+a.count('7')<=k print(cnt) ```
3
92
A
Chips
PROGRAMMING
800
[ "implementation", "math" ]
A. Chips
2
256
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*. The presenter has *m* chips. The pre...
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly.
Print the number of chips the presenter ended up with.
[ "4 11\n", "17 107\n", "3 8\n" ]
[ "0\n", "2\n", "1\n" ]
In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the ...
500
[ { "input": "4 11", "output": "0" }, { "input": "17 107", "output": "2" }, { "input": "3 8", "output": "1" }, { "input": "46 7262", "output": "35" }, { "input": "32 6864", "output": "0" }, { "input": "36 6218", "output": "14" }, { "input": "...
1,637,749,610
2,147,483,647
Python 3
OK
TESTS
25
124
0
N, M = map(int, input().split()) S = int(N * (N + 1) / 2) Imax = int((-1.0 + (1 + 8 * (M % S)) ** 0.5) / 2.0) result = int(M % S - Imax * (Imax + 1) / 2) print(result)
Title: Chips Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus nu...
```python N, M = map(int, input().split()) S = int(N * (N + 1) / 2) Imax = int((-1.0 + (1 + 8 * (M % S)) ** 0.5) / 2.0) result = int(M % S - Imax * (Imax + 1) / 2) print(result) ```
3.969
897
B
Chtholly's request
PROGRAMMING
1,300
[ "brute force" ]
null
null
— I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation with...
The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109).
Output single integer — answer to the problem.
[ "2 100\n", "5 30\n" ]
[ "33\n", "15\n" ]
In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
1,000
[ { "input": "2 100", "output": "33" }, { "input": "5 30", "output": "15" }, { "input": "42147 412393322", "output": "251637727" }, { "input": "77809 868097296", "output": "440411873" }, { "input": "5105 443422097", "output": "363192634" }, { "input": "7...
1,512,476,742
2,147,483,647
Python 3
OK
TESTS
26
155
5,529,600
k,p=list(map(int,input().split())) a=0 for i in range(1,k+1): s=str(i) a=(a+int(s+s[::-1]))%p print(a)
Title: Chtholly's request Time Limit: None seconds Memory Limit: None megabytes Problem Description: — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thi...
```python k,p=list(map(int,input().split())) a=0 for i in range(1,k+1): s=str(i) a=(a+int(s+s[::-1]))%p print(a) ```
3
166
A
Rank List
PROGRAMMING
1,100
[ "binary search", "implementation", "sortings" ]
null
null
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two give...
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All num...
In the only line print the sought number of teams that got the *k*-th place in the final results' table.
[ "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n" ]
[ "3\n", "4\n" ]
The final results' table for the first sample is: - 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10 The table shows that the se...
500
[ { "input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "output": "3" }, { "input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1", "output": "4" }, { "input": "5 1\n2 2\n1 1\n1 1\n1 1\n2 2", "output": "2" }, { "input": "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5", "output": "1" }, { "i...
1,649,847,883
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
from collections import Counter #x = [1,2,4,5,5,6,6,6] #print(max(Counter(x).values())) n, k = map(int,input().split()) lst = [] problems = [] penalty = [] for i in range(n): n1,n2 = map(int,input().split()) problems.append(int(n1)) penalty.append(int(n2)) print(max(penalty)) penalty = [max(pen...
Title: Rank List Time Limit: None seconds Memory Limit: None megabytes Problem Description: Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for...
```python from collections import Counter #x = [1,2,4,5,5,6,6,6] #print(max(Counter(x).values())) n, k = map(int,input().split()) lst = [] problems = [] penalty = [] for i in range(n): n1,n2 = map(int,input().split()) problems.append(int(n1)) penalty.append(int(n2)) print(max(penalty)) penalty =...
0
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,690,453,685
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
palavra = str(input("Digite uma palavra: ")) maiusculas = 0 minusculas = 0 for i in palavra: if i.islower(): minusculas += 1 elif i.isupper(): maiusculas += 1 if(maiusculas > minusculas): palavra = palavra.upper() elif minusculas > maiusculas: palavra = palavra.lower() else: palavra ...
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 palavra = str(input("Digite uma palavra: ")) maiusculas = 0 minusculas = 0 for i in palavra: if i.islower(): minusculas += 1 elif i.isupper(): maiusculas += 1 if(maiusculas > minusculas): palavra = palavra.upper() elif minusculas > maiusculas: palavra = palavra.lower() else: ...
0
907
A
Masha and Bears
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg...
You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=&gt;<=*V*2<=&gt;<=*V*3.
Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes).
[ "50 30 10 10\n", "100 50 10 21\n" ]
[ "50\n30\n10\n", "-1\n" ]
In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
500
[ { "input": "50 30 10 10", "output": "50\n30\n10" }, { "input": "100 50 10 21", "output": "-1" }, { "input": "100 50 19 10", "output": "100\n50\n19" }, { "input": "99 50 25 49", "output": "100\n99\n49" }, { "input": "3 2 1 1", "output": "4\n3\n1" }, { "...
1,627,286,831
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
62
6,963,200
arr = input().split() a = int(arr[0]) b = int(arr[1]) c = int(arr[2]) d = int(arr[3]) a1 = 2 * a b1 = b * 2 c1 = min(c, d) * 2 if c1 < b1 and c1 >= c and c1 >= d: print(a1) print(b1) print(c1) else: print(-1)
Title: Masha and Bears Time Limit: None seconds Memory Limit: None megabytes Problem Description: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son b...
```python arr = input().split() a = int(arr[0]) b = int(arr[1]) c = int(arr[2]) d = int(arr[3]) a1 = 2 * a b1 = b * 2 c1 = min(c, d) * 2 if c1 < b1 and c1 >= c and c1 >= d: print(a1) print(b1) print(c1) else: print(-1) ```
0
109
A
Lucky Sum of Digits
PROGRAMMING
1,000
[ "brute force", "implementation" ]
A. Lucky Sum of Digits
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. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi...
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
[ "11\n", "10\n" ]
[ "47\n", "-1\n" ]
none
500
[ { "input": "11", "output": "47" }, { "input": "10", "output": "-1" }, { "input": "64", "output": "4477777777" }, { "input": "1", "output": "-1" }, { "input": "4", "output": "4" }, { "input": "7", "output": "7" }, { "input": "12", "outpu...
1,587,709,211
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
186
0
from sys import stdin , stdout num = int(stdin.readline()) count7=0 count4=0 while(num>0): #print(num) if num >= 7: num = num - 7 count7+=1 #print(num) if num < 7: num = num -4 count4+=1 #print(num) if num < 0: stdout.write...
Title: Lucky Sum of Digits 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 from sys import stdin , stdout num = int(stdin.readline()) count7=0 count4=0 while(num>0): #print(num) if num >= 7: num = num - 7 count7+=1 #print(num) if num < 7: num = num -4 count4+=1 #print(num) if num < 0: st...
0
452
C
Magic Trick
PROGRAMMING
2,100
[ "combinatorics", "math", "probabilities" ]
null
null
Alex enjoys performing magic tricks. He has a trick that requires a deck of *n* cards. He has *m* identical decks of *n* different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs *n* cards at random and performs the trick with those. The resulting deck looks like a normal dec...
First line of the input consists of two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000), separated by space — number of cards in each deck, and number of decks.
On the only line of the output print one floating point number – probability of Alex successfully performing the trick. Relative or absolute error of your answer should not be higher than 10<=-<=6.
[ "2 2\n", "4 4\n", "1 2\n" ]
[ "0.6666666666666666\n", "0.4000000000000000\n", "1.0000000000000000\n" ]
In the first sample, with probability <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/64c94d13eeb330b494061e86538db66574ad0f7d.png" style="max-width: 100.0%;max-height: 100.0%;"/> Alex will perform the trick with two cards with the same value from two different decks. In this case the trick...
1,000
[ { "input": "2 2", "output": "0.6666666666666666" }, { "input": "4 4", "output": "0.4000000000000000" }, { "input": "1 2", "output": "1.0000000000000000" }, { "input": "2 1", "output": "0.5000000000000000" }, { "input": "10 10", "output": "0.1818181818181818" ...
1,406,539,095
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
61
0
def C(a,b): return fact(a)/fact(b)/fact(a-b) def fact(a): res=1 for i in range(2,a+1): res*=i return res n,m=map(int,input().split()) ans=0 for i in range(m+1): ans += min((1.0 * i) / n, 1.0) * (C(n, i) / ((n * (m + 1)) / 2)); print(ans)
Title: Magic Trick Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alex enjoys performing magic tricks. He has a trick that requires a deck of *n* cards. He has *m* identical decks of *n* different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs ...
```python def C(a,b): return fact(a)/fact(b)/fact(a-b) def fact(a): res=1 for i in range(2,a+1): res*=i return res n,m=map(int,input().split()) ans=0 for i in range(m+1): ans += min((1.0 * i) / n, 1.0) * (C(n, i) / ((n * (m + 1)) / 2)); print(ans) ```
0
515
C
Drazil and Factorial
PROGRAMMING
1,400
[ "greedy", "math", "sortings" ]
null
null
Drazil is playing a math game with Varda. Let's define for positive integer *x* as a product of factorials of its digits. For example, . First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they shoul...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*. The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes.
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
[ "4\n1234\n", "3\n555\n" ]
[ "33222\n", "555\n" ]
In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "4\n1234", "output": "33222" }, { "input": "3\n555", "output": "555" }, { "input": "15\n012345781234578", "output": "7777553333222222222222" }, { "input": "1\n8", "output": "7222" }, { "input": "10\n1413472614", "output": "75333332222222" }, { ...
1,620,844,890
2,147,483,647
PyPy 3
OK
TESTS
45
108
20,172,800
import sys import math input = sys.stdin.readline def primefactors(n): l = [] while n % 2 == 0: l.append(2) n = n // 2 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: l.append(i) n = n // i if n > 2: l.append(n) ...
Title: Drazil and Factorial Time Limit: None seconds Memory Limit: None megabytes Problem Description: Drazil is playing a math game with Varda. Let's define for positive integer *x* as a product of factorials of its digits. For example, . First, they choose a decimal number *a* consisting of *n* digits that cont...
```python import sys import math input = sys.stdin.readline def primefactors(n): l = [] while n % 2 == 0: l.append(2) n = n // 2 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: l.append(i) n = n // i if n > 2: l.ap...
3
199
A
Hexadecimal's theorem
PROGRAMMING
900
[ "brute force", "constructive algorithms", "implementation", "number theory" ]
null
null
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F...
The input contains of a single integer *n* (0<=≤<=*n*<=&lt;<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number.
Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them.
[ "3\n", "13\n" ]
[ "1 1 1\n", "2 3 8\n" ]
none
500
[ { "input": "3", "output": "1 1 1" }, { "input": "13", "output": "2 3 8" }, { "input": "0", "output": "0 0 0" }, { "input": "1", "output": "1 0 0" }, { "input": "2", "output": "1 1 0" }, { "input": "1597", "output": "233 377 987" }, { "input...
1,613,328,322
2,147,483,647
Python 3
OK
TESTS
54
124
0
print(0,0,int(input()))
Title: Hexadecimal's theorem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let'...
```python print(0,0,int(input())) ```
3
834
A
The Useless Toy
PROGRAMMING
900
[ "implementation" ]
null
null
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption. Spinners in Sweetland have the form of V-shaped pieces of caramel. Each s...
There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), &lt; (ASCII code 60), ^ (ASCII code 94) or &gt; (ASCII code 62) (see the picture above for reference). Characters are separated...
Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.
[ "^ &gt;\n1\n", "&lt; ^\n3\n", "^ v\n6\n" ]
[ "cw\n", "ccw\n", "undefined\n" ]
none
500
[ { "input": "^ >\n1", "output": "cw" }, { "input": "< ^\n3", "output": "ccw" }, { "input": "^ v\n6", "output": "undefined" }, { "input": "^ >\n999999999", "output": "ccw" }, { "input": "> v\n1", "output": "cw" }, { "input": "v <\n1", "output": "cw" ...
1,603,438,185
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
77
0
dirs = ['v','<','^','>'] a,b = map(dirs.index(), input().split()) k = (b-a+4)%4 n = int(input()) if k==0 or k==2: print('undefined') elif k==n%4: print('cw') else: print('ccw')
Title: The Useless Toy Time Limit: None seconds Memory Limit: None megabytes Problem Description: Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bough...
```python dirs = ['v','<','^','>'] a,b = map(dirs.index(), input().split()) k = (b-a+4)%4 n = int(input()) if k==0 or k==2: print('undefined') elif k==n%4: print('cw') else: print('ccw') ```
-1
371
A
K-Periodic Array
PROGRAMMING
1,000
[ "greedy", "implementation", "math" ]
null
null
This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2. Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represented by array *b* written exactly times consecutively. In other words, array *a* is *k*-periodic, if it...
The first line of the input contains a pair of integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100), where *n* is the length of the array and the value *n* is divisible by *k*. The second line contains the sequence of elements of the given array *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), *a**i* is the *i*-th element of ...
Print the minimum number of array elements we need to change to make the array *k*-periodic. If the array already is *k*-periodic, then print 0.
[ "6 2\n2 1 2 2 2 1\n", "8 4\n1 1 2 1 1 1 2 1\n", "9 3\n2 1 1 1 2 1 1 1 2\n" ]
[ "1\n", "0\n", "3\n" ]
In the first sample it is enough to change the fourth element from 2 to 1, then the array changes to [2, 1, 2, 1, 2, 1]. In the second sample, the given array already is 4-periodic. In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as [1, 1, 1, 1...
500
[ { "input": "6 2\n2 1 2 2 2 1", "output": "1" }, { "input": "8 4\n1 1 2 1 1 1 2 1", "output": "0" }, { "input": "9 3\n2 1 1 1 2 1 1 1 2", "output": "3" }, { "input": "1 1\n2", "output": "0" }, { "input": "2 1\n1 1", "output": "0" }, { "input": "2 2\n2 2...
1,658,682,431
2,147,483,647
PyPy 3
OK
TESTS
24
77
0
I=lambda:map(int,input().split()) n,k=I() a=[0]*n i=0 for v in I():a[i]+=v-1;i=(i+1)%k print(sum(map(lambda x:min(x,n//k-x),a)))
Title: K-Periodic Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2. Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represent...
```python I=lambda:map(int,input().split()) n,k=I() a=[0]*n i=0 for v in I():a[i]+=v-1;i=(i+1)%k print(sum(map(lambda x:min(x,n//k-x),a))) ```
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,672,318,703
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
6
92
0
from sys import exit n=int(input()) s=input() z=list(s) if len(s)%n!=0: print (-1) exit() o=sorted(z) f=[o.count(o[0])] a=[] for i in o: if i not in a: a.append(i) if o.count(i)!=f[0]: print( -1) exit() p='' x=int(o.count(a[0])/n) for i in range(len(...
Title: k-String Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ...
```python from sys import exit n=int(input()) s=input() z=list(s) if len(s)%n!=0: print (-1) exit() o=sorted(z) f=[o.count(o[0])] a=[] for i in o: if i not in a: a.append(i) if o.count(i)!=f[0]: print( -1) exit() p='' x=int(o.count(a[0])/n) for i in ...
0
235
A
LCM Challenge
PROGRAMMING
1,600
[ "number theory" ]
null
null
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it. But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find ...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement.
Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*.
[ "9\n", "7\n" ]
[ "504\n", "210\n" ]
The least common multiple of some positive integers is the least positive integer which is multiple for each of them. The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended. For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is ...
500
[ { "input": "9", "output": "504" }, { "input": "7", "output": "210" }, { "input": "1", "output": "1" }, { "input": "5", "output": "60" }, { "input": "6", "output": "60" }, { "input": "33", "output": "32736" }, { "input": "21", "output": ...
1,619,598,646
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
218
0
from math import gcd def lcm(a,b): return (a*b)//gcd(a,b) n=int(input()) print(lcm(lcm(n,n-1),n-2))
Title: LCM Challenge Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it. But I also don't want to use many numbers, so I'll choose three positive...
```python from math import gcd def lcm(a,b): return (a*b)//gcd(a,b) n=int(input()) print(lcm(lcm(n,n-1),n-2)) ```
0
305
C
Ivan and Powers of Two
PROGRAMMING
1,600
[ "greedy", "implementation" ]
null
null
Ivan has got an array of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2*a*1,<=2*a*2,<=...,<=2*a**n* on a piece of paper. Now he wonders, what minimum number of integers of form 2*b* (*b*<=≥<=0) need to be added to the pi...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second input line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·109). It is guaranteed that *a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*.
Print a single integer — the answer to the problem.
[ "4\n0 1 1 1\n", "1\n3\n" ]
[ "0\n", "3\n" ]
In the first sample you do not need to add anything, the sum of numbers already equals 2<sup class="upper-index">3</sup> - 1 = 7. In the second sample you need to add numbers 2<sup class="upper-index">0</sup>, 2<sup class="upper-index">1</sup>, 2<sup class="upper-index">2</sup>.
1,500
[ { "input": "4\n0 1 1 1", "output": "0" }, { "input": "1\n3", "output": "3" }, { "input": "1\n0", "output": "0" }, { "input": "1\n2000000000", "output": "2000000000" }, { "input": "1\n1", "output": "1" }, { "input": "26\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
1,554,170,524
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
500
6,656,000
n = int(input()) ant = 0 v = input().split() s = 0 for i in v: s += 2**int(i) s = bin(s) s = list((s))[2:] resp = 0 for i in s: if(i == '0'): resp+=1 print(resp)
Title: Ivan and Powers of Two Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan has got an array of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2*a*1,<=2*a*2,<=...,<=2*a**n* on a piece o...
```python n = int(input()) ant = 0 v = input().split() s = 0 for i in v: s += 2**int(i) s = bin(s) s = list((s))[2:] resp = 0 for i in s: if(i == '0'): resp+=1 print(resp) ```
0
331
D1
Escaping on Beaveractor
PROGRAMMING
2,400
[ "dfs and similar", "implementation" ]
null
null
Don't put up with what you're sick of! The Smart Beaver decided to escape from the campus of Beaver Science Academy (BSA). BSA is a *b*<=×<=*b* square on a plane. Each point *x*,<=*y* (0<=≤<=*x*,<=*y*<=≤<=*b*) belongs to BSA. To make the path quick and funny, the Beaver constructed a Beaveractor, an effective and comfo...
The first line contains two integers: the number of traffic rules *n* and the size of the campus *b*, 0<=≤<=*n*, 1<=≤<=*b*. Next *n* lines contain the rules. Each line of the rules contains four space-separated integers *x*0, *y*0, *x*1, *y*1 — the beginning and the end of the arrow. It is guaranteed that all arrows ar...
Print *q* lines. Each line should contain two integers — the Beaveractor's coordinates at the final moment of time for each plan. If the Smart Beaver manages to leave the campus in time *t**i*, print the coordinates of the last point in the campus he visited.
[ "3 3\n0 0 0 1\n0 2 2 2\n3 3 2 3\n12\n0 0 L 0\n0 0 L 1\n0 0 L 2\n0 0 L 3\n0 0 L 4\n0 0 L 5\n0 0 L 6\n2 0 U 2\n2 0 U 3\n3 0 U 5\n1 3 D 2\n1 3 R 2\n" ]
[ "0 0\n0 1\n0 2\n1 2\n2 2\n3 2\n3 2\n2 2\n3 2\n1 3\n2 2\n1 3\n" ]
none
30
[]
1,680,714,189
189
PyPy 3-64
WRONG_ANSWER
TESTS1
5
3,462
62,771,200
"""Railway construction Recursive algorithm """ import logging from functools import lru_cache, partial from typing import Dict, List, Literal, Optional, Tuple DirectionType = Literal["U", "D", "L", "R"] PositionType = Tuple[int, int] RuleType = Tuple[PositionType, PositionType] PlanType = Tuple[PositionType, str, in...
Title: Escaping on Beaveractor Time Limit: None seconds Memory Limit: None megabytes Problem Description: Don't put up with what you're sick of! The Smart Beaver decided to escape from the campus of Beaver Science Academy (BSA). BSA is a *b*<=×<=*b* square on a plane. Each point *x*,<=*y* (0<=≤<=*x*,<=*y*<=≤<=*b*) b...
```python """Railway construction Recursive algorithm """ import logging from functools import lru_cache, partial from typing import Dict, List, Literal, Optional, Tuple DirectionType = Literal["U", "D", "L", "R"] PositionType = Tuple[int, int] RuleType = Tuple[PositionType, PositionType] PlanType = Tuple[PositionTyp...
0
903
A
Hungry Student Problem
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken. CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly ...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases. The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat.
Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO.
[ "2\n6\n5\n" ]
[ "YES\nNO\n" ]
In the first example Ivan can buy two small portions. In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
0
[ { "input": "2\n6\n5", "output": "YES\nNO" }, { "input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\...
1,580,635,066
166
Python 3
OK
TESTS
8
109
307,200
for _ in " "*int(input()):print("NO" if int(input()) in [2,5,11,4,1,8] else "YES")
Title: Hungry Student Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken. CFK sells chicken chunks in small and large portions. A small portion contains 3 chun...
```python for _ in " "*int(input()):print("NO" if int(input()) in [2,5,11,4,1,8] else "YES") ```
3
463
D
Gargari and Permutations
PROGRAMMING
1,900
[ "dfs and similar", "dp", "graphs", "implementation" ]
null
null
Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found *k* permutations. Each of them consists of numbers 1,<=2,<=...,<=*n* in some order. Now he should find the length of the longest common subsequence of these permutatio...
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1000; 2<=≤<=*k*<=≤<=5). Each of the next *k* lines contains integers 1,<=2,<=...,<=*n* in some order — description of the current permutation.
Print the length of the longest common subsequence.
[ "4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3\n" ]
[ "3\n" ]
The answer for the first test sample is subsequence [1, 2, 3].
2,000
[ { "input": "4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3", "output": "3" }, { "input": "6 3\n2 5 1 4 6 3\n5 1 4 3 2 6\n5 4 2 6 3 1", "output": "3" }, { "input": "41 4\n24 15 17 35 13 41 4 14 23 5 8 16 21 18 30 36 6 22 11 29 26 1 40 31 7 3 32 10 28 38 12 20 39 37 34 19 33 27 2 25 9\n22 13 25 24 38 35 2...
1,699,101,867
2,147,483,647
PyPy 3-64
OK
TESTS
40
93
4,403,200
n, k = map(int, input().split()) a = [[]]*6 b = [] for i in range(6): b.append([0]*(n + 1)) for i in range(k): a[i] = list(map(int, input().split())) for j in range(n): b[i][a[i][j]] = j dp = [1] * n for i in range(n): for j in range(i): key = 1 for t in range(1,...
Title: Gargari and Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found *k* permutations. Each of them consists of numbers 1,<=2,...
```python n, k = map(int, input().split()) a = [[]]*6 b = [] for i in range(6): b.append([0]*(n + 1)) for i in range(k): a[i] = list(map(int, input().split())) for j in range(n): b[i][a[i][j]] = j dp = [1] * n for i in range(n): for j in range(i): key = 1 for t i...
3
998
B
Cutting
PROGRAMMING
1,200
[ "dp", "greedy", "sortings" ]
null
null
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers. There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulti...
First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have. Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal...
Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins.
[ "6 4\n1 2 5 10 15 20\n", "4 10\n1 3 2 4\n", "6 100\n1 2 3 4 5 6\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins. In the second sample it is not possible to make even one cut even with unlimited number of bitcoins. In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$....
1,000
[ { "input": "6 4\n1 2 5 10 15 20", "output": "1" }, { "input": "4 10\n1 3 2 4", "output": "0" }, { "input": "6 100\n1 2 3 4 5 6", "output": "2" }, { "input": "2 100\n13 78", "output": "0" }, { "input": "10 1\n56 56 98 2 11 64 97 41 95 53", "output": "0" }, ...
1,532,578,662
2,147,483,647
Python 3
OK
TESTS
34
124
0
n, b = map(int,input().split()) v = list(map(int,input().split())) costs = [] odds = 0 evens = 0 for i in range(n-1): if v[i] % 2 == 0: evens += 1 else: odds += 1 if odds == evens and odds != 0 and i != (n-1): costs.append(abs(v[i+1]-v[i])) odds = 0 evens = 0 count...
Title: Cutting Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers. There is a sequence of integers, which contains the equal number of even and odd numbers. Gi...
```python n, b = map(int,input().split()) v = list(map(int,input().split())) costs = [] odds = 0 evens = 0 for i in range(n-1): if v[i] % 2 == 0: evens += 1 else: odds += 1 if odds == evens and odds != 0 and i != (n-1): costs.append(abs(v[i+1]-v[i])) odds = 0 evens ...
3
4
A
Watermelon
PROGRAMMING
800
[ "brute force", "math" ]
A. Watermelon
1
64
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and ...
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
[ "8\n" ]
[ "YES\n" ]
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
0
[ { "input": "8", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "7", "output": "NO"...
1,691,222,195
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
def fn(n): s="NO" if n%2==0: s= "YES" return s
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin...
```python def fn(n): s="NO" if n%2==0: s= "YES" return s ```
0
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,682,109,115
2,147,483,647
Python 3
OK
TESTS
102
62
0
stri1 = input() stri2 = input() solut = [] for i in range(len(stri1)): if stri1[i] == stri2[i]: solut.append("0") else: solut.append("1") print("".join(solut))
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 stri1 = input() stri2 = input() solut = [] for i in range(len(stri1)): if stri1[i] == stri2[i]: solut.append("0") else: solut.append("1") print("".join(solut)) ```
3.9845
697
A
Pineapple Incident
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc. Barney woke up in the morn...
The first and only line of input contains three integers *t*, *s* and *x* (0<=≤<=*t*,<=*x*<=≤<=109, 2<=≤<=*s*<=≤<=109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively.
Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output.
[ "3 10 4\n", "3 10 3\n", "3 8 51\n", "3 8 52\n" ]
[ "NO\n", "YES\n", "YES\n", "YES\n" ]
In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3. In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and ...
500
[ { "input": "3 10 4", "output": "NO" }, { "input": "3 10 3", "output": "YES" }, { "input": "3 8 51", "output": "YES" }, { "input": "3 8 52", "output": "YES" }, { "input": "456947336 740144 45", "output": "NO" }, { "input": "33 232603 599417964", "ou...
1,672,196,973
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
[t,s,x] = map(int, input().split()) if x<t: print("no") if x==t: print("no") else: if x==t+1 or s!=1: print("yes") else: if (x-t)%s==0 or (x-t)%s==1 : print("yes") else: print("no")
Title: Pineapple Incident Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times...
```python [t,s,x] = map(int, input().split()) if x<t: print("no") if x==t: print("no") else: if x==t+1 or s!=1: print("yes") else: if (x-t)%s==0 or (x-t)%s==1 : print("yes") else: print("no") ```
0
538
A
Cutting Banner
PROGRAMMING
1,400
[ "brute force", "implementation" ]
null
null
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case ...
The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES.
Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).
[ "CODEWAITFORITFORCES\n", "BOTTOMCODER\n", "DECODEFORCES\n", "DOGEFORCES\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n" ]
none
500
[ { "input": "CODEWAITFORITFORCES", "output": "YES" }, { "input": "BOTTOMCODER", "output": "NO" }, { "input": "DECODEFORCES", "output": "YES" }, { "input": "DOGEFORCES", "output": "NO" }, { "input": "ABACABA", "output": "NO" }, { "input": "CODEFORCE", ...
1,629,382,578
2,147,483,647
Python 3
OK
TESTS
55
78
6,758,400
# Problem: A. Cutting Banner # Contest: Codeforces - Codeforces Round #300 # URL: https://codeforces.com/contest/538/problem/A # Memory Limit: 256 MB # Time Limit: 2000 ms # Powered by CP Editor (https://github.com/cpeditor/cpeditor) from sys import stdin def get_ints(): return list(map(int, stdin.readline()...
Title: Cutting Banner Time Limit: None seconds Memory Limit: None megabytes Problem Description: A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody ...
```python # Problem: A. Cutting Banner # Contest: Codeforces - Codeforces Round #300 # URL: https://codeforces.com/contest/538/problem/A # Memory Limit: 256 MB # Time Limit: 2000 ms # Powered by CP Editor (https://github.com/cpeditor/cpeditor) from sys import stdin def get_ints(): return list(map(int, stdin....
3
851
B
Arpa and an exam about geometry
PROGRAMMING
1,400
[ "geometry", "math" ]
null
null
Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points *a*,<=*b*,<=*c*. Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old ...
The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct.
Print "Yes" if the problem has a solution, "No" otherwise. You can print each letter in any case (upper or lower).
[ "0 1 1 1 1 0\n", "1 1 0 0 1000 1000\n" ]
[ "Yes\n", "No\n" ]
In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test, you can't find any solution.
1,000
[ { "input": "0 1 1 1 1 0", "output": "Yes" }, { "input": "1 1 0 0 1000 1000", "output": "No" }, { "input": "1 0 2 0 3 0", "output": "No" }, { "input": "3 4 0 0 4 3", "output": "Yes" }, { "input": "-1000000000 1 0 0 1000000000 1", "output": "Yes" }, { "i...
1,508,530,392
2,147,483,647
Python 3
OK
TESTS
46
61
5,529,600
def main(): ax, ay, bx, by, cx, cy = [int(i) for i in input().split()] if ax*by + bx*cy + cx*ay - bx*ay - cx*by - ax*cy == 0: print("No") elif (bx - ax)**2 + (by - ay)**2 == (cx - bx)**2 + (cy - by)**2: print("Yes") else: print("No") main() # 1508530390696
Title: Arpa and an exam about geometry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points *a*,<=*b*,<=*c*. Find a point and an angle such that if we rotate the page around the point by the angle...
```python def main(): ax, ay, bx, by, cx, cy = [int(i) for i in input().split()] if ax*by + bx*cy + cx*ay - bx*ay - cx*by - ax*cy == 0: print("No") elif (bx - ax)**2 + (by - ay)**2 == (cx - bx)**2 + (cy - by)**2: print("Yes") else: print("No") main() # 1508530390696 ```
3
551
E
GukiZ and GukiZiana
PROGRAMMING
2,500
[ "binary search", "data structures", "implementation" ]
null
null
Professor GukiZ was playing with arrays again and accidentally discovered new function, which he called *GukiZiana*. For given array *a*, indexed with integers from 1 to *n*, and number *y*, *GukiZiana*(*a*,<=*y*) represents maximum value of *j*<=-<=*i*, such that *a**j*<==<=*a**i*<==<=*y*. If there is no *y* as an ele...
The first line contains two integers *n*, *q* (1<=≤<=*n*<=≤<=5<=*<=105,<=1<=≤<=*q*<=≤<=5<=*<=104), size of array *a*, and the number of queries. The second line contains *n* integers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=109), forming an array *a*. Each of next *q* lines contain either four or two numbers, as ...
For each query of type 2, print the value of *GukiZiana*(*a*,<=*y*), for *y* value for that query.
[ "4 3\n1 2 3 4\n1 1 2 1\n1 1 1 1\n2 3\n", "2 3\n1 2\n1 2 2 1\n2 3\n2 4\n" ]
[ "2\n", "0\n-1\n" ]
none
2,500
[ { "input": "4 3\n1 2 3 4\n1 1 2 1\n1 1 1 1\n2 3", "output": "2" }, { "input": "2 3\n1 2\n1 2 2 1\n2 3\n2 4", "output": "0\n-1" }, { "input": "8 5\n1 1 1 2 1 3 1 1\n2 1\n1 1 8 1\n2 2\n1 2 5 2\n2 4", "output": "7\n7\n4" }, { "input": "8 8\n1 9 1 9 2 3 4 5\n1 3 7 1\n2 6\n2 8\n2 ...
1,537,294,388
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
140
0
n, q = map(int, input().split()) a = list(map(int, input().split())) for _ in range(q): inpt = list(map(int, input().split())) if inpt[0] == 1: for i in range(inpt[1], inpt[2] + 1): a[i] += inpt[3] else: i = 0 j = len(a) - 1 while (a[i] != inpt[1]) a...
Title: GukiZ and GukiZiana Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ was playing with arrays again and accidentally discovered new function, which he called *GukiZiana*. For given array *a*, indexed with integers from 1 to *n*, and number *y*, *GukiZiana*(*a*,<=*y*) r...
```python n, q = map(int, input().split()) a = list(map(int, input().split())) for _ in range(q): inpt = list(map(int, input().split())) if inpt[0] == 1: for i in range(inpt[1], inpt[2] + 1): a[i] += inpt[3] else: i = 0 j = len(a) - 1 while (a[i] != ...
0
774
D
Lie or Truth
PROGRAMMING
1,500
[ "*special", "constructive algorithms", "implementation", "sortings" ]
null
null
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,<=*a*2,<=...,<=*a**n*. While Vasya was walking, his little brother Stepan played with Vasya's cub...
The first line contains three integers *n*, *l*, *r* (1<=≤<=*n*<=≤<=105, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of integers written on cubes in the Vasya's order. ...
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
[ "5 2 4\n3 4 2 3 1\n3 2 3 4 1\n", "3 1 2\n1 2 3\n3 1 2\n", "4 2 4\n1 1 1 1\n1 1 1 1\n" ]
[ "TRUTH\n", "LIE\n", "TRUTH\n" ]
In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and...
0
[ { "input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1", "output": "TRUTH" }, { "input": "3 1 2\n1 2 3\n3 1 2", "output": "LIE" }, { "input": "4 2 4\n1 1 1 1\n1 1 1 1", "output": "TRUTH" }, { "input": "5 1 3\n2 2 2 1 2\n2 2 2 1 2", "output": "TRUTH" }, { "input": "7 1 4\n2 5 5 5...
1,686,493,729
2,147,483,647
PyPy 3-64
OK
TESTS
52
140
19,046,400
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb N,L,R = map(int,input().split()) A = list(map(int,input().split())) B = list(map(i...
Title: Lie or Truth Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,...
```python import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb N,L,R = map(int,input().split()) A = list(map(int,input().split())) B = ...
3
818
A
Diplomas and Certificates
PROGRAMMING
800
[ "implementation", "math" ]
null
null
There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and ...
The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas.
Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners.
[ "18 2\n", "9 10\n", "1000000000000 5\n", "1000000000000 499999999999\n" ]
[ "3 6 9\n", "0 0 9\n", "83333333333 416666666665 500000000002\n", "1 499999999999 500000000000\n" ]
none
0
[ { "input": "18 2", "output": "3 6 9" }, { "input": "9 10", "output": "0 0 9" }, { "input": "1000000000000 5", "output": "83333333333 416666666665 500000000002" }, { "input": "1000000000000 499999999999", "output": "1 499999999999 500000000000" }, { "input": "1 1",...
1,516,853,999
2,147,483,647
Python 3
OK
TESTS
44
62
5,632,000
n, k = map(int,input().split()) d = 0 g = 0 nul = n l = 0 r = n while r-l!=1: x = (l+r)//2 if x+x//k<=n//2: if x%k==0: d = x//k g = d*k nul = n - d - g l = x else: r = x d = l//k g = d*k nul = n - d - g pri...
Title: Diplomas and Certificates Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with...
```python n, k = map(int,input().split()) d = 0 g = 0 nul = n l = 0 r = n while r-l!=1: x = (l+r)//2 if x+x//k<=n//2: if x%k==0: d = x//k g = d*k nul = n - d - g l = x else: r = x d = l//k g = d*k nul = n - ...
3
918
A
Eleven
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the ...
The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Print Eleven's new name on the first and only line of output.
[ "8\n", "15\n" ]
[ "OOOoOooO\n", "OOOoOooOooooOoo\n" ]
none
500
[ { "input": "8", "output": "OOOoOooO" }, { "input": "15", "output": "OOOoOooOooooOoo" }, { "input": "85", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo" }, { "input": "381", "output": "OOOoOooOooooOoooooooOooooooooooooOooo...
1,592,548,012
2,147,483,647
PyPy 3
OK
TESTS
18
155
1,433,600
n=int(input()) f=0 s=1 lst=[] while f<=(n+1): lst.append(f) f,s=s,f+s for i in range(1,n+1): if i in lst: print('O',end='') else: print('o',end='') print()
Title: Eleven Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should o...
```python n=int(input()) f=0 s=1 lst=[] while f<=(n+1): lst.append(f) f,s=s,f+s for i in range(1,n+1): if i in lst: print('O',end='') else: print('o',end='') print() ```
3
794
B
Cutting Carrot
PROGRAMMING
1,200
[ "geometry", "math" ]
null
null
Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into *n* pieces of equal area. Formally, the carrot can be viewed as an isosceles tri...
The first and only line of input contains two space-separated integers, *n* and *h* (2<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=105).
The output should contain *n*<=-<=1 real numbers *x*1,<=*x*2,<=...,<=*x**n*<=-<=1. The number *x**i* denotes that the *i*-th cut must be made *x**i* units away from the apex of the carrot. In addition, 0<=&lt;<=*x*1<=&lt;<=*x*2<=&lt;<=...<=&lt;<=*x**n*<=-<=1<=&lt;<=*h* must hold. Your output will be considered correc...
[ "3 2\n", "2 100000\n" ]
[ "1.154700538379 1.632993161855\n", "70710.678118654752\n" ]
Definition of isosceles triangle: [https://en.wikipedia.org/wiki/Isosceles_triangle](https://en.wikipedia.org/wiki/Isosceles_triangle).
1,000
[ { "input": "3 2", "output": "1.154700538379 1.632993161855" }, { "input": "2 100000", "output": "70710.678118654752" }, { "input": "1000 100000", "output": "3162.277660168379 4472.135954999579 5477.225575051661 6324.555320336759 7071.067811865475 7745.966692414834 8366.600265340755 8...
1,647,695,984
2,147,483,647
Python 3
OK
TESTS
31
46
0
from math import sqrt n, h = map(int, input().split()) for i in range(1, n): print(h*sqrt(i/n), end=' ' if i +1 < n else '\n')
Title: Cutting Carrot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cu...
```python from math import sqrt n, h = map(int, input().split()) for i in range(1, n): print(h*sqrt(i/n), end=' ' if i +1 < n else '\n') ```
3
864
B
Polycarp and Letters
PROGRAMMING
1,000
[ "brute force", "implementation", "strings" ]
null
null
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters. Let *A* be a set of positions in the string. Let's call it pretty if following conditions are met: - letters on positions from *A* in the string are all distinct and lowerc...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200) — length of string *s*. The second line contains a string *s* consisting of lowercase and uppercase Latin letters.
Print maximum number of elements in pretty set of positions for string *s*.
[ "11\naaaaBaabAbA\n", "12\nzACaAbbaazzC\n", "3\nABC\n" ]
[ "2\n", "3\n", "0\n" ]
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There...
1,000
[ { "input": "11\naaaaBaabAbA", "output": "2" }, { "input": "12\nzACaAbbaazzC", "output": "3" }, { "input": "3\nABC", "output": "0" }, { "input": "1\na", "output": "1" }, { "input": "2\naz", "output": "2" }, { "input": "200\nXbTJZqcbpYuZQEoUrbxlPXAPCtVLr...
1,506,854,277
2,147,483,647
Python 3
OK
TESTS
55
62
0
n=int(input()) s=input()+'ZZ' j=0 m=0 past=set() for x in range(n+1): if s[x].islower() and s[x] not in past: j+=1 past.add(s[x]) elif s[x].isupper(): m=max(m,j) j=0 past.clear() print(m)
Title: Polycarp and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters. Let *A* be a set of positions in the string. Let's call it pretty if...
```python n=int(input()) s=input()+'ZZ' j=0 m=0 past=set() for x in range(n+1): if s[x].islower() and s[x] not in past: j+=1 past.add(s[x]) elif s[x].isupper(): m=max(m,j) j=0 past.clear() print(m) ```
3
217
A
Ice Skating
PROGRAMMING
1,200
[ "brute force", "dfs and similar", "dsu", "graphs" ]
null
null
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves...
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift. Note that the north direction coinсides with the direction of *Oy* ...
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
[ "2\n2 1\n1 2\n", "2\n2 1\n4 1\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "2\n2 1\n1 2", "output": "1" }, { "input": "2\n2 1\n4 1", "output": "0" }, { "input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182...
1,625,408,805
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
154
0
n = int(input()) listx = [] listy = [] ans = 0 for _ in range(n): x, y = map(int, input().split()) if x not in listx and y not in listy: listx.append(x) listy.append(y) ans += 1 else: listx.append(x) listy.append(y) print(ans -1)
Title: Ice Skating Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha...
```python n = int(input()) listx = [] listy = [] ans = 0 for _ in range(n): x, y = map(int, input().split()) if x not in listx and y not in listy: listx.append(x) listy.append(y) ans += 1 else: listx.append(x) listy.append(y) print(ans -1) ```
0
580
B
Kefa and Company
PROGRAMMING
1,500
[ "binary search", "sortings", "two pointers" ]
null
null
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has *n* friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend...
The first line of the input contains two space-separated integers, *n* and *d* (1<=≤<=*n*<=≤<=105, ) — the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively. Next *n* lines contain the descriptions of Kefa's friends, the (*i*<=+<=1)-th line contains the...
Print the maximum total friendship factir that can be reached.
[ "4 5\n75 5\n0 100\n150 20\n75 1\n", "5 100\n0 7\n11 32\n99 10\n46 8\n87 54\n" ]
[ "100\n", "111\n" ]
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse. In the second sample test we can take all the friends.
1,250
[ { "input": "4 5\n75 5\n0 100\n150 20\n75 1", "output": "100" }, { "input": "5 100\n0 7\n11 32\n99 10\n46 8\n87 54", "output": "111" }, { "input": "1 1000000000\n15 12", "output": "12" }, { "input": "5 1\n5 9\n2 10\n8 5\n18 12\n1 1", "output": "12" }, { "input": "3...
1,688,651,771
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
0
0
def max_friendship_factor(n, d, friends): max_friendship_factor = 0 cumulative_sum = 0 min_money = min(friends, key=lambda x: x[0])[0] prefix_sums = [0] for i in range(n): cumulative_sum += friends[i][1] prefix_sums.append(cumulative_sum) left = 0 right = n ...
Title: Kefa and Company Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has *n* friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the a...
```python def max_friendship_factor(n, d, friends): max_friendship_factor = 0 cumulative_sum = 0 min_money = min(friends, key=lambda x: x[0])[0] prefix_sums = [0] for i in range(n): cumulative_sum += friends[i][1] prefix_sums.append(cumulative_sum) left = 0 right...
0
611
A
New Year and Days
PROGRAMMING
900
[ "implementation" ]
null
null
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015. Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016. Limak wants to prove how responsible a bear he is. He is going to regularly save candies for ...
The only line of the input is in one of the following two formats: - "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month.
Print one integer — the number of candies Limak will save in the year 2016.
[ "4 of week\n", "30 of month\n" ]
[ "52\n", "11\n" ]
Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday. In the first sample Limak wants to sav...
500
[ { "input": "4 of week", "output": "52" }, { "input": "30 of month", "output": "11" }, { "input": "17 of month", "output": "12" }, { "input": "31 of month", "output": "7" }, { "input": "6 of week", "output": "53" }, { "input": "1 of week", "output":...
1,451,491,821
3,921
Python 3
WRONG_ANSWER
PRETESTS
4
46
0
def month(a): return { '31': 7, '30': 11, }.get(a,12) def week(a): return{ '1': 53, '2': 53, }.get(a,52) a,b,s=input().split() if(s=="month"): print(month(a)) else: print(week(a))
Title: New Year and Days Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015. Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming ye...
```python def month(a): return { '31': 7, '30': 11, }.get(a,12) def week(a): return{ '1': 53, '2': 53, }.get(a,52) a,b,s=input().split() if(s=="month"): print(month(a)) else: print(week(a)) ```
0
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they...
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "...
1,686,238,453
2,147,483,647
Python 3
OK
TESTS
48
46
0
x1, x2, x3 = map(int, input().split()) coordinates = [x1, x2, x3] coordinates.sort() median = coordinates[1] total_distance = abs(x1 - median) + abs(x2 - median) + abs(x3 - median) print(total_distance)
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ...
```python x1, x2, x3 = map(int, input().split()) coordinates = [x1, x2, x3] coordinates.sort() median = coordinates[1] total_distance = abs(x1 - median) + abs(x2 - median) + abs(x3 - median) print(total_distance) ```
3
3
C
Tic-tac-toe
PROGRAMMING
1,800
[ "brute force", "games", "implementation" ]
C. Tic-tac-toe
1
64
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the...
The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero).
Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw.
[ "X0X\n.0.\n.X.\n" ]
[ "second\n" ]
none
0
[ { "input": "X0X\n.0.\n.X.", "output": "second" }, { "input": "0.X\nXX.\n000", "output": "illegal" }, { "input": "XXX\n.0.\n000", "output": "illegal" }, { "input": "XXX\n...\n000", "output": "illegal" }, { "input": "X.X\nX..\n00.", "output": "second" }, { ...
1,539,878,207
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
218
0
l1=input() l2=input() l3=input() l = l1+l2+l3 co = 0 cx = 0 i = 0 while(i<9): char = l[i] if char == 'X': cx=cx+1 if char == '0': co=co+1 i=i+1 cd = 9 - (cx+co) if (co <= cx-2 )or ((cx+cd+co) != 9) or (co>cx): print("illegal") elif ((l[0]+l[1]+l[2])=="000") or ((l[3]...
Title: Tic-tac-toe Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds ...
```python l1=input() l2=input() l3=input() l = l1+l2+l3 co = 0 cx = 0 i = 0 while(i<9): char = l[i] if char == 'X': cx=cx+1 if char == '0': co=co+1 i=i+1 cd = 9 - (cx+co) if (co <= cx-2 )or ((cx+cd+co) != 9) or (co>cx): print("illegal") elif ((l[0]+l[1]+l[2])=="000")...
0
570
A
Elections
PROGRAMMING
1,100
[ "implementation" ]
null
null
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in ...
The first line of the input contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of candidates and of cities, respectively. Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*j*<=≤<=*n*, 1<=≤<=*i*<=≤<=*m*, 0<=≤<=*a**ij*<=≤<=109) denotes ...
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
[ "3 3\n1 2 3\n2 3 1\n1 2 1\n", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n" ]
[ "2", "1" ]
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm...
500
[ { "input": "3 3\n1 2 3\n2 3 1\n1 2 1", "output": "2" }, { "input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "output": "1" }, { "input": "1 3\n5\n3\n2", "output": "1" }, { "input": "3 1\n1 2 3", "output": "3" }, { "input": "3 1\n100 100 100", "output": "1" }, {...
1,552,714,174
2,147,483,647
Python 3
OK
TESTS
62
109
0
m, n = input().split() cand = [] for i in range (int(m)): cand.append(0) for i in range (int(n)): a = [int(x) for x in input().split()] cand[a.index(max(a))] += 1 print(cand.index(max(cand)) + 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 m, n = input().split() cand = [] for i in range (int(m)): cand.append(0) for i in range (int(n)): a = [int(x) for x in input().split()] cand[a.index(max(a))] += 1 print(cand.index(max(cand)) + 1) ```
3
1,007
A
Reorder the Array
PROGRAMMING
1,300
[ "combinatorics", "data structures", "math", "sortings", "two pointers" ]
null
null
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $[10, 20, 30, 40]$, we can ...
The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array.
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
[ "7\n10 1 1 1 5 5 3\n", "5\n1 1 1 1 1\n" ]
[ "4\n", "0\n" ]
In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4. In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
500
[ { "input": "7\n10 1 1 1 5 5 3", "output": "4" }, { "input": "5\n1 1 1 1 1", "output": "0" }, { "input": "6\n300000000 200000000 300000000 200000000 1000000000 300000000", "output": "3" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "9" }, { "input": "1\n1", ...
1,664,990,151
2,147,483,647
PyPy 3-64
OK
TESTS
33
93
20,070,400
# from heapq import * # from collections import deque def lets_do_it(): n = int(input()) count = {} for a in input().split(): a = int(a) count[a] = count.get(a, 0) + 1 max_val = 0 for value in count.values(): max_val = max(max_val, value) print(n - max_val) def main(...
Title: Reorder the Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find t...
```python # from heapq import * # from collections import deque def lets_do_it(): n = int(input()) count = {} for a in input().split(): a = int(a) count[a] = count.get(a, 0) + 1 max_val = 0 for value in count.values(): max_val = max(max_val, value) print(n - max_val) ...
3