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
545
C
Woodcutters
PROGRAMMING
1,500
[ "dp", "greedy" ]
null
null
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees. Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree. The pairs are given in the order of ascending *x**i*. No two trees are located at the point with t...
Print a single number — the maximum number of trees that you can cut down by the given rules.
[ "5\n1 2\n2 1\n5 10\n10 9\n19 1\n", "5\n1 2\n2 1\n5 10\n10 9\n20 1\n" ]
[ "3\n", "4\n" ]
In the first sample you can fell the trees like that: - fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — ...
1,750
[ { "input": "5\n1 2\n2 1\n5 10\n10 9\n19 1", "output": "3" }, { "input": "5\n1 2\n2 1\n5 10\n10 9\n20 1", "output": "4" }, { "input": "4\n10 4\n15 1\n19 3\n20 1", "output": "4" }, { "input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10...
1,685,292,862
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> using namespace std; using ll = long long; ll n; vector<vector<ll>> trees; ll dfs(ll i, ll l, ll r) { // cout << i << " " << l << " " << r << '\n'; ll ans = 0; if (i+1 == n) return 0; i += 1; ll x, h; x = trees[i][0]; h = trees[i][1]; ...
Title: Woodcutters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described b...
```python #include <bits/stdc++.h> using namespace std; using ll = long long; ll n; vector<vector<ll>> trees; ll dfs(ll i, ll l, ll r) { // cout << i << " " << l << " " << r << '\n'; ll ans = 0; if (i+1 == n) return 0; i += 1; ll x, h; x = trees[i][0]; h = tree...
-1
99
B
Help Chef Gerasim
PROGRAMMING
1,300
[ "implementation", "sortings" ]
B. Help Chef Gerasim
0
256
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup...
The first line contains integer *n* — the number of cups on the royal table (1<=≤<=*n*<=≤<=1000). Next *n* lines contain volumes of juice in each cup — non-negative integers, not exceeding 104.
If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "*v* ml. from cup #*a* to cup #*b*." (without the quotes), where *v* represents the volume of poured juice, *a* represents the number of the cup from...
[ "5\n270\n250\n250\n230\n250\n", "5\n250\n250\n250\n250\n250\n", "5\n270\n250\n249\n230\n250\n" ]
[ "20 ml. from cup #4 to cup #1.\n", "Exemplary pages.\n", "Unrecoverable configuration.\n" ]
none
1,000
[ { "input": "5\n270\n250\n250\n230\n250", "output": "20 ml. from cup #4 to cup #1." }, { "input": "5\n250\n250\n250\n250\n250", "output": "Exemplary pages." }, { "input": "5\n270\n250\n249\n230\n250", "output": "Unrecoverable configuration." }, { "input": "4\n200\n190\n210\n20...
1,693,454,296
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
2
93
2,048,000
n = int(input()) arr = [] for _ in range(n): arr.append(int(input())) juice_amount = sum(arr) / len(arr) arr_dict = {} for element in arr: arr_dict[element] = arr_dict.get(element, 0) + 1 if(len(arr_dict) == 1): print("Exemplary pages.") exit() if(arr_dict[juice_amount] != len(arr) - 2): print("Unrecoverable confi...
Title: Help Chef Gerasim Time Limit: 0 seconds Memory Limit: 256 megabytes Problem Description: In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim ...
```python n = int(input()) arr = [] for _ in range(n): arr.append(int(input())) juice_amount = sum(arr) / len(arr) arr_dict = {} for element in arr: arr_dict[element] = arr_dict.get(element, 0) + 1 if(len(arr_dict) == 1): print("Exemplary pages.") exit() if(arr_dict[juice_amount] != len(arr) - 2): print("Unrecover...
-1
766
B
Mahmoud and a Triangle
PROGRAMMING
1,000
[ "constructive algorithms", "geometry", "greedy", "math", "number theory", "sortings" ]
null
null
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments...
The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has.
In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.
[ "5\n1 5 3 2 4\n", "3\n4 1 2\n" ]
[ "YES\n", "NO\n" ]
For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.
1,000
[ { "input": "5\n1 5 3 2 4", "output": "YES" }, { "input": "3\n4 1 2", "output": "NO" }, { "input": "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576", "output": "NO" },...
1,651,803,289
2,147,483,647
PyPy 3-64
OK
TESTS
87
156
16,691,200
n = int(input()) a = list(map(int, input().split())) a.sort() # print(a) f = 0 for i in range(2, n): if a[i]<a[i-1]+a[i-2]: f = 1 break if f: print("YES") else: print("NO")
Title: Mahmoud and a Triangle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he ca...
```python n = int(input()) a = list(map(int, input().split())) a.sort() # print(a) f = 0 for i in range(2, n): if a[i]<a[i-1]+a[i-2]: f = 1 break if f: print("YES") else: print("NO") ```
3
16
A
Flag
PROGRAMMING
800
[ "implementation" ]
A. Flag
2
64
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be...
The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands ...
Output YES, if the flag meets the new ISO standard, and NO otherwise.
[ "3 3\n000\n111\n222\n", "3 3\n000\n000\n111\n", "3 3\n000\n111\n002\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
0
[ { "input": "3 3\n000\n111\n222", "output": "YES" }, { "input": "3 3\n000\n000\n111", "output": "NO" }, { "input": "3 3\n000\n111\n002", "output": "NO" }, { "input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000...
1,648,672,612
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
#Ejercicio 16A codeforce #este ejercicio las personas ingresan numeros por pantalla y el programa solo dice si esta bien o no listColors = [] matriz = [] equivocacion = 0 filas = input(" ") f = 0 while f<int(filas[0]): colors = input("") listColors.append(colors) for x in range(len(colors)): ...
Title: Flag Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of...
```python #Ejercicio 16A codeforce #este ejercicio las personas ingresan numeros por pantalla y el programa solo dice si esta bien o no listColors = [] matriz = [] equivocacion = 0 filas = input(" ") f = 0 while f<int(filas[0]): colors = input("") listColors.append(colors) for x in range(len(col...
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,622,976,393
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
434
2,150,400
a=input() s=0 for i in a: if i==upper(i): s+=1 if s>len(a)//2: print(upper(a)) else: print(lower(a))
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python a=input() s=0 for i in a: if i==upper(i): s+=1 if s>len(a)//2: print(upper(a)) else: print(lower(a)) ```
-1
22
A
Second Order Statistics
PROGRAMMING
800
[ "brute force" ]
A. Second Order Statistics
2
256
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ...
The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
[ "4\n1 2 2 -4\n", "5\n1 2 3 1 1\n" ]
[ "1\n", "2\n" ]
none
0
[ { "input": "4\n1 2 2 -4", "output": "1" }, { "input": "5\n1 2 3 1 1", "output": "2" }, { "input": "1\n28", "output": "NO" }, { "input": "2\n-28 12", "output": "12" }, { "input": "3\n-83 40 -80", "output": "-80" }, { "input": "8\n93 77 -92 26 21 -48 53 ...
1,595,045,254
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
10
218
6,656,000
""" Author: VISHVESH BHAVSAR :) """ n=int(input()) ar=sorted(set([int(x) for x in input().split()])) if n==1: print("NO") else: #print(ar) print(ar[1])
Title: Second Order Statistics Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis...
```python """ Author: VISHVESH BHAVSAR :) """ n=int(input()) ar=sorted(set([int(x) for x in input().split()])) if n==1: print("NO") else: #print(ar) print(ar[1]) ```
-1
768
B
Code For 1
PROGRAMMING
1,600
[ "constructive algorithms", "dfs and similar", "divide and conquer" ]
null
null
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s...
The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=&lt;<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*. It is guaranteed that *r* is not greater than the length of the final list.
Output the total number of 1s in the range *l* to *r* in the final sequence.
[ "7 2 5\n", "10 3 10\n" ]
[ "4\n", "5\n" ]
Consider first example: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/> Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4. For the second example: <img al...
1,000
[ { "input": "7 2 5", "output": "4" }, { "input": "10 3 10", "output": "5" }, { "input": "56 18 40", "output": "20" }, { "input": "203 40 124", "output": "67" }, { "input": "903316762502 354723010040 354723105411", "output": "78355" }, { "input": "335343...
1,697,702,774
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
def count_ones(n, l, r): def recursive_process(num): if num == 1: return [1] else: half = num // 2 remainder = num % 2 return recursive_process(half) + [remainder] + recursive_process(half) sequence = recursive_process(n) ones_count = 0 fo...
Title: Code For 1 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and ta...
```python def count_ones(n, l, r): def recursive_process(num): if num == 1: return [1] else: half = num // 2 remainder = num % 2 return recursive_process(half) + [remainder] + recursive_process(half) sequence = recursive_process(n) ones_count ...
0
908
A
New Year and Counting Cards
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a c...
The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit.
Print a single integer, the minimum number of cards you must turn over to verify your claim.
[ "ee\n", "z\n", "0ay1\n" ]
[ "2\n", "0\n", "2\n" ]
In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side. In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th...
500
[ { "input": "ee", "output": "2" }, { "input": "z", "output": "0" }, { "input": "0ay1", "output": "2" }, { "input": "0abcdefghijklmnopqrstuvwxyz1234567896", "output": "10" }, { "input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b", "output": "18" }, { "input": "01...
1,564,425,740
2,147,483,647
Python 3
OK
TESTS
38
109
0
n=list(input()) t=['a','e','i','o','u'] count=0 for i in range(len(n)): if n[i] in t and n[i].isdigit()==False: count+=1 if n[i].isdigit() and int(n[i])%2!=0: count+=1 print(count)
Title: New Year and Counting Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each car...
```python n=list(input()) t=['a','e','i','o','u'] count=0 for i in range(len(n)): if n[i] in t and n[i].isdigit()==False: count+=1 if n[i].isdigit() and int(n[i])%2!=0: count+=1 print(count) ```
3
994
A
Fingerprints
PROGRAMMING
800
[ "implementation" ]
null
null
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse...
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen...
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
[ "7 3\n3 5 7 1 6 2 8\n1 2 7\n", "4 4\n3 4 1 0\n0 1 7 9\n" ]
[ "7 1 2\n", "1 0\n" ]
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence. In the second example digits $...
500
[ { "input": "7 3\n3 5 7 1 6 2 8\n1 2 7", "output": "7 1 2" }, { "input": "4 4\n3 4 1 0\n0 1 7 9", "output": "1 0" }, { "input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8", "output": "8 6 4 2" }, { "input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9", "output": "3 7 4 9 0" }, { "...
1,612,405,939
2,147,483,647
PyPy 3
OK
TESTS
31
93
0
n,m=map(int,input().split()) seq=list(map(str,input().split())) fp=list(map(str,input().split())) checklist=[] for number in seq: if(number in fp): checklist.append(number) print(" ".join(checklist))
Title: Fingerprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keyp...
```python n,m=map(int,input().split()) seq=list(map(str,input().split())) fp=list(map(str,input().split())) checklist=[] for number in seq: if(number in fp): checklist.append(number) print(" ".join(checklist)) ```
3
999
A
Mishka and Contest
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses ...
The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are...
Print one integer — the maximum number of problems Mishka can solve.
[ "8 4\n4 2 3 1 5 1 6 4\n", "5 2\n3 1 2 1 3\n", "5 100\n12 34 55 43 21\n" ]
[ "5\n", "0\n", "5\n" ]
In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$. In the second example, M...
0
[ { "input": "8 4\n4 2 3 1 5 1 6 4", "output": "5" }, { "input": "5 2\n3 1 2 1 3", "output": "0" }, { "input": "5 100\n12 34 55 43 21", "output": "5" }, { "input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 1...
1,694,583,597
297
Python 3
OK
TESTS
48
46
0
n, k=map(int, input().split()) l=list(map(int, input().split())) c=0 for i in l: if i<=k: c+=1 else: break if c<n: for i in l[::-1]: if i<=k: c+=1 else: break print(c)
Title: Mishka and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his...
```python n, k=map(int, input().split()) l=list(map(int, input().split())) c=0 for i in l: if i<=k: c+=1 else: break if c<n: for i in l[::-1]: if i<=k: c+=1 else: break print(c) ```
3
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,584,293,651
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
0
num=int(input()) temp=num rev=0 while temp!=0: rev=(rev*10)+(temp%10) temp=temp//10 if num==rev: print("YES") else: print("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 num=int(input()) temp=num rev=0 while temp!=0: rev=(rev*10)+(temp%10) temp=temp//10 if num==rev: print("YES") else: print("NO") ```
0
443
A
Anton and Letters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to ti...
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Print a single number — the number of distinct letters in Anton's set.
[ "{a, b, c}\n", "{b, a, b, a}\n", "{}\n" ]
[ "3\n", "2\n", "0\n" ]
none
500
[ { "input": "{a, b, c}", "output": "3" }, { "input": "{b, a, b, a}", "output": "2" }, { "input": "{}", "output": "0" }, { "input": "{a, a, c, b, b, b, c, c, c, c}", "output": "3" }, { "input": "{a, c, b, b}", "output": "3" }, { "input": "{a, b}", "o...
1,698,257,307
2,147,483,647
Python 3
OK
TESTS
27
46
0
n = input() distinct_characters = set() for char in n: if char.isalnum(): # You can adjust this condition to match your requirements distinct_characters.add(char) count = len(distinct_characters) print(count)
Title: Anton and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi...
```python n = input() distinct_characters = set() for char in n: if char.isalnum(): # You can adjust this condition to match your requirements distinct_characters.add(char) count = len(distinct_characters) print(count) ```
3
845
D
Driving Test
PROGRAMMING
1,800
[ "data structures", "dp", "greedy" ]
null
null
Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types. - speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type); - overtake is allowed: this sign means that ...
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=2·105) — number of events. Each of the next *n* lines starts with integer *t* (1<=≤<=*t*<=≤<=6) — the type of the event. An integer *s* (1<=≤<=*s*<=≤<=300) follows in the query of the first and the third type (if it is the query of first type, then it's ne...
Print the minimal number of road signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view.
[ "11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300\n", "5\n1 100\n3 200\n2\n4\n5\n", "7\n1 20\n2\n6\n4\n6\n6\n2\n" ]
[ "2\n", "0\n", "2\n" ]
In the first example Polycarp should say he didn't notice the "speed limit" sign with the limit of 70 and the second "speed limit" sign with the limit of 120. In the second example Polycarp didn't make any rule violation. In the third example Polycarp should say he didn't notice both "no overtake allowed" that came a...
0
[ { "input": "11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300", "output": "2" }, { "input": "5\n1 100\n3 200\n2\n4\n5", "output": "0" }, { "input": "7\n1 20\n2\n6\n4\n6\n6\n2", "output": "2" }, { "input": "1\n1 100", "output": "0" }, { "input": "2\n1 100\...
1,622,725,702
2,147,483,647
Python 3
OK
TESTS
25
608
1,536,000
n = int(input()) speed_limits = [] obgon = 0 current_speed = 0 count = 0 for i in range(n): event = list(input().split()) if (len(event) == 2): type, x = map(int, event) if type == 1: # 1 изменил скорость на х current_speed = x while len(speed_limits) != 0 and speed...
Title: Driving Test Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types. - speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (c...
```python n = int(input()) speed_limits = [] obgon = 0 current_speed = 0 count = 0 for i in range(n): event = list(input().split()) if (len(event) == 2): type, x = map(int, event) if type == 1: # 1 изменил скорость на х current_speed = x while len(speed_limits) != 0...
3
807
A
Is it rated?
PROGRAMMING
900
[ "implementation", "sortings" ]
null
null
Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ...
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants. Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order...
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
[ "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n", "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n", "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n" ]
[ "rated\n", "unrated\n", "maybe\n" ]
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som...
500
[ { "input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884", "output": "rated" }, { "input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699", "output": "maybe" }, { ...
1,629,530,420
2,147,483,647
PyPy 3
OK
TESTS
150
124
21,708,800
n=int(input()) before,after=[],[] for i in range(n): l=[int(i) for i in input().split()] before.append(l[0]) after.append(l[1]) for i in range(n): if before[i]!=after[i]: print('rated') exit() if after!=sorted(after,reverse=True): print('unrated') exit() print('maybe...
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()) before,after=[],[] for i in range(n): l=[int(i) for i in input().split()] before.append(l[0]) after.append(l[1]) for i in range(n): if before[i]!=after[i]: print('rated') exit() if after!=sorted(after,reverse=True): print('unrated') exit() pr...
3
268
A
Games
PROGRAMMING
800
[ "brute force" ]
null
null
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ...
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
In a single line print the number of games where the host team is going to play in the guest uniform.
[ "3\n1 2\n2 4\n3 4\n", "4\n100 42\n42 100\n5 42\n100 5\n", "2\n1 2\n1 2\n" ]
[ "1\n", "5\n", "0\n" ]
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea...
500
[ { "input": "3\n1 2\n2 4\n3 4", "output": "1" }, { "input": "4\n100 42\n42 100\n5 42\n100 5", "output": "5" }, { "input": "2\n1 2\n1 2", "output": "0" }, { "input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52", "output": "6" }, { "input": "10\n68 42\n1 35\n25 70\n...
1,689,008,474
2,147,483,647
Python 3
OK
TESTS
31
92
0
a = int(input()) H=[] A=[] C=0 for i in range(a): b,c = map(int,input().split()) H.append(b) A.append(c) for i in range(a): for j in range(a): if H[i] == A[j]: C+=1 print(C)
Title: Games Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W...
```python a = int(input()) H=[] A=[] C=0 for i in range(a): b,c = map(int,input().split()) H.append(b) A.append(c) for i in range(a): for j in range(a): if H[i] == A[j]: C+=1 print(C) ```
3
82
A
Double Cola
PROGRAMMING
1,100
[ "implementation", "math" ]
A. Double Cola
1
256
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d...
The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.
Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.
[ "1\n", "6\n", "1802\n" ]
[ "Sheldon\n", "Sheldon\n", "Penny\n" ]
none
500
[ { "input": "1", "output": "Sheldon" }, { "input": "6", "output": "Sheldon" }, { "input": "1802", "output": "Penny" }, { "input": "1", "output": "Sheldon" }, { "input": "2", "output": "Leonard" }, { "input": "3", "output": "Penny" }, { "inpu...
1,589,552,299
2,147,483,647
PyPy 3
OK
TESTS
41
140
20,172,800
n=int(input()) while n>5: n = n - 4 s=n%2 n=(n-s)/2 if n==1: print('Sheldon') if n==2: print('Leonard') if n==3: print('Penny') if n==4: print('Rajesh') if n==5:print('Howard')
Title: Double Cola Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin...
```python n=int(input()) while n>5: n = n - 4 s=n%2 n=(n-s)/2 if n==1: print('Sheldon') if n==2: print('Leonard') if n==3: print('Penny') if n==4: print('Rajesh') if n==5:print('Howard') ```
3.892425
484
A
Bits
PROGRAMMING
1,700
[ "bitmasks", "constructive algorithms" ]
null
null
Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*. You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that *l*<=≤<=*x*<=≤<=*r*, and is maximum possible. If there are multiple such numbers find the...
The first line contains integer *n* — the number of queries (1<=≤<=*n*<=≤<=10000). Each of the following *n* lines contain two integers *l**i*,<=*r**i* — the arguments for the corresponding query (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=1018).
For each query print the answer in a separate line.
[ "3\n1 2\n2 4\n1 10\n" ]
[ "1\n3\n7\n" ]
The binary representations of numbers from 1 to 10 are listed below: 1<sub class="lower-index">10</sub> = 1<sub class="lower-index">2</sub> 2<sub class="lower-index">10</sub> = 10<sub class="lower-index">2</sub> 3<sub class="lower-index">10</sub> = 11<sub class="lower-index">2</sub> 4<sub class="lower-index">10</su...
500
[ { "input": "3\n1 2\n2 4\n1 10", "output": "1\n3\n7" }, { "input": "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n5 7\n5 8\n5 9\n5 10\n6 6\n6 7\n6 8\n6 9\n6 10...
1,681,826,675
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
15
1,000
7,987,200
def check(num): ans = ''.join(num) if f(ans) > r: return False return True def f(s): ans = 0 k = 0 for i in range(len(s)-1, -1, -1): if s[i] == '1': ans += (2**k) k += 1 return ans for _ in range(int(input())): l, r = map(int, inp...
Title: Bits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*. You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that ...
```python def check(num): ans = ''.join(num) if f(ans) > r: return False return True def f(s): ans = 0 k = 0 for i in range(len(s)-1, -1, -1): if s[i] == '1': ans += (2**k) k += 1 return ans for _ in range(int(input())): l, r = ma...
0
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,656,365,754
2,147,483,647
Python 3
OK
TESTS
81
92
0
number=int(input()) l=[] g=0 for i in range(number): a,b,c=map(int,input().split()) if g==0: l.extend((a, b, c)) else: l[0]+=a l[1]+=b l[2]+=c g+=1 if l[0]== 0 and l[1]==0 and l[2]==0: print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python number=int(input()) l=[] g=0 for i in range(number): a,b,c=map(int,input().split()) if g==0: l.extend((a, b, c)) else: l[0]+=a l[1]+=b l[2]+=c g+=1 if l[0]== 0 and l[1]==0 and l[2]==0: print("YES") else: print("NO") ```
3.977
0
none
none
none
0
[ "none" ]
null
null
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made *y* submissions, out of which *x* have been successful. Thus, your current success rate on Codeforces is equal to *x*<=/<=*y*. Your favorite rational number in the [0;1] range is *p*<=/<=*q*. Now you wonde...
The first line contains a single integer *t* (1<=≤<=*t*<=≤<=1000) — the number of test cases. Each of the next *t* lines contains four integers *x*, *y*, *p* and *q* (0<=≤<=*x*<=≤<=*y*<=≤<=109; 0<=≤<=*p*<=≤<=*q*<=≤<=109; *y*<=&gt;<=0; *q*<=&gt;<=0). It is guaranteed that *p*<=/<=*q* is an irreducible fraction. Hacks...
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
[ "4\n3 10 1 2\n7 14 3 8\n20 70 2 7\n5 6 1 1\n" ]
[ "4\n10\n0\n-1\n" ]
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submiss...
0
[ { "input": "4\n3 10 1 2\n7 14 3 8\n20 70 2 7\n5 6 1 1", "output": "4\n10\n0\n-1" }, { "input": "8\n0 1 0 1\n0 2 1 2\n0 3 1 1\n1 2 0 1\n1 2 1 1\n2 2 0 1\n3 3 1 2\n4 4 1 1", "output": "0\n2\n-1\n-1\n-1\n-1\n3\n0" }, { "input": "5\n1 1000000000 1 2\n1 1000000000 1 2\n1 1000000000 1 2\n1 100...
1,593,435,851
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
124
7,065,600
from functools import reduce def gcd(x, y): """greatest common divisor of x and y""" while y: x, y = y, x % y return x def extended_gcd(a, b): """returns gcd(a, b), s, r s.t. a * s + b * r == gcd(a, b)""" s, old_s = 0, 1 r, old_r = b, a while r: q = old_r /...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made *y* submissions, out of which *x* have been successful. Thus, your current success rate on Codeforces is equal to *x...
```python from functools import reduce def gcd(x, y): """greatest common divisor of x and y""" while y: x, y = y, x % y return x def extended_gcd(a, b): """returns gcd(a, b), s, r s.t. a * s + b * r == gcd(a, b)""" s, old_s = 0, 1 r, old_r = b, a while r: q...
-1
811
A
Vladik and Courtesy
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving eac...
Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively.
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
[ "1 1\n", "7 6\n" ]
[ "Valera\n", "Vladik\n" ]
Illustration for first test case: <img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/> Illustration for second test case: <img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e...
500
[ { "input": "1 1", "output": "Valera" }, { "input": "7 6", "output": "Vladik" }, { "input": "25 38", "output": "Vladik" }, { "input": "8311 2468", "output": "Valera" }, { "input": "250708 857756", "output": "Vladik" }, { "input": "957985574 24997558", ...
1,504,801,085
2,147,483,647
PyPy 3
OK
TESTS
42
93
409,600
a, b = [int(x) for x in input().split()] n = 0 s = 0 m = 0 i = 1 while s + i <= a: s += i i += 2 n += 1 s = 0 i = 2 while s + i <= b: s += i i += 2 m += 1 if n > m: print("Valera") else: print("Vladik")
Title: Vladik and Courtesy Time Limit: None seconds Memory Limit: None megabytes Problem Description: At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vla...
```python a, b = [int(x) for x in input().split()] n = 0 s = 0 m = 0 i = 1 while s + i <= a: s += i i += 2 n += 1 s = 0 i = 2 while s + i <= b: s += i i += 2 m += 1 if n > m: print("Valera") else: print("Vladik") ```
3
2
A
Winner
PROGRAMMING
1,500
[ "hashing", "implementation" ]
A. Winner
1
64
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ...
Print the name of the winner.
[ "3\nmike 3\nandrew 5\nmike 2\n", "3\nandrew 3\nandrew 2\nmike 5\n" ]
[ "andrew\n", "andrew\n" ]
none
0
[ { "input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew" }, { "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew" }, { "input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "output": "kaxqybeultn" },...
1,630,595,603
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
6,963,200
r = {} for _ in range(int(input())): n,t = map(str,input().split()) t = int(t) if(n in r): r[n] += int(t) else: r[n] = int(t) r = dict(sorted(r.items(), key=lambda x: x[1], reverse=True)) print(list(r.keys())[0])
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes...
```python r = {} for _ in range(int(input())): n,t = map(str,input().split()) t = int(t) if(n in r): r[n] += int(t) else: r[n] = int(t) r = dict(sorted(r.items(), key=lambda x: x[1], reverse=True)) print(list(r.keys())[0]) ```
0
0
none
none
none
0
[ "none" ]
null
null
Vasya's telephone contains *n* photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo *n*. Similarly, by swiping right from the last photo you reach photo 1. It takes *...
The first line of the input contains 4 integers *n*,<=*a*,<=*b*,<=*T* (1<=≤<=*n*<=≤<=5·105, 1<=≤<=*a*,<=*b*<=≤<=1000, 1<=≤<=*T*<=≤<=109) — the number of photos, time to move from a photo to adjacent, time to change orientation of a photo and time Vasya can spend for watching photo. Second line of the input contains a ...
Output the only integer, the maximum number of photos Vasya is able to watch during those *T* seconds.
[ "4 2 3 10\nwwhw\n", "5 2 4 13\nhhwhh\n", "5 2 4 1000\nhhwhh\n", "3 1 100 10\nwhw\n" ]
[ "2\n", "4\n", "5\n", "0\n" ]
In the first sample test you can rotate the first photo (3 seconds), watch the first photo (1 seconds), move left (2 second), rotate fourth photo (3 seconds), watch fourth photo (1 second). The whole process takes exactly 10 seconds. Note that in the last sample test the time is not enough even to watch the first phot...
0
[ { "input": "4 2 3 10\nwwhw", "output": "2" }, { "input": "5 2 4 13\nhhwhh", "output": "4" }, { "input": "5 2 4 1000\nhhwhh", "output": "5" }, { "input": "3 1 100 10\nwhw", "output": "0" }, { "input": "10 2 3 32\nhhwwhwhwwh", "output": "7" }, { "input":...
1,587,575,069
7,169
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <iostream> #include <bits/stdc++.h> using namespace std; int main(){ int n, a, b, T; cin>>n>>a>>b>>T; string orent; cin>>orent; char oren[orent.length()+1]; strcpy(oren, orent.c_str()); int weights[n]; for(int i = 0; i < n; i++){ if(oren[i] == 'w'){ weig...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya's telephone contains *n* photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reac...
```python #include <iostream> #include <bits/stdc++.h> using namespace std; int main(){ int n, a, b, T; cin>>n>>a>>b>>T; string orent; cin>>orent; char oren[orent.length()+1]; strcpy(oren, orent.c_str()); int weights[n]; for(int i = 0; i < n; i++){ if(oren[i] == 'w'){ ...
-1
913
B
Christmas Spruce
PROGRAMMING
1,200
[ "implementation", "trees" ]
null
null
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there exists a directed edge from *v* to *u*. A vertex is called a leaf if it doesn't have children and has a ...
The first line contains one integer *n* — the number of vertices in the tree (3<=≤<=*n*<=≤<=1<=000). Each of the next *n*<=-<=1 lines contains one integer *p**i* (1<=≤<=*i*<=≤<=*n*<=-<=1) — the index of the parent of the *i*<=+<=1-th vertex (1<=≤<=*p**i*<=≤<=*i*). Vertex 1 is the root. It's guaranteed that the root ha...
Print "Yes" if the tree is a spruce and "No" otherwise.
[ "4\n1\n1\n1\n", "7\n1\n1\n1\n2\n2\n2\n", "8\n1\n1\n1\n1\n3\n3\n3\n" ]
[ "Yes\n", "No\n", "Yes\n" ]
The first example: <img class="tex-graphics" src="https://espresso.codeforces.com/8dd976913226df83d535dfa66193f5525f8471bc.png" style="max-width: 100.0%;max-height: 100.0%;"/> The second example: <img class="tex-graphics" src="https://espresso.codeforces.com/44dad5804f5290a2e026c9c41a15151562df8682.png" style="max-w...
750
[ { "input": "4\n1\n1\n1", "output": "Yes" }, { "input": "7\n1\n1\n1\n2\n2\n2", "output": "No" }, { "input": "8\n1\n1\n1\n1\n3\n3\n3", "output": "Yes" }, { "input": "3\n1\n1", "output": "No" }, { "input": "13\n1\n2\n2\n2\n1\n6\n6\n6\n1\n10\n10\n10", "output": "N...
1,646,828,420
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
if __name__ == '__main__': _n = int(input()) mas = [] flag = True for i in range(_n-1): mas.append(int(input())) help_mas = set(mas) res = [0]*(_n+1) for i in range(len(mas)): if i+2 not in help_mas: res[mas[i]] += 1 for i in res[1:]: if not(i == 3 o...
Title: Christmas Spruce Time Limit: None seconds Memory Limit: None megabytes Problem Description: Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there ex...
```python if __name__ == '__main__': _n = int(input()) mas = [] flag = True for i in range(_n-1): mas.append(int(input())) help_mas = set(mas) res = [0]*(_n+1) for i in range(len(mas)): if i+2 not in help_mas: res[mas[i]] += 1 for i in res[1:]: if no...
0
203
A
Two Problems
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as *x* points for his first contest. But Arkady did not believe his friend's words and decided to check whether Valera could have shown such a result. He knows that the c...
The single line of the input contains six integers *x*,<=*t*,<=*a*,<=*b*,<=*d**a*,<=*d**b* (0<=≤<=*x*<=≤<=600; 1<=≤<=*t*,<=*a*,<=*b*,<=*d**a*,<=*d**b*<=≤<=300) — Valera's result, the contest's duration, the initial cost of the first problem, the initial cost of the second problem, the number of points that the first an...
If Valera could have earned exactly *x* points at a contest, print "YES", otherwise print "NO" (without the quotes).
[ "30 5 20 20 3 5\n", "10 4 100 5 5 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample Valera could have acted like this: he could have submitted the first problem at minute 0 and the second problem — at minute 2. Then the first problem brings him 20 points and the second problem brings him 10 points, that in total gives the required 30 points.
500
[ { "input": "30 5 20 20 3 5", "output": "YES" }, { "input": "10 4 100 5 5 1", "output": "NO" }, { "input": "0 7 30 50 3 4", "output": "YES" }, { "input": "50 10 30 20 1 2", "output": "YES" }, { "input": "40 1 40 5 11 2", "output": "YES" }, { "input": "3...
1,583,080,574
2,147,483,647
Python 3
OK
TESTS
51
248
307,200
x, t, a, b, da, db = map(int, input().split()) A = [0] + [a-i*da for i in range(t)] B = {0} | {b-i*db for i in range(t)} print('YES' if any(x-a in B for a in A) else 'NO')
Title: Two Problems Time Limit: None seconds Memory Limit: None megabytes Problem Description: A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as *x* points for his first contest. But Arkady did not believe his frien...
```python x, t, a, b, da, db = map(int, input().split()) A = [0] + [a-i*da for i in range(t)] B = {0} | {b-i*db for i in range(t)} print('YES' if any(x-a in B for a in A) else 'NO') ```
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,637,035,823
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
9
62
0
s = input() t = input() ans = 'YES' for i in range(len(s)): if s[i] != t[len(s)-i-1]: ans = 'NO' break print(ans)
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python s = input() t = input() ans = 'YES' for i in range(len(s)): if s[i] != t[len(s)-i-1]: ans = 'NO' break print(ans) ```
-1
463
A
Caisa and Sugar
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town. Unfortunately, he has just *s* dollars for sugar. But that's not a reason to be sad, because there are *n* types of sugar in the supermarket, maybe he able to buy one. B...
The first line contains two space-separated integers *n*,<=*s* (1<=≤<=*n*,<=*s*<=≤<=100). The *i*-th of the next *n* lines contains two integers *x**i*, *y**i* (1<=≤<=*x**i*<=≤<=100; 0<=≤<=*y**i*<=&lt;<=100), where *x**i* represents the number of dollars and *y**i* the number of cents needed in order to buy the *i*-th...
Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar.
[ "5 10\n3 90\n12 0\n9 70\n5 50\n7 0\n", "5 5\n10 10\n20 20\n30 30\n40 40\n50 50\n" ]
[ "50\n", "-1\n" ]
In the first test sample Caisa can buy the fourth type of sugar, in such a case he will take 50 sweets as a change.
500
[ { "input": "5 10\n3 90\n12 0\n9 70\n5 50\n7 0", "output": "50" }, { "input": "5 5\n10 10\n20 20\n30 30\n40 40\n50 50", "output": "-1" }, { "input": "1 2\n1 0", "output": "0" }, { "input": "2 10\n20 99\n30 99", "output": "-1" }, { "input": "15 21\n16 51\n33 44\n32 ...
1,638,411,261
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
30
0
n, s = map(int, input().split()) s *= 100 maxim = 0 for _ in range(n): x, y = map(int, input().split()) cost = x * 100 + y maxim = max(s % cost % 100, maxim) print(-1 if maxim == 0 else maxim)
Title: Caisa and Sugar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town. Unfortunately, he has just *s* dollars for sugar. But that's not a r...
```python n, s = map(int, input().split()) s *= 100 maxim = 0 for _ in range(n): x, y = map(int, input().split()) cost = x * 100 + y maxim = max(s % cost % 100, maxim) print(-1 if maxim == 0 else maxim) ```
0
672
B
Different is Good
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "strings" ]
null
null
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*. The second line contains the string *s* of length *n* consisting of only lowercase English letters.
If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
[ "2\naa\n", "4\nkoko\n", "5\nmurat\n" ]
[ "1\n", "2\n", "0\n" ]
In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
1,000
[ { "input": "2\naa", "output": "1" }, { "input": "4\nkoko", "output": "2" }, { "input": "5\nmurat", "output": "0" }, { "input": "6\nacbead", "output": "1" }, { "input": "7\ncdaadad", "output": "4" }, { "input": "25\npeoaicnbisdocqofsqdpgobpn", "outp...
1,658,899,314
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
n=int(input()) s=set(input()) print(abs(n-s))
Title: Different is Good Time Limit: None seconds Memory Limit: None megabytes Problem Description: A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are di...
```python n=int(input()) s=set(input()) print(abs(n-s)) ```
-1
931
A
Friends Meeting
PROGRAMMING
800
[ "brute force", "greedy", "implementation", "math" ]
null
null
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco...
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*.
Print the minimum possible total tiredness if the friends meet in the same point.
[ "3\n4\n", "101\n99\n", "5\n10\n" ]
[ "1\n", "2\n", "9\n" ]
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, an...
500
[ { "input": "3\n4", "output": "1" }, { "input": "101\n99", "output": "2" }, { "input": "5\n10", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n1000", "output": "250000" }, { "input": "999\n1000", "output": "1" }, { "inpu...
1,520,178,716
1,016
Python 3
OK
TESTS
40
62
5,632,000
a = int(input()) b = int(input()) health = 0 i = 1 if a > b : x = (a - b )// 2 + b while a != b: if a != x: a -= 1 health += i if b != x: b += 1 health += i i += 1 else: x = (b - a ) // 2 + a while a != b: i...
Title: Friends Meeting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in...
```python a = int(input()) b = int(input()) health = 0 i = 1 if a > b : x = (a - b )// 2 + b while a != b: if a != x: a -= 1 health += i if b != x: b += 1 health += i i += 1 else: x = (b - a ) // 2 + a while a != b: ...
3
994
A
Fingerprints
PROGRAMMING
800
[ "implementation" ]
null
null
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse...
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen...
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
[ "7 3\n3 5 7 1 6 2 8\n1 2 7\n", "4 4\n3 4 1 0\n0 1 7 9\n" ]
[ "7 1 2\n", "1 0\n" ]
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence. In the second example digits $...
500
[ { "input": "7 3\n3 5 7 1 6 2 8\n1 2 7", "output": "7 1 2" }, { "input": "4 4\n3 4 1 0\n0 1 7 9", "output": "1 0" }, { "input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8", "output": "8 6 4 2" }, { "input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9", "output": "3 7 4 9 0" }, { "...
1,566,424,165
2,147,483,647
Python 3
OK
TESTS
31
124
0
n, m = map(int, input().split()) xs = map(int, input().split()) ys = map(int, input().split()) flags = [False] * 10 for y in ys: flags[y] = True res = (str(x) for x in xs if flags[x]) print(" ".join(res))
Title: Fingerprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keyp...
```python n, m = map(int, input().split()) xs = map(int, input().split()) ys = map(int, input().split()) flags = [False] * 10 for y in ys: flags[y] = True res = (str(x) for x in xs if flags[x]) print(" ".join(res)) ```
3
22
B
Bargaining Table
PROGRAMMING
1,500
[ "brute force", "dp" ]
B. Bargaining Table
2
256
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room *n*<=×<=*m* meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, t...
The first line contains 2 space-separated numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=25) — the office room dimensions. Then there follow *n* lines with *m* characters 0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in ...
Output one number — the maximum possible perimeter of a bargaining table for Bob's office room.
[ "3 3\n000\n010\n000\n", "5 4\n1100\n0000\n0000\n0000\n0000\n" ]
[ "8\n", "16\n" ]
none
0
[ { "input": "3 3\n000\n010\n000", "output": "8" }, { "input": "5 4\n1100\n0000\n0000\n0000\n0000", "output": "16" }, { "input": "3 3\n000\n110\n000", "output": "8" }, { "input": "4 2\n00\n10\n11\n00", "output": "6" }, { "input": "3 5\n00001\n00000\n10100", "out...
1,642,116,378
2,147,483,647
PyPy 3-64
OK
TESTS
23
342
26,009,600
# Codeforces Beta Round #22 (Div. 2 Only) # B. Bargaining Table n, m = map(int, input().split()) office = [] for _ in range(n): office += [list(input())] # dp is a set of 4-tuples (x, y, l, w) which describes the coordinates of a # table. (x, y, l, w) is in dp iff the rectangle from (x, y) to (x + l, y + w) # is ...
Title: Bargaining Table Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room *n*<=×<=*m* meters. Each square meter of the room is either ...
```python # Codeforces Beta Round #22 (Div. 2 Only) # B. Bargaining Table n, m = map(int, input().split()) office = [] for _ in range(n): office += [list(input())] # dp is a set of 4-tuples (x, y, l, w) which describes the coordinates of a # table. (x, y, l, w) is in dp iff the rectangle from (x, y) to (x + l, y ...
3.866053
884
B
Japanese Crosswords Strike Back
PROGRAMMING
1,100
[ "implementation" ]
null
null
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect. For example: - If *x*<==<...
The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding.
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
[ "2 4\n1 3\n", "3 10\n3 3 2\n", "2 10\n1 3\n" ]
[ "NO\n", "YES\n", "NO\n" ]
none
0
[ { "input": "2 4\n1 3", "output": "NO" }, { "input": "3 10\n3 3 2", "output": "YES" }, { "input": "2 10\n1 3", "output": "NO" }, { "input": "1 1\n1", "output": "YES" }, { "input": "1 10\n10", "output": "YES" }, { "input": "1 10000\n10000", "output":...
1,601,464,983
2,147,483,647
PyPy 3
OK
TESTS
66
186
10,137,600
n,x=map(int,input().split()) l=list(map(int,input().split())) if sum(l)>x: print("NO") elif sum(l)+n-1==x or (n==1 and (l[0]==x)): print("YES") else: print("NO")
Title: Japanese Crosswords Strike Back Time Limit: None seconds Memory Limit: None megabytes Problem Description: A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely ...
```python n,x=map(int,input().split()) l=list(map(int,input().split())) if sum(l)>x: print("NO") elif sum(l)+n-1==x or (n==1 and (l[0]==x)): print("YES") else: print("NO") ```
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,663,858,075
2,147,483,647
Python 3
OK
TESTS
40
92
0
kelime=list(input()) word=list(input()) kelime.reverse() if kelime==word: print("YES") else: print("NO")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python kelime=list(input()) word=list(input()) kelime.reverse() if kelime==word: print("YES") else: print("NO") ```
3.977
954
A
Diagonal Walking
PROGRAMMING
800
[ "implementation" ]
null
null
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R.
Print the minimum possible length of the sequence of moves after all replacements are done.
[ "5\nRUURU\n", "17\nUUURRRRRUUURURUUU\n" ]
[ "3\n", "13\n" ]
In the first test the shortened sequence of moves may be DUD (its length is 3). In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).
0
[ { "input": "5\nRUURU", "output": "3" }, { "input": "17\nUUURRRRRUUURURUUU", "output": "13" }, { "input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", "output": "100" }, { "input": "100\nRRURRUUUURURRRURRRRURRRRRR...
1,637,575,333
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
n=int(input()) s=input() count=0 for i in range(n-1): if (s[i]=='U' and s[i+1]=='R')or(s[i]=='R' and s[i+1]=='U'): count+=1 elif (s[i]=='U' and s[i+1]=='U')or(s[i]=='R' and s[i+1]=='R'): count+=1 print(count)
Title: Diagonal Walking Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence movi...
```python n=int(input()) s=input() count=0 for i in range(n-1): if (s[i]=='U' and s[i+1]=='R')or(s[i]=='R' and s[i+1]=='U'): count+=1 elif (s[i]=='U' and s[i+1]=='U')or(s[i]=='R' and s[i+1]=='R'): count+=1 print(count) ```
0
237
A
Free Cash
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is...
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
[ "4\n8 0\n8 10\n8 10\n8 45\n", "3\n0 12\n10 11\n22 22\n" ]
[ "2\n", "1\n" ]
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so ...
500
[ { "input": "4\n8 0\n8 10\n8 10\n8 45", "output": "2" }, { "input": "3\n0 12\n10 11\n22 22", "output": "1" }, { "input": "5\n12 8\n15 27\n15 27\n16 2\n19 52", "output": "2" }, { "input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23", "output": "3" }, { "input": "...
1,663,917,806
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
9
2,000
8,806,400
dic={} for i in range(int(input())): s=input() if s in list(dic.keys()): dic[s]+=1 else: dic[s]=1 print(max(dic.values()))
Title: Free Cash Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l...
```python dic={} for i in range(int(input())): s=input() if s in list(dic.keys()): dic[s]+=1 else: dic[s]=1 print(max(dic.values())) ```
0
489
C
Given Length and Sum of Digits...
PROGRAMMING
1,400
[ "dp", "greedy", "implementation" ]
null
null
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers.
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
[ "2 15\n", "3 0\n" ]
[ "69 96\n", "-1 -1\n" ]
none
1,500
[ { "input": "2 15", "output": "69 96" }, { "input": "3 0", "output": "-1 -1" }, { "input": "2 1", "output": "10 10" }, { "input": "3 10", "output": "109 910" }, { "input": "100 100", "output": "1000000000000000000000000000000000000000000000000000000000000000000...
1,695,055,025
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
31
0
def len_and_sum(m, s): if 9 * m < s or s < 1: return '-1 -1' s1 = s maxz, minz = '', '' for i in range(m): if s >= 9: maxz += '9' s -= 9 else: maxz += str(s) s = 0 minz = maxz[::-1] if minz[0] == '0': f...
Title: Given Length and Sum of Digits... Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should ...
```python def len_and_sum(m, s): if 9 * m < s or s < 1: return '-1 -1' s1 = s maxz, minz = '', '' for i in range(m): if s >= 9: maxz += '9' s -= 9 else: maxz += str(s) s = 0 minz = maxz[::-1] if minz[0] == '0': ...
0
272
B
Dima and Sequence
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
Dima got into number sequences. Now he's got sequence *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Also, Dima has got a function *f*(*x*), which can be defined with the following recurrence: - *f*(0)<==<=0; - *f*(2·*x*)<==<=*f*(*x*); - *f*(2·*x*<=+<=1)<==<=*f*(*x*)<=+<=1. Dima wonders, how many...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). The numbers in the lines are separated by single spaces.
In a single line print the answer to the problem. Please, don't use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3\n1 2 4\n", "3\n5 3 1\n" ]
[ "3\n", "1\n" ]
In the first sample any pair (*i*, *j*) will do, so the answer is 3. In the second sample only pair (1, 2) will do.
1,000
[ { "input": "3\n1 2 4", "output": "3" }, { "input": "3\n5 3 1", "output": "1" }, { "input": "2\n469264357 996569493", "output": "0" }, { "input": "6\n396640239 62005863 473635171 329666981 510631133 207643327", "output": "2" }, { "input": "8\n851991424 32517099 310...
1,559,322,009
2,889
Python 3
WRONG_ANSWER
TESTS
0
154
0
n = int(input()) def norm(a): if a % 2 == 0: while a % 2 == 0: a //= 2 if a > 1: while (a - 1) % 4 == 0: a = (a - 1) // 2 + 1 return a m = sorted([norm(int(x)) for x in input().split()]) s = 0 for i in range(len(m)-1): if m[i] == m[i+1]: ...
Title: Dima and Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima got into number sequences. Now he's got sequence *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Also, Dima has got a function *f*(*x*), which can be defined with the following recurrence: - *f...
```python n = int(input()) def norm(a): if a % 2 == 0: while a % 2 == 0: a //= 2 if a > 1: while (a - 1) % 4 == 0: a = (a - 1) // 2 + 1 return a m = sorted([norm(int(x)) for x in input().split()]) s = 0 for i in range(len(m)-1): if m[i] == m[i+...
0
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,605,791,998
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
154
0
s = input() t = input() if len(s) != len(t): print('Error') else: tmp = list(s) n = len(tmp) for i in range(n): tmp[i], tmp[n-i-1] = tmp[n-i-1], tmp[i] word = ''.join(tmp) if word == t: print('YES') else: print('NO')
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python s = input() t = input() if len(s) != len(t): print('Error') else: tmp = list(s) n = len(tmp) for i in range(n): tmp[i], tmp[n-i-1] = tmp[n-i-1], tmp[i] word = ''.join(tmp) if word == t: print('YES') else: print('NO'...
0
659
E
New Reform
PROGRAMMING
1,600
[ "data structures", "dfs and similar", "dsu", "graphs", "greedy" ]
null
null
Berland has *n* cities connected by *m* bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only the existing roads. The President of Berland decided to make changes to the roa...
The first line of the input contains two positive integers, *n* and *m* — the number of the cities and the number of roads in Berland (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000). Next *m* lines contain the descriptions of the roads: the *i*-th road is determined by two distinct integers *x**i*,<=*y**i* (1<=≤<=*x...
Print a single integer — the minimum number of separated cities after the reform.
[ "4 3\n2 1\n1 3\n4 3\n", "5 5\n2 1\n1 3\n2 3\n2 5\n4 3\n", "6 5\n1 2\n2 3\n4 5\n4 6\n5 6\n" ]
[ "1\n", "0\n", "1\n" ]
In the first sample the following road orientation is allowed: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e5b18c46402af724bd3841d549d5d6f52fc16253.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/04481ace...
1,500
[ { "input": "4 3\n2 1\n1 3\n4 3", "output": "1" }, { "input": "5 5\n2 1\n1 3\n2 3\n2 5\n4 3", "output": "0" }, { "input": "6 5\n1 2\n2 3\n4 5\n4 6\n5 6", "output": "1" }, { "input": "4 4\n1 2\n2 3\n3 4\n4 1", "output": "0" }, { "input": "10 45\n3 5\n2 3\n4 8\n2 5\n...
1,596,071,037
2,147,483,647
PyPy 3
OK
TESTS
41
998
43,417,600
#cycle detection def dfs(node,par): seen[node] = 1 for each in adj[node]: if seen[each] == 0: if dfs(each,node) == True: return True else: if each != par: return True return False n,m = map(int,input().split()) adj = [list() for i in range(n+1)] seen = [0...
Title: New Reform Time Limit: None seconds Memory Limit: None megabytes Problem Description: Berland has *n* cities connected by *m* bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other ...
```python #cycle detection def dfs(node,par): seen[node] = 1 for each in adj[node]: if seen[each] == 0: if dfs(each,node) == True: return True else: if each != par: return True return False n,m = map(int,input().split()) adj = [list() for i in range(n+1)] ...
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", ...
1,566,668,030
2,147,483,647
Python 3
OK
TESTS
36
466
1,126,400
from fractions import Fraction y, w = [int(i) for i in input().split()] greater = max(y, w) greaters = 6 - greater + 1 result = Fraction(greaters, 6) if result.denominator == 1: print(str(result.numerator) + '/1') else: print(result)
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T...
```python from fractions import Fraction y, w = [int(i) for i in input().split()] greater = max(y, w) greaters = 6 - greater + 1 result = Fraction(greaters, 6) if result.denominator == 1: print(str(result.numerator) + '/1') else: print(result) ```
3.758608
729
B
Spotlights
PROGRAMMING
1,200
[ "dp", "implementation" ]
null
null
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a spotlight on the stage in some good position. The spotlight will project light in one of t...
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan. The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell ...
Print one integer — the number of good positions for placing the spotlight.
[ "2 4\n0 1 0 0\n1 0 1 0\n", "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n" ]
[ "9\n", "20\n" ]
In the first example the following positions are good: 1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and...
1,000
[ { "input": "2 4\n0 1 0 0\n1 0 1 0", "output": "9" }, { "input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0", "output": "20" }, { "input": "1 5\n1 1 0 0 0", "output": "3" }, { "input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0", "output": "20" }, { "input": "3 ...
1,479,637,393
4,693
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
6
1,000
5,939,200
a, b = map(int, input().split()) scene = [list(map(int, input().split())) for i in range(a)] lines = [False] * a columns = [False] * b ans = 0 for i in range(a): for j in range(b): if scene[i][j] == 0: if lines[i] == True: ans += 1 else: lines[i] = ...
Title: Spotlights Time Limit: None seconds Memory Limit: None megabytes Problem Description: Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to pl...
```python a, b = map(int, input().split()) scene = [list(map(int, input().split())) for i in range(a)] lines = [False] * a columns = [False] * b ans = 0 for i in range(a): for j in range(b): if scene[i][j] == 0: if lines[i] == True: ans += 1 else: l...
0
280
C
Game on Tree
PROGRAMMING
2,200
[ "implementation", "math", "probabilities", "trees" ]
null
null
Momiji has got a rooted tree, consisting of *n* nodes. The tree nodes are numbered by integers from 1 to *n*. The root has number 1. Momiji decided to play a game on this tree. The game consists of several steps. On each step, Momiji chooses one of the remaining tree nodes (let's denote it by *v*) and removes all the ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of nodes in the tree. The next *n*<=-<=1 lines contain the tree edges. The *i*-th line contains integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*) — the numbers of the nodes that are connected by the *i*-th edge. It is guarant...
Print a single real number — the expectation of the number of steps in the described game. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6.
[ "2\n1 2\n", "3\n1 2\n1 3\n" ]
[ "1.50000000000000000000\n", "2.00000000000000000000\n" ]
In the first sample, there are two cases. One is directly remove the root and another is remove the root after one step. Thus the expected steps are: In the second sample, things get more complex. There are two cases that reduce to the first sample, and one case cleaned at once. Thus the expected steps are:
1,500
[ { "input": "2\n1 2", "output": "1.50000000000000000000" }, { "input": "3\n1 2\n1 3", "output": "2.00000000000000000000" }, { "input": "10\n1 2\n2 3\n3 4\n1 5\n2 6\n6 7\n4 8\n6 9\n9 10", "output": "3.81666666666666690000" }, { "input": "6\n1 3\n2 4\n5 6\n3 6\n5 4", "output...
1,588,047,835
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
40
1,000
10,342,400
# encoding: utf-8 """ 有一棵树,每次随机选一个点, 将其及其子孙节点全部删除,问将树删空需要的操作次数期望 树根的概率必然为1 一级子节点的概率为树根排在其后的概率,1/2 二级子节点的概率为树根与一级均排在其后的概率,1/3 ... """ from math import sqrt from queue import Queue import sys sys.setrecursionlimit(10**6) if __name__ == '__main__': # sys.stdin = open('1.txt', ...
Title: Game on Tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: Momiji has got a rooted tree, consisting of *n* nodes. The tree nodes are numbered by integers from 1 to *n*. The root has number 1. Momiji decided to play a game on this tree. The game consists of several steps. On each ...
```python # encoding: utf-8 """ 有一棵树,每次随机选一个点, 将其及其子孙节点全部删除,问将树删空需要的操作次数期望 树根的概率必然为1 一级子节点的概率为树根排在其后的概率,1/2 二级子节点的概率为树根与一级均排在其后的概率,1/3 ... """ from math import sqrt from queue import Queue import sys sys.setrecursionlimit(10**6) if __name__ == '__main__': # sys.stdin = open...
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,597,124,293
2,147,483,647
Python 3
OK
TESTS
102
108
6,656,000
def f(a,b): l=len(a) r=[' '] *l for i in range(0,l): if a[i]==b[i]: r[i]='0' else: r[i]='1' return "".join(r) a=input() b=input() print(f(a,b))
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 def f(a,b): l=len(a) r=[' '] *l for i in range(0,l): if a[i]==b[i]: r[i]='0' else: r[i]='1' return "".join(r) a=input() b=input() print(f(a,b)) ```
3.960602
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,657,447,537
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
155
10,035,200
n = int(input()) for i in range(n): t = list(map(int, input().split())) cnt1, cnt2, cnt3 = t.count(1), t.count(2), t.count(3) min_mun = min(cnt1, cnt2, cnt3) if cnt1 == 0 or cnt2 == 0 or cnt3 == 0: print(0) else: li = [] while cnt1 and c...
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): t = list(map(int, input().split())) cnt1, cnt2, cnt3 = t.count(1), t.count(2), t.count(3) min_mun = min(cnt1, cnt2, cnt3) if cnt1 == 0 or cnt2 == 0 or cnt3 == 0: print(0) else: li = [] while ...
-1
659
A
Round House
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th...
The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.
Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk.
[ "6 2 -5\n", "5 1 3\n", "3 2 7\n" ]
[ "3\n", "4\n", "3\n" ]
The first example is illustrated by the picture in the statements.
500
[ { "input": "6 2 -5", "output": "3" }, { "input": "5 1 3", "output": "4" }, { "input": "3 2 7", "output": "3" }, { "input": "1 1 0", "output": "1" }, { "input": "1 1 -1", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "100 ...
1,621,245,934
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
18
93
0
n,a,w=map(int,input().split()) w1=abs(w) w1=w1%n if(w1==0): print(a) elif(w>0): if(a+w1<=n): print(a+w1) else: print(n-a-w1) elif(w<0): w1=n-w1 if(a+w1<=n): print(a+w1) else: print(n-a-w1)
Title: Round House Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in e...
```python n,a,w=map(int,input().split()) w1=abs(w) w1=w1%n if(w1==0): print(a) elif(w>0): if(a+w1<=n): print(a+w1) else: print(n-a-w1) elif(w<0): w1=n-w1 if(a+w1<=n): print(a+w1) else: print(n-a-w1) ```
0
902
A
Visiting a Friend
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point *m* on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmos...
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house. The next *n* lines contain information about teleports. The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where ...
Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "3 5\n0 2\n2 4\n3 5\n", "3 7\n0 4\n2 5\n6 7\n" ]
[ "YES\n", "NO\n" ]
The first example is shown on the picture below: Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives. The second example is shown on the picture below: You...
500
[ { "input": "3 5\n0 2\n2 4\n3 5", "output": "YES" }, { "input": "3 7\n0 4\n2 5\n6 7", "output": "NO" }, { "input": "1 1\n0 0", "output": "NO" }, { "input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7...
1,513,769,171
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> using namespace std; const int maxn=105; vector<int>g[105]; bool vis[105]; void add(int a,int b){ g[a].push_back(b); g[b].push_back(a); } void dfs(int m){ for(int i=0;i<g[m].size();i++){ if(!vis[g[m][i]]){ vis[g[m][i]]=true; dfs(g[m][i])...
Title: Visiting a Friend Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point *m* on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain ...
```python #include <bits/stdc++.h> using namespace std; const int maxn=105; vector<int>g[105]; bool vis[105]; void add(int a,int b){ g[a].push_back(b); g[b].push_back(a); } void dfs(int m){ for(int i=0;i<g[m].size();i++){ if(!vis[g[m][i]]){ vis[g[m][i]]=true; df...
-1
615
A
Bulbs
PROGRAMMING
800
[ "implementation" ]
null
null
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs? I...
The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively. Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**...
If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO".
[ "3 4\n2 1 4\n3 1 3 1\n1 2\n", "3 3\n1 1\n1 2\n1 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.
500
[ { "input": "3 4\n2 1 4\n3 1 3 1\n1 2", "output": "YES" }, { "input": "3 3\n1 1\n1 2\n1 1", "output": "NO" }, { "input": "3 4\n1 1\n1 2\n1 3", "output": "NO" }, { "input": "1 5\n5 1 2 3 4 5", "output": "YES" }, { "input": "1 5\n5 4 4 1 2 3", "output": "NO" },...
1,665,466,735
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
46
0
n, m = [int(t) for t in input().split()] bulbs = [0] * m for _ in range(n): on = [int(t) - 1 for t in input().split()] for i in on: bulbs[i] = 1 if 0 in bulbs: print('NO') else: print('YES')
Title: Bulbs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is...
```python n, m = [int(t) for t in input().split()] bulbs = [0] * m for _ in range(n): on = [int(t) - 1 for t in input().split()] for i in on: bulbs[i] = 1 if 0 in bulbs: print('NO') else: print('YES') ```
0
476
A
Dreamoon and Stairs
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*. What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?
The single line contains two space separated integers *n*, *m* (0<=&lt;<=*n*<=≤<=10000,<=1<=&lt;<=*m*<=≤<=10).
Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead.
[ "10 2\n", "3 5\n" ]
[ "6\n", "-1\n" ]
For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}. For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5.
500
[ { "input": "10 2", "output": "6" }, { "input": "3 5", "output": "-1" }, { "input": "29 7", "output": "21" }, { "input": "2 2", "output": "2" }, { "input": "1 2", "output": "-1" }, { "input": "10000 2", "output": "5000" }, { "input": "10000 ...
1,680,864,131
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
#Khushal Sindhav #Indian Institute Of Technology, Jodhpur # 2022 import sys input=sys.stdin.readline def exe(): no_of_two=n//2 no_of_one=n%2 tot=(no_of_one+no_of_two) no=tot//m if(tot%m!=0): no+=1 a=no*m req=a-tot if(no_of_two>=req): return...
Title: Dreamoon and Stairs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*. What is the minimal number of moves making him climb ...
```python #Khushal Sindhav #Indian Institute Of Technology, Jodhpur # 2022 import sys input=sys.stdin.readline def exe(): no_of_two=n//2 no_of_one=n%2 tot=(no_of_one+no_of_two) no=tot//m if(tot%m!=0): no+=1 a=no*m req=a-tot if(no_of_two>=req): ...
0
340
A
The Wall
PROGRAMMING
1,200
[ "math" ]
null
null
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints th...
The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*).
Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink.
[ "2 3 6 18\n" ]
[ "3" ]
Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18.
500
[ { "input": "2 3 6 18", "output": "3" }, { "input": "4 6 20 201", "output": "15" }, { "input": "15 27 100 10000", "output": "74" }, { "input": "105 60 3456 78910", "output": "179" }, { "input": "1 1 1000 100000", "output": "99001" }, { "input": "3 2 5 5...
1,478,790,868
2,147,483,647
Python 3
OK
TESTS
35
124
0
import math if __name__ == '__main__': x, y, a, b = str(input()).split() x, y, a, b = int(x), int(y), int(a), int(b) n = x * y // math.gcd(x, y) print(1 + b // n - (a + n - 1) // n)
Title: The Wall Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub ...
```python import math if __name__ == '__main__': x, y, a, b = str(input()).split() x, y, a, b = int(x), int(y), int(a), int(b) n = x * y // math.gcd(x, y) print(1 + b // n - (a + n - 1) // n) ```
3
13
A
Numbers
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Numbers
1
64
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1. Note that all c...
Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000).
Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator.
[ "5\n", "3\n" ]
[ "7/3\n", "2/1\n" ]
In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.
0
[ { "input": "5", "output": "7/3" }, { "input": "3", "output": "2/1" }, { "input": "1000", "output": "90132/499" }, { "input": "927", "output": "155449/925" }, { "input": "260", "output": "6265/129" }, { "input": "131", "output": "3370/129" }, { ...
1,603,697,691
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
186
0
number = input() number = int(number) all_bases = [i for i in range(int(number)) if i > 1] nums_list = [] for base in all_bases: remainder = number while True: nums_list.append(remainder%base) remainder = remainder//base if remainder == remainder%base: nums_list.app...
Title: Numbers Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of su...
```python number = input() number = int(number) all_bases = [i for i in range(int(number)) if i > 1] nums_list = [] for base in all_bases: remainder = number while True: nums_list.append(remainder%base) remainder = remainder//base if remainder == remainder%base: num...
0
143
B
Help Kingdom of Far Far Away 2
PROGRAMMING
1,200
[ "implementation", "strings" ]
null
null
For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more easily readable format. However, as time went by, the economy of the Far Far Away developed and the scale of operatio...
The input contains a number that needs to be converted into financial format. The number's notation length does not exceed 100 characters, including (possible) signs "-" (minus) and "." (decimal point). The number's notation is correct, that is: - The number's notation only contains characters from the set {"0" – "9...
Print the number given in the input in the financial format by the rules described in the problem statement.
[ "2012\n", "0.000\n", "-0.00987654321\n", "-12345678.9\n" ]
[ "$2,012.00", "$0.00", "($0.00)", "($12,345,678.90)" ]
Pay attention to the second and third sample tests. They show that the sign of a number in the financial format (and consequently, the presence or absence of brackets) is determined solely by the sign of the initial number. It does not depend on the sign of the number you got after translating the number to the financi...
1,000
[ { "input": "2012", "output": "$2,012.00" }, { "input": "0.000", "output": "$0.00" }, { "input": "-0.00987654321", "output": "($0.00)" }, { "input": "-12345678.9", "output": "($12,345,678.90)" }, { "input": "0.99999999999999999999", "output": "$0.99" }, { ...
1,660,823,556
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
124
2,867,200
import collections import heapq import sys import math import itertools import bisect from io import BytesIO, IOBase import os # sys.setrecursionlimit(10000) def values(): return tuple(map(int, sys.stdin.readline().split())) def inlst(): return [int(i) for i in sys.stdin.readline().split()] def inp(): re...
Title: Help Kingdom of Far Far Away 2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more e...
```python import collections import heapq import sys import math import itertools import bisect from io import BytesIO, IOBase import os # sys.setrecursionlimit(10000) def values(): return tuple(map(int, sys.stdin.readline().split())) def inlst(): return [int(i) for i in sys.stdin.readline().split()] def...
-1
299
A
Ksusha and Array
PROGRAMMING
1,000
[ "brute force", "number theory", "sortings" ]
null
null
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!
The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements.
Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1. If there are multiple answers, you are allowed to print any of them.
[ "3\n2 2 4\n", "5\n2 1 3 1 6\n", "3\n2 3 5\n" ]
[ "2\n", "1\n", "-1\n" ]
none
500
[ { "input": "3\n2 2 4", "output": "2" }, { "input": "5\n2 1 3 1 6", "output": "1" }, { "input": "3\n2 3 5", "output": "-1" }, { "input": "1\n331358794", "output": "331358794" }, { "input": "5\n506904227 214303304 136194869 838256937 183952885", "output": "-1" ...
1,518,379,204
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
5,632,000
from sys import stdin def read(): return map(int, stdin.readline().split()) read() a = list(read()) x = max(a) for y in a: if x % y != 0: x = -1 break print(x)
Title: Ksusha and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that ...
```python from sys import stdin def read(): return map(int, stdin.readline().split()) read() a = list(read()) x = max(a) for y in a: if x % y != 0: x = -1 break print(x) ```
0
514
A
Chewbaсca and Number
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits....
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
[ "27\n", "4545\n" ]
[ "22\n", "4444\n" ]
none
500
[ { "input": "27", "output": "22" }, { "input": "4545", "output": "4444" }, { "input": "1", "output": "1" }, { "input": "9", "output": "9" }, { "input": "8772", "output": "1222" }, { "input": "81", "output": "11" }, { "input": "71723447", ...
1,677,145,774
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
31
0
s=list(input()) # print(s) if(len(s)==1 and s[0]=='9'): print(9) else: for i in range(len(s)): s[i]=str(min(int(s[i]),9-int(s[i]))) for i in range(len(s)): print(s[i],end='')
Title: Chewbaсca and Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform...
```python s=list(input()) # print(s) if(len(s)==1 and s[0]=='9'): print(9) else: for i in range(len(s)): s[i]=str(min(int(s[i]),9-int(s[i]))) for i in range(len(s)): print(s[i],end='') ```
0
460
A
Vasya and Socks
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la...
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Print a single integer — the answer to the problem.
[ "2 2\n", "9 3\n" ]
[ "3\n", "13\n" ]
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on...
500
[ { "input": "2 2", "output": "3" }, { "input": "9 3", "output": "13" }, { "input": "1 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "1 99", "output": "1" }, { "input": "4 4", "output": "5" }, { "input": "10 2", "outp...
1,696,004,752
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
31
0
n, m = map(int, input().split()) days = 0 socks = n for day in range(1, 101): if socks < day: break if day % m == 0: socks += 1 days += 1 print(days)
Title: Vasya and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th...
```python n, m = map(int, input().split()) days = 0 socks = n for day in range(1, 101): if socks < day: break if day % m == 0: socks += 1 days += 1 print(days) ```
0
581
A
Vasya the Hipster
PROGRAMMING
800
[ "implementation", "math" ]
null
null
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning ...
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he'...
[ "3 1\n", "2 3\n", "7 3\n" ]
[ "1 1\n", "2 0\n", "3 2\n" ]
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
500
[ { "input": "3 1", "output": "1 1" }, { "input": "2 3", "output": "2 0" }, { "input": "7 3", "output": "3 2" }, { "input": "100 100", "output": "100 0" }, { "input": "4 10", "output": "4 3" }, { "input": "6 10", "output": "6 2" }, { "input":...
1,683,744,035
2,147,483,647
PyPy 3-64
OK
TESTS
30
62
0
import sys b, r = [int(x) for x in sys.stdin.readline().split()] max = b if b >= r else r min = b if b <= r else r print(str(min) + ' ' + str((max - min) // 2))
Title: Vasya the Hipster Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red...
```python import sys b, r = [int(x) for x in sys.stdin.readline().split()] max = b if b >= r else r min = b if b <= r else r print(str(min) + ' ' + str((max - min) // 2)) ```
3
725
A
Jumping Ball
PROGRAMMING
1,000
[ "implementation" ]
null
null
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '&lt;' and '&gt;'. When the ball hits the bumper at pos...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '&lt;' and '&gt;'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper.
Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position.
[ "4\n&lt;&lt;&gt;&lt;\n", "5\n&gt;&gt;&gt;&gt;&gt;\n", "4\n&gt;&gt;&lt;&lt;\n" ]
[ "2", "5", "0" ]
In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
500
[ { "input": "4\n<<><", "output": "2" }, { "input": "5\n>>>>>", "output": "5" }, { "input": "4\n>><<", "output": "0" }, { "input": "3\n<<>", "output": "3" }, { "input": "3\n<<<", "output": "3" }, { "input": "3\n><<", "output": "0" }, { "input...
1,492,256,473
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
5,222,400
'''input 4 >><< ''' n = int(input()) s = input() t = "<" for x in range(n): if t != s[x]: break else: x += 1 s = s[::-1] t = ">" for y in range(n): if t != s[x]: break else: x += 1 print(x + y)
Title: Jumping Ball Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of b...
```python '''input 4 >><< ''' n = int(input()) s = input() t = "<" for x in range(n): if t != s[x]: break else: x += 1 s = s[::-1] t = ">" for y in range(n): if t != s[x]: break else: x += 1 print(x + y) ```
0
471
B
MUH and Important Things
PROGRAMMING
1,300
[ "implementation", "sortings" ]
null
null
It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are *n* tasks for the day and each animal should do each of these tasks. For each task, they have evaluated its difficulty. Also animals decided to do the tasks in ord...
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of tasks. The second line contains *n* integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=2000), where *h**i* is the difficulty of the *i*-th task. The larger number *h**i* is, the more difficult the *i*-th task is.
In the first line print "YES" (without the quotes), if it is possible to come up with three distinct plans of doing the tasks. Otherwise print in the first line "NO" (without the quotes). If three desired plans do exist, print in the second line *n* distinct integers that represent the numbers of the tasks in the order...
[ "4\n1 3 3 1\n", "5\n2 4 1 4 8\n" ]
[ "YES\n1 4 2 3 \n4 1 2 3 \n4 1 3 2 \n", "NO" ]
In the first sample the difficulty of the tasks sets one limit: tasks 1 and 4 must be done before tasks 2 and 3. That gives the total of four possible sequences of doing tasks : [1, 4, 2, 3], [4, 1, 2, 3], [1, 4, 3, 2], [4, 1, 3, 2]. You can print any three of them in the answer. In the second sample there are only tw...
1,000
[ { "input": "4\n1 3 3 1", "output": "YES\n1 4 2 3 \n4 1 2 3 \n4 1 3 2 " }, { "input": "5\n2 4 1 4 8", "output": "NO" }, { "input": "8\n1 5 4 12 7 2 10 11", "output": "NO" }, { "input": "6\n5 1 2 5 2 4", "output": "YES\n2 3 5 6 1 4 \n2 5 3 6 1 4 \n2 5 3 6 4 1 " }, { ...
1,587,196,900
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
124
0
n=int(input()) l=list(map(int,input().split())) s=[] for i in range(n): x=[l[i],i] s.append(x) s.sort() flag=0 sw=[] ans=[] for i in range(n): x=s[i][1] ans.append(x) for i in range(n-1): if s[i][0]==s[i+1][0]: sw.append((i,i+1)) if len(sw)==2: print('YES') ...
Title: MUH and Important Things Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are *n* tasks for the day and each animal should do each ...
```python n=int(input()) l=list(map(int,input().split())) s=[] for i in range(n): x=[l[i],i] s.append(x) s.sort() flag=0 sw=[] ans=[] for i in range(n): x=s[i][1] ans.append(x) for i in range(n-1): if s[i][0]==s[i+1][0]: sw.append((i,i+1)) if len(sw)==2: print('Y...
0
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If...
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "outp...
1,691,503,696
2,147,483,647
PyPy 3-64
OK
TESTS
44
122
0
t = input() count1 = 0 count0 = 0 y = "NO" for x in t: if x == "1": count1 += 1 count0 = 0 elif x == "0": count0 += 1 count1 = 0 if count0 >= 7 or count1 >= 7: y = "YES" break print(y)
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A...
```python t = input() count1 = 0 count0 = 0 y = "NO" for x in t: if x == "1": count1 += 1 count0 = 0 elif x == "0": count0 += 1 count1 = 0 if count0 >= 7 or count1 >= 7: y = "YES" break print(y) ```
3.9695
435
A
Queue on Bus Stop
PROGRAMMING
1,000
[ "implementation" ]
null
null
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups. The bus stop queue has *n* groups of people. The *i*-th group from the beginning ...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*m*).
Print a single integer — the number of buses that is needed to transport all *n* groups to the dacha countryside.
[ "4 3\n2 3 2 1\n", "3 4\n1 2 1\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "4 3\n2 3 2 1", "output": "3" }, { "input": "3 4\n1 2 1", "output": "1" }, { "input": "1 5\n4", "output": "1" }, { "input": "5 1\n1 1 1 1 1", "output": "5" }, { "input": "6 4\n1 3 2 3 4 1", "output": "5" }, { "input": "6 8\n6 1 1 1 4 5", ...
1,570,719,268
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
l=list(map(int,input().split(" "))) n=l[0] m=l[1] l=list(map(int,input().split(" "))) i=0 s=0 cnt=0 while(i<n): print(s,cnt) s=s+l[i] if(s<m): i+=1 elif(s==m): s=0 cnt+=1 i+=1 else: s=0 cnt+=1 print(cnt)
Title: Queue on Bus Stop Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand...
```python l=list(map(int,input().split(" "))) n=l[0] m=l[1] l=list(map(int,input().split(" "))) i=0 s=0 cnt=0 while(i<n): print(s,cnt) s=s+l[i] if(s<m): i+=1 elif(s==m): s=0 cnt+=1 i+=1 else: s=0 cnt+=1 print(cnt) ```
0
912
A
Tricky Alchemy
PROGRAMMING
800
[ "implementation" ]
null
null
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ...
The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal. The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained.
Print a single integer — the minimum number of crystals that Grisha should acquire in addition.
[ "4 3\n2 1 1\n", "3 9\n1 1 3\n", "12345678 87654321\n43043751 1000000000 53798715\n" ]
[ "2\n", "1\n", "2147483648\n" ]
In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.
500
[ { "input": "4 3\n2 1 1", "output": "2" }, { "input": "3 9\n1 1 3", "output": "1" }, { "input": "12345678 87654321\n43043751 1000000000 53798715", "output": "2147483648" }, { "input": "12 12\n3 5 2", "output": "0" }, { "input": "770 1390\n170 442 311", "output"...
1,536,160,743
2,147,483,647
Python 3
OK
TESTS
38
124
307,200
YC, BC = map(int, input().split()) YB, GB, BB = map(int, input().split()) YCR = 2 * YB + GB BCR = GB + 3 * BB print(max(0, YCR-YC) + max(0, BCR-BC))
Title: Tricky Alchemy Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obta...
```python YC, BC = map(int, input().split()) YB, GB, BB = map(int, input().split()) YCR = 2 * YB + GB BCR = GB + 3 * BB print(max(0, YCR-YC) + max(0, BCR-BC)) ```
3
777
E
Hanoi Factory
PROGRAMMING
2,000
[ "brute force", "data structures", "dp", "greedy", "sortings" ]
null
null
Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to create as high tower as possible. They were not ready to serve such a strang...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of rings in factory's stock. The *i*-th of the next *n* lines contains three integers *a**i*, *b**i* and *h**i* (1<=≤<=*a**i*,<=*b**i*,<=*h**i*<=≤<=109, *b**i*<=&gt;<=*a**i*) — inner radius, outer radius and the height of t...
Print one integer — the maximum height of the tower that can be obtained.
[ "3\n1 5 1\n2 6 2\n3 7 3\n", "4\n1 2 1\n1 3 3\n4 6 2\n5 7 1\n" ]
[ "6\n", "4\n" ]
In the first sample, the optimal solution is to take all the rings and put them on each other in order 3, 2, 1. In the second sample, one can put the ring 3 on the ring 4 and get the tower of height 3, or put the ring 1 on the ring 2 and get the tower of height 4.
2,500
[ { "input": "3\n1 5 1\n2 6 2\n3 7 3", "output": "6" }, { "input": "4\n1 2 1\n1 3 3\n4 6 2\n5 7 1", "output": "4" }, { "input": "1\n1 2 1", "output": "1" }, { "input": "5\n6 10 4\n9 20 19\n8 11 18\n18 20 1\n19 20 8", "output": "50" }, { "input": "5\n21 25 26\n14 30 ...
1,488,317,842
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
62
4,608,000
n=int(input()) j=[] for i in range(n): ch=input() l=ch.split(' ') j.append(l) i=n-1 k=[] while i>=0: test=True s=int(j[i][2]) i=i-1 while (test==True)and(i>=0): if int(j[i][1])>int(j[i+1][0]): s=s+int(j[i][2]) else: test=False i=i-1...
Title: Hanoi Factory Time Limit: None seconds Memory Limit: None megabytes Problem Description: Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the worke...
```python n=int(input()) j=[] for i in range(n): ch=input() l=ch.split(' ') j.append(l) i=n-1 k=[] while i>=0: test=True s=int(j[i][2]) i=i-1 while (test==True)and(i>=0): if int(j[i][1])>int(j[i+1][0]): s=s+int(j[i][2]) else: test=False ...
0
932
A
Palindromic Supersequence
PROGRAMMING
800
[ "constructive algorithms" ]
null
null
You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequ...
First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*.
Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them.
[ "aba\n", "ab\n" ]
[ "aba", "aabaa" ]
In the first example, "aba" is a subsequence of "aba" which is a palindrome. In the second example, "ab" is a subsequence of "aabaa" which is a palindrome.
500
[ { "input": "aba", "output": "abaaba" }, { "input": "ab", "output": "abba" }, { "input": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmk...
1,603,513,435
2,147,483,647
Python 3
OK
TESTS
48
108
0
s=input() x=s[::-1] if(s==x): print(s) else: print(s+x)
Title: Palindromic Supersequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily co...
```python s=input() x=s[::-1] if(s==x): print(s) else: print(s+x) ```
3
825
A
Binary Protocol
PROGRAMMING
1,100
[ "implementation" ]
null
null
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: - Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in ord...
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*. The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts...
Print the decoded number.
[ "3\n111\n", "9\n110011101\n" ]
[ "3\n", "2031\n" ]
none
0
[ { "input": "3\n111", "output": "3" }, { "input": "9\n110011101", "output": "2031" }, { "input": "1\n1", "output": "1" }, { "input": "3\n100", "output": "100" }, { "input": "5\n10001", "output": "1001" }, { "input": "14\n11001100011000", "output": "...
1,504,644,067
2,147,483,647
Python 3
OK
TESTS
13
62
0
input() count = 0 out = '' for l in input(): if l == '1': count +=1 else: out=out+str(count) count = 0 out=out+str(count) print(out)
Title: Binary Protocol Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: - Each digit is represented with number of '1' charact...
```python input() count = 0 out = '' for l in input(): if l == '1': count +=1 else: out=out+str(count) count = 0 out=out+str(count) print(out) ```
3
675
B
Restoring Painting
PROGRAMMING
1,400
[ "brute force", "constructive algorithms", "math" ]
null
null
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. - The painting is a square 3<=×<=3, each cell contains a single integer from 1 to *n*,...
The first line of the input contains five integers *n*, *a*, *b*, *c* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=*n*) — maximum possible value of an integer in the cell and four integers that Vasya remembers.
Print one integer — the number of distinct valid squares.
[ "2 1 1 1 2\n", "3 3 1 2 3\n" ]
[ "2\n", "6\n" ]
Below are all the possible paintings for the first sample. <img class="tex-graphics" src="https://espresso.codeforces.com/c4c53d4e7b6814d8aad7b72604b6089d61dadb48.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/46a6ad6a5d3db202f3779b045b9dc77fc2348cf1....
1,000
[ { "input": "2 1 1 1 2", "output": "2" }, { "input": "3 3 1 2 3", "output": "6" }, { "input": "1 1 1 1 1", "output": "1" }, { "input": "1000 522 575 426 445", "output": "774000" }, { "input": "99000 52853 14347 64237 88869", "output": "1296306000" }, { ...
1,469,919,335
2,147,483,647
Python 3
OK
TESTS
58
218
0
n,a,b,c,d=map(int,input().split()) M=0 for E in range(1,n+1): F=E+b-c H=E+a-d K=E+a+b-c-d if 0<F<=n and 0<H<=n and 0<K<=n:M+=n print(M)
Title: Restoring Painting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some ...
```python n,a,b,c,d=map(int,input().split()) M=0 for E in range(1,n+1): F=E+b-c H=E+a-d K=E+a+b-c-d if 0<F<=n and 0<H<=n and 0<K<=n:M+=n print(M) ```
3
950
A
Left-handers, Right-handers and Ambidexters
PROGRAMMING
800
[ "implementation", "math" ]
null
null
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and ...
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
[ "1 4 2\n", "5 5 5\n", "0 2 0\n" ]
[ "6\n", "14\n", "0\n" ]
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five l...
500
[ { "input": "1 4 2", "output": "6" }, { "input": "5 5 5", "output": "14" }, { "input": "0 2 0", "output": "0" }, { "input": "30 70 34", "output": "128" }, { "input": "89 32 24", "output": "112" }, { "input": "89 44 77", "output": "210" }, { ...
1,520,960,157
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
5,632,000
from math import* A = [] A = input().split() B=[] B.insert(0,int(A[0])) B.insert(1,int(A[1])) B.insert(2,int(A[2])) count = min(B[0], B[1]) razn=abs(B[0]-B[1]) if (B[2]>=razn): count += razn B[2] = B[2]/2 count += int(B[2]) else: count += B[2] print(count)
Title: Left-handers, Right-handers and Ambidexters Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand....
```python from math import* A = [] A = input().split() B=[] B.insert(0,int(A[0])) B.insert(1,int(A[1])) B.insert(2,int(A[2])) count = min(B[0], B[1]) razn=abs(B[0]-B[1]) if (B[2]>=razn): count += razn B[2] = B[2]/2 count += int(B[2]) else: count += B[2] print(count) ```
0
527
A
Playing with Paper
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle...
The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=1012) — the sizes of the original sheet of paper.
Print a single integer — the number of ships that Vasya will make.
[ "2 1\n", "10 7\n", "1000000000000 1\n" ]
[ "2\n", "6\n", "1000000000000\n" ]
Pictures to the first and second sample test.
500
[ { "input": "2 1", "output": "2" }, { "input": "10 7", "output": "6" }, { "input": "1000000000000 1", "output": "1000000000000" }, { "input": "3 1", "output": "3" }, { "input": "4 1", "output": "4" }, { "input": "3 2", "output": "3" }, { "in...
1,468,050,868
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
2,000
0
d = [int(x) for x in input().split()] a,b = d[0], d[1] sq = 0 while a != b: if a > b: sq+=1 a-=b else: sq+=1 b-=a if a == b: print(sq+1) else: print(sq)
Title: Playing with Paper Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a squ...
```python d = [int(x) for x in input().split()] a,b = d[0], d[1] sq = 0 while a != b: if a > b: sq+=1 a-=b else: sq+=1 b-=a if a == b: print(sq+1) else: print(sq) ```
0
2
A
Winner
PROGRAMMING
1,500
[ "hashing", "implementation" ]
A. Winner
1
64
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ...
Print the name of the winner.
[ "3\nmike 3\nandrew 5\nmike 2\n", "3\nandrew 3\nandrew 2\nmike 5\n" ]
[ "andrew\n", "andrew\n" ]
none
0
[ { "input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew" }, { "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew" }, { "input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "output": "kaxqybeultn" },...
1,567,289,139
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
9
280
0
n = int(input()) name = [] cnt = [] maxs = 0 maxn = '' for _ in range(n): s = input().split() if s[0] not in name: name.append(s[0]) cnt.append(int(s[1])) else: cnt[name.index(s[0])] += int(s[1]) if cnt[name.index(s[0])] > maxs: maxs = cnt[name.index(s[0])]...
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes...
```python n = int(input()) name = [] cnt = [] maxs = 0 maxn = '' for _ in range(n): s = input().split() if s[0] not in name: name.append(s[0]) cnt.append(int(s[1])) else: cnt[name.index(s[0])] += int(s[1]) if cnt[name.index(s[0])] > maxs: maxs = cnt[name.in...
0
584
D
Dima and Lisa
PROGRAMMING
1,800
[ "brute force", "math", "number theory" ]
null
null
Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes. More formally, you are given an odd numer *n*. Find a set of numbers *p**i* (1<=≤<=*i*<=≤<=*k*), such that 1. 1<=...
The single line contains an odd number *n* (3<=≤<=*n*<=&lt;<=109).
In the first line print *k* (1<=≤<=*k*<=≤<=3), showing how many numbers are in the representation you found. In the second line print numbers *p**i* in any order. If there are multiple possible solutions, you can print any of them.
[ "27\n" ]
[ "3\n5 11 11\n" ]
A prime is an integer strictly larger than one that is divisible only by one and by itself.
2,000
[ { "input": "27", "output": "3\n2 2 23" }, { "input": "3", "output": "1\n3" }, { "input": "25", "output": "2\n2 23" }, { "input": "9", "output": "2\n2 7" }, { "input": "91", "output": "2\n2 89" }, { "input": "57", "output": "3\n2 2 53" }, { ...
1,675,704,523
2,147,483,647
PyPy 3-64
OK
TESTS
109
77
1,638,400
import sys import math input = sys.stdin.readline def p(n): for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False else: return True n = int(input()) if p(n): print(1) print(n) quit() if p(n - 2): print(2) print(n - 2, 2) quit() z ...
Title: Dima and Lisa Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes. More formally, ...
```python import sys import math input = sys.stdin.readline def p(n): for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False else: return True n = int(input()) if p(n): print(1) print(n) quit() if p(n - 2): print(2) print(n - 2, 2) ...
3
588
B
Duff in Love
PROGRAMMING
1,300
[ "math" ]
null
null
Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=&gt;<=1 such that *a*2 is a divisor of *x*. Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek want...
The first and only line of input contains one integer, *n* (1<=≤<=*n*<=≤<=1012).
Print the answer in one line.
[ "10\n", "12\n" ]
[ "10\n", "6\n" ]
In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely. In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2<sup class="upper-index">2</sup>, so 12 is not lovely, while 6 is indeed lovely.
1,000
[ { "input": "10", "output": "10" }, { "input": "12", "output": "6" }, { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "4", "output": "2" }, { "input": "8", "output": "2" }, { "input": "3", "output": "3" }, ...
1,636,452,640
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
4,505,600
import math def sq(n): return int(math.sqrt(n))+1 def judge(k): for i in range(2,sq(n)): if(k%(i*i) == 0): return False return True while True: n=eval(input()) ans=0 f = 0 for i in range(1,sq(n)): k = n / i if(n%i==0 and judge(k)): f=1 ...
Title: Duff in Love Time Limit: None seconds Memory Limit: None megabytes Problem Description: Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=&gt;<=1 such that *a*2 is a divisor of *x*. Malek has a number store! In his store, he has...
```python import math def sq(n): return int(math.sqrt(n))+1 def judge(k): for i in range(2,sq(n)): if(k%(i*i) == 0): return False return True while True: n=eval(input()) ans=0 f = 0 for i in range(1,sq(n)): k = n / i if(n%i==0 and judge(k)): f=...
-1
150
C
Smart Cheater
PROGRAMMING
2,200
[ "data structures", "math", "probabilities" ]
null
null
I guess there's not much point in reminding you that Nvodsk winters aren't exactly hot. That increased the popularity of the public transport dramatically. The route of bus 62 has exactly *n* stops (stop 1 goes first on its way and stop *n* goes last). The stops are positioned on a straight line and their coordinates a...
The first line contains three integers *n*, *m* and *c* (2<=≤<=*n*<=≤<=150<=000, 1<=≤<=*m*<=≤<=300<=000, 1<=≤<=*c*<=≤<=10<=000). The next line contains *n* integers *x**i* (0<=≤<=*x**i*<=≤<=109, *x*1<==<=0, *x**i*<=&lt;<=*x**i*<=+<=1) — the coordinates of the stops on the bus's route. The third line contains *n*<=-<=...
Print the single real number — the maximum expectation of the conductor's profit. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, i...
[ "3 3 10\n0 10 100\n100 0\n1 2\n2 3\n1 3\n", "10 8 187\n0 10 30 70 150 310 630 1270 2550 51100\n13 87 65 0 100 44 67 3 4\n1 10\n2 9\n3 8\n1 5\n6 10\n2 7\n4 10\n4 5\n" ]
[ "90.000000000\n", "76859.990000000\n" ]
A comment to the first sample: The first and third passengers get tickets from stop 1 to stop 2. The second passenger doesn't get a ticket. There always is inspection on the segment 1-2 but both passengers have the ticket for it. There never is an inspection on the segment 2-3, that's why the second passenger gets awa...
1,000
[]
1,668,610,127
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
import sys from math import gcd from collections import defaultdict input = sys.stdin.readline get_int = lambda: int(input().rstrip()) get_arr = lambda: [int(w) for w in input().split()] get_str = lambda: input().rstrip() n, m, c = get_arr() xs = get_arr() ps = get_arr() ost = [0] * (n + 1) for _...
Title: Smart Cheater Time Limit: None seconds Memory Limit: None megabytes Problem Description: I guess there's not much point in reminding you that Nvodsk winters aren't exactly hot. That increased the popularity of the public transport dramatically. The route of bus 62 has exactly *n* stops (stop 1 goes first on i...
```python import sys from math import gcd from collections import defaultdict input = sys.stdin.readline get_int = lambda: int(input().rstrip()) get_arr = lambda: [int(w) for w in input().split()] get_str = lambda: input().rstrip() n, m, c = get_arr() xs = get_arr() ps = get_arr() ost = [0] * (n + 1...
0
729
B
Spotlights
PROGRAMMING
1,200
[ "dp", "implementation" ]
null
null
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a spotlight on the stage in some good position. The spotlight will project light in one of t...
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan. The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell ...
Print one integer — the number of good positions for placing the spotlight.
[ "2 4\n0 1 0 0\n1 0 1 0\n", "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n" ]
[ "9\n", "20\n" ]
In the first example the following positions are good: 1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and...
1,000
[ { "input": "2 4\n0 1 0 0\n1 0 1 0", "output": "9" }, { "input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0", "output": "20" }, { "input": "1 5\n1 1 0 0 0", "output": "3" }, { "input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0", "output": "20" }, { "input": "3 ...
1,551,188,786
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
1,000
11,059,200
n,m=map(int,input().split()) M=[[0 for i in range(m)] for i in range(n)] L=[list(map(int,input().split())) for i in range(n)] for i in range(n) : p=0 for j in range(m) : if L[i][j]==1 : p=1 else : if p==1 : M[i][j]+=1 p=0 for j in range(m-1,-1,-1) : if L[i][j]==1 : ...
Title: Spotlights Time Limit: None seconds Memory Limit: None megabytes Problem Description: Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to pl...
```python n,m=map(int,input().split()) M=[[0 for i in range(m)] for i in range(n)] L=[list(map(int,input().split())) for i in range(n)] for i in range(n) : p=0 for j in range(m) : if L[i][j]==1 : p=1 else : if p==1 : M[i][j]+=1 p=0 for j in range(m-1,-1,-1) : if L[i]...
0
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,695,937,600
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
x= int (input()) print ((((x//5)//4)//3)//2)
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()) print ((((x//5)//4)//3)//2) ```
0
202
A
LLPS
PROGRAMMING
800
[ "binary search", "bitmasks", "brute force", "greedy", "implementation", "strings" ]
null
null
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*...
The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10.
Print the lexicographically largest palindromic subsequence of string *s*.
[ "radar\n", "bowwowwow\n", "codeforces\n", "mississipp\n" ]
[ "rr\n", "wwwww\n", "s\n", "ssss\n" ]
Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".
500
[ { "input": "radar", "output": "rr" }, { "input": "bowwowwow", "output": "wwwww" }, { "input": "codeforces", "output": "s" }, { "input": "mississipp", "output": "ssss" }, { "input": "tourist", "output": "u" }, { "input": "romka", "output": "r" }, ...
1,645,849,458
2,147,483,647
Python 3
OK
TESTS
54
92
0
s=input() l=set(s) m=max(l) print(s.count(m)*m)
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() l=set(s) m=max(l) print(s.count(m)*m) ```
3
580
C
Kefa and Park
PROGRAMMING
1,500
[ "dfs and similar", "graphs", "trees" ]
null
null
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the v...
The first line contains two integers, *n* and *m* (2<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=*n*) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where each *a**i* either equals to 0 (then ...
A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most *m* consecutive vertices with cats.
[ "4 1\n1 1 0 0\n1 2\n1 3\n1 4\n", "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n" ]
[ "2\n", "2\n" ]
Let us remind you that a tree is a connected graph on *n* vertices and *n* - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if i...
1,500
[ { "input": "4 1\n1 1 0 0\n1 2\n1 3\n1 4", "output": "2" }, { "input": "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7", "output": "2" }, { "input": "3 2\n1 1 1\n1 2\n2 3", "output": "0" }, { "input": "5 2\n1 1 0 1 1\n1 2\n2 3\n3 4\n4 5", "output": "1" }, { "inpu...
1,693,151,934
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
62
0
n, m = map(int, input().split()) cats = list(map(int, input().split())) adjList = dict() parent = dict() for i in range (n) : adjList[i+1] = [] for _ in range (n-1) : a, b = map(int, input().split()) adjList[a].append(b) adjList[b].append(a) if a>b : parent[a] = b else : parent[b] = a...
Title: Kefa and Park Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house...
```python n, m = map(int, input().split()) cats = list(map(int, input().split())) adjList = dict() parent = dict() for i in range (n) : adjList[i+1] = [] for _ in range (n-1) : a, b = map(int, input().split()) adjList[a].append(b) adjList[b].append(a) if a>b : parent[a] = b else : par...
0
999
A
Mishka and Contest
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses ...
The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are...
Print one integer — the maximum number of problems Mishka can solve.
[ "8 4\n4 2 3 1 5 1 6 4\n", "5 2\n3 1 2 1 3\n", "5 100\n12 34 55 43 21\n" ]
[ "5\n", "0\n", "5\n" ]
In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$. In the second example, M...
0
[ { "input": "8 4\n4 2 3 1 5 1 6 4", "output": "5" }, { "input": "5 2\n3 1 2 1 3", "output": "0" }, { "input": "5 100\n12 34 55 43 21", "output": "5" }, { "input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 1...
1,616,618,937
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
62
307,200
n, k = list(map(int, input().split())) a = list(map(int, input().split())) i = 0 j = n-1 z = 0 l = True r = True while l or r: if a[i] <= k: i += 1 else: l = False if a[j] <= k: j -= 1 z += 1 else: r = False if j <= i: break ...
Title: Mishka and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his...
```python n, k = list(map(int, input().split())) a = list(map(int, input().split())) i = 0 j = n-1 z = 0 l = True r = True while l or r: if a[i] <= k: i += 1 else: l = False if a[j] <= k: j -= 1 z += 1 else: r = False if j <= i: ...
0
29
A
Spit Problem
PROGRAMMING
1,000
[ "brute force" ]
A. Spit Problem
2
256
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at wh...
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
[ "2\n0 1\n1 -1\n", "3\n0 1\n1 1\n2 -2\n", "5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "2\n0 1\n1 -1", "output": "YES" }, { "input": "3\n0 1\n1 1\n2 -2", "output": "NO" }, { "input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES" }, { "input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n759...
1,633,041,376
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
6,656,000
n=int(input()) lx=set() for i in range(n): x,d=map(int,input().split()) if (x+d,x) in lx: print("YES") exit() lx.add((x+d,x)) print("NO")
Title: Spit Problem Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know ...
```python n=int(input()) lx=set() for i in range(n): x,d=map(int,input().split()) if (x+d,x) in lx: print("YES") exit() lx.add((x+d,x)) print("NO") ```
0
181
B
Number of Triplets
PROGRAMMING
1,300
[ "binary search", "brute force" ]
null
null
You are given *n* points on a plane. All points are different. Find the number of different groups of three points (*A*,<=*B*,<=*C*) such that point *B* is the middle of segment *AC*. The groups of three points are considered unordered, that is, if point *B* is the middle of segment *AC*, then groups (*A*,<=*B*,<=*C...
The first line contains a single integer *n* (3<=≤<=*n*<=≤<=3000) — the number of points. Next *n* lines contain the points. The *i*-th line contains coordinates of the *i*-th point: two space-separated integers *x**i*,<=*y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000). It is guaranteed that all given points are diff...
Print the single number — the answer to the problem.
[ "3\n1 1\n2 2\n3 3\n", "3\n0 0\n-1 0\n0 1\n" ]
[ "1\n", "0\n" ]
none
1,000
[ { "input": "3\n1 1\n2 2\n3 3", "output": "1" }, { "input": "3\n0 0\n-1 0\n0 1", "output": "0" }, { "input": "4\n0 0\n1 0\n2 0\n3 0", "output": "2" }, { "input": "5\n0 -1\n0 -2\n0 -3\n0 -4\n0 -5", "output": "4" }, { "input": "7\n1 1\n-1 -1\n1 0\n0 1\n-1 0\n0 -1\n0 ...
1,641,265,774
2,147,483,647
PyPy 3-64
OK
TESTS
37
716
77,619,200
N = 1000 n = int(input()) x = [] y = [] f = [[0 for x in range(3*N)] for y in range(3*N)] s = 0 for i in range(n): u, v = map(int, input().split()) x.append(u) y.append(v) f[u+N][v+N] = 1 for i in range(n): for j in range(i+1, n): u = x[i]+x[j] v = y[i]+y[j] s += not(u % 2 or v % 2) and f[u//2+N][v//2+N] pri...
Title: Number of Triplets Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* points on a plane. All points are different. Find the number of different groups of three points (*A*,<=*B*,<=*C*) such that point *B* is the middle of segment *AC*. The groups of three points ar...
```python N = 1000 n = int(input()) x = [] y = [] f = [[0 for x in range(3*N)] for y in range(3*N)] s = 0 for i in range(n): u, v = map(int, input().split()) x.append(u) y.append(v) f[u+N][v+N] = 1 for i in range(n): for j in range(i+1, n): u = x[i]+x[j] v = y[i]+y[j] s += not(u % 2 or v % 2) and f[u//2+N][v...
3
291
A
Spyke Talks
PROGRAMMING
800
[ "*special", "implementation", "sortings" ]
null
null
Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session numbe...
The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the number of secretaries in Polycarpus's corporation. The next line contains *n* space-separated integers: *id*1,<=*id*2,<=...,<=*id**n* (0<=≤<=*id**i*<=≤<=109). Number *id**i* equals the number of the call session of the *i*-th secretary, if the secretary is t...
Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place.
[ "6\n0 1 7 1 7 10\n", "3\n1 1 1\n", "1\n0\n" ]
[ "2\n", "-1\n", "0\n" ]
In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed.
500
[ { "input": "6\n0 1 7 1 7 10", "output": "2" }, { "input": "3\n1 1 1", "output": "-1" }, { "input": "1\n0", "output": "0" }, { "input": "5\n2 2 1 1 3", "output": "2" }, { "input": "1\n1", "output": "0" }, { "input": "10\n4 21 3 21 21 1 1 2 2 3", "ou...
1,659,244,589
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
92
0
n = int(input()) vals = [int(x) for x in input().strip().split()] count = 0 for i in vals: counter = 0 for j in vals: if i == j: counter+=1 count+=1 if counter % 2 != 0 and counter != 1: print(-1) exit() print((count-n)//2)
Title: Spyke Talks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each othe...
```python n = int(input()) vals = [int(x) for x in input().strip().split()] count = 0 for i in vals: counter = 0 for j in vals: if i == j: counter+=1 count+=1 if counter % 2 != 0 and counter != 1: print(-1) exit() print((count-n)//2) ```
0
691
E
Xor-sequences
PROGRAMMING
1,900
[ "matrices" ]
null
null
You are given *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n*. A sequence of integers *x*1,<=<=*x*2,<=<=...,<=<=*x**k* is called a "xor-sequence" if for every 1<=<=≤<=<=*i*<=<=≤<=<=*k*<=-<=1 the number of ones in the binary representation of the number *x**i* *x**i*<=<=+<=<=1's is a multiple of 3 and for all 1<=≤<=*i*...
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1018) — the number of given integers and the length of the "xor-sequences". The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1018).
Print the only integer *c* — the number of "xor-sequences" of length *k* modulo 109<=+<=7.
[ "5 2\n15 1 2 4 8\n", "5 1\n15 1 2 4 8\n" ]
[ "13\n", "5\n" ]
none
0
[ { "input": "5 2\n15 1 2 4 8", "output": "13" }, { "input": "5 1\n15 1 2 4 8", "output": "5" }, { "input": "10 1\n44 65 23 44 100 19 19 23 19 40", "output": "10" }, { "input": "10 2\n93 93 85 48 44 98 93 100 98 98", "output": "52" }, { "input": "10 100\n22 0 41 63 ...
1,633,449,818
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
6
3,000
29,491,200
import sys input = sys.stdin.readline def matmul(a, b, n): c = [] for i in range(n): for j in range(n): x = 0 for k in range(n): x += a[n * i + k] * b[n * k + j] % mod x %= mod c.append(x) return c n, k = map(int, in...
Title: Xor-sequences Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n*. A sequence of integers *x*1,<=<=*x*2,<=<=...,<=<=*x**k* is called a "xor-sequence" if for every 1<=<=≤<=<=*i*<=<=≤<=<=*k*<=-<=1 the number of ones in the binar...
```python import sys input = sys.stdin.readline def matmul(a, b, n): c = [] for i in range(n): for j in range(n): x = 0 for k in range(n): x += a[n * i + k] * b[n * k + j] % mod x %= mod c.append(x) return c n, k = m...
0
900
B
Position in Fraction
PROGRAMMING
1,300
[ "math", "number theory" ]
null
null
You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point.
The first contains three single positive integers *a*, *b*, *c* (1<=≤<=*a*<=&lt;<=*b*<=≤<=105, 0<=≤<=*c*<=≤<=9).
Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
[ "1 2 0\n", "2 3 7\n" ]
[ "2", "-1" ]
The fraction in the first example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/896357459a466614a0542f34c9cfb0cef1afc9ed.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first zero stands on second position. The fraction in the second example ...
1,000
[ { "input": "1 2 0", "output": "2" }, { "input": "2 3 7", "output": "-1" }, { "input": "1 100000 1", "output": "5" }, { "input": "1 7 7", "output": "6" }, { "input": "99999 100000 8", "output": "-1" }, { "input": "44102 73848 2", "output": "132" }...
1,565,868,623
23
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n = input() c = [-9] + [0] * n p, q = 0, 0 for i in map(int, raw_input().split()): if p < i: q = p p = i c[p] -= 1 elif q < i: q = i c[p] += 1 print c.index(max(c))
Title: Position in Fraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point. Input Specification: The first contains three single positive integers *a*, *b*, ...
```python n = input() c = [-9] + [0] * n p, q = 0, 0 for i in map(int, raw_input().split()): if p < i: q = p p = i c[p] -= 1 elif q < i: q = i c[p] += 1 print c.index(max(c)) ```
-1
426
A
Sereja and Mugs
PROGRAMMING
800
[ "implementation" ]
null
null
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume th...
The first line contains integers *n* and *s* (2<=≤<=*n*<=≤<=100; 1<=≤<=*s*<=≤<=1000) — the number of mugs and the volume of the cup. The next line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10). Number *a**i* means the volume of the *i*-th mug.
In a single line, print "YES" (without the quotes) if his friends can play in the described manner, and "NO" (without the quotes) otherwise.
[ "3 4\n1 1 1\n", "3 4\n3 1 3\n", "3 4\n4 4 4\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "3 4\n1 1 1", "output": "YES" }, { "input": "3 4\n3 1 3", "output": "YES" }, { "input": "3 4\n4 4 4", "output": "NO" }, { "input": "2 1\n1 10", "output": "YES" }, { "input": "3 12\n5 6 6", "output": "YES" }, { "input": "4 10\n6 3 8 7", "...
1,585,130,826
2,147,483,647
PyPy 3
OK
TESTS
42
155
0
n, s = map(int, input().split()) a = [int(s) for s in input().split()] a = sorted(a) if sum(a) - a[len(a)-1] <= s: print('YES') else: print('NO')
Title: Sereja and Mugs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non...
```python n, s = map(int, input().split()) a = [int(s) for s in input().split()] a = sorted(a) if sum(a) - a[len(a)-1] <= s: print('YES') else: print('NO') ```
3
748
A
Santa Claus and a Place in a Class
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane ar...
The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.
Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.
[ "4 3 9\n", "4 3 24\n", "2 4 4\n" ]
[ "2 2 L\n", "4 3 R\n", "1 2 R\n" ]
The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his pla...
500
[ { "input": "4 3 9", "output": "2 2 L" }, { "input": "4 3 24", "output": "4 3 R" }, { "input": "2 4 4", "output": "1 2 R" }, { "input": "3 10 24", "output": "2 2 R" }, { "input": "10 3 59", "output": "10 3 L" }, { "input": "10000 10000 160845880", "...
1,538,411,558
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
3
124
0
s1 = input() li=s1.split() m = int(s1[0]) n = int(s1[2]) san = int(li[2]) # print(m,n,san) sumdes = 0 for i in range(m): sumdes = sumdes + 2*n if san <= sumdes: lane = i + 1 break # print(lane,sumdes) desk = n for i in range(n): if san > sumdes-2: break sumdes = ...
Title: Santa Claus and a Place in a Class Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two work...
```python s1 = input() li=s1.split() m = int(s1[0]) n = int(s1[2]) san = int(li[2]) # print(m,n,san) sumdes = 0 for i in range(m): sumdes = sumdes + 2*n if san <= sumdes: lane = i + 1 break # print(lane,sumdes) desk = n for i in range(n): if san > sumdes-2: break ...
-1
991
A
If at first you don't succeed...
PROGRAMMING
1,000
[ "implementation" ]
null
null
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam. Some of them celebrated in the BugDonalds restaurant, some of them...
The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$).
If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam. ...
[ "10 10 5 20\n", "2 2 0 4\n", "2 2 2 1\n" ]
[ "5", "-1", "-1" ]
The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam. In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students...
500
[ { "input": "10 10 5 20", "output": "5" }, { "input": "2 2 0 4", "output": "-1" }, { "input": "2 2 2 1", "output": "-1" }, { "input": "98 98 97 100", "output": "1" }, { "input": "1 5 2 10", "output": "-1" }, { "input": "5 1 2 10", "output": "-1" }...
1,685,201,943
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
31
0
a,b,c,n = map(int,input().split()) x = a+b-c if n-x>0: print(n-x) else: print(-1)
Title: If at first you don't succeed... Time Limit: None seconds Memory Limit: None megabytes Problem Description: Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group w...
```python a,b,c,n = map(int,input().split()) x = a+b-c if n-x>0: print(n-x) else: print(-1) ```
0
989
B
A Tide of Riverscape
PROGRAMMING
1,200
[ "constructive algorithms", "strings" ]
null
null
"Time," Mino thinks aloud. "What?" "Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this." "And what are you recording?" "You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence. Doubtfully, Kanno peeks a...
The first line contains two space-separated integers $n$ and $p$ ($1 \leq p \leq n \leq 2000$) — the length of the given string and the supposed period, respectively. The second line contains a string $s$ of $n$ characters — Mino's records. $s$ only contains characters '0', '1' and '.', and contains at least one '.' c...
Output one line — if it's possible that $p$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
[ "10 7\n1.0.1.0.1.\n", "10 6\n1.0.1.1000\n", "10 9\n1........1\n" ]
[ "1000100010\n", "1001101000\n", "No\n" ]
In the first example, $7$ is not a period of the resulting string because the $1$-st and $8$-th characters of it are different. In the second example, $6$ is not a period of the resulting string because the $4$-th and $10$-th characters of it are different. In the third example, $9$ is always a period because the onl...
1,000
[ { "input": "10 7\n1.0.1.0.1.", "output": "1000100010" }, { "input": "10 6\n1.0.1.1000", "output": "1001101000" }, { "input": "10 9\n1........1", "output": "No" }, { "input": "1 1\n.", "output": "No" }, { "input": "5 1\n0...1", "output": "00001" }, { "i...
1,609,345,910
2,147,483,647
PyPy 3
OK
TESTS
59
155
1,331,200
n,p=map(int, input().split()) s=input() t=s.replace('.', '0') if(all(t[i] == t[i + p] for i in range(n - p))): k=-1 for r in range(p - 1, -1, -1): x=s[r::p].rfind('.') if(x!=-1 and s[r::p]!='.'): k=max(k,x*p+r) if(k==-1): print('No') else: print(t[...
Title: A Tide of Riverscape Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Time," Mino thinks aloud. "What?" "Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this." "And what are you recording?" "You see it, tide. Everything has its...
```python n,p=map(int, input().split()) s=input() t=s.replace('.', '0') if(all(t[i] == t[i + p] for i in range(n - p))): k=-1 for r in range(p - 1, -1, -1): x=s[r::p].rfind('.') if(x!=-1 and s[r::p]!='.'): k=max(k,x*p+r) if(k==-1): print('No') else: ...
3
576
A
Vasya and Petya's Game
PROGRAMMING
1,500
[ "math", "number theory" ]
null
null
Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number. Petya can ask questions like: "Is the unknown number divisible by number *y*?". The game is played by the following rules: first Petya asks all the questions that interest him (also, he can a...
A single line contains number *n* (1<=≤<=*n*<=≤<=103).
Print the length of the sequence of questions *k* (0<=≤<=*k*<=≤<=*n*), followed by *k* numbers — the questions *y**i* (1<=≤<=*y**i*<=≤<=*n*). If there are several correct sequences of questions of the minimum length, you are allowed to print any of them.
[ "4\n", "6\n" ]
[ "3\n2 4 3 \n", "4\n2 4 3 5 \n" ]
The sequence from the answer to the first sample test is actually correct. If the unknown number is not divisible by one of the sequence numbers, it is equal to 1. If the unknown number is divisible by 4, it is 4. If the unknown number is divisible by 3, then the unknown number is 3. Otherwise, it is equal to 2. Th...
500
[ { "input": "4", "output": "3\n2 4 3 " }, { "input": "6", "output": "4\n2 4 3 5 " }, { "input": "1", "output": "0" }, { "input": "15", "output": "9\n2 4 8 3 9 5 7 11 13 " }, { "input": "19", "output": "12\n2 4 8 16 3 9 5 7 11 13 17 19 " }, { "input": "2...
1,572,446,527
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
93
0
from math import sqrt n = int(input()) ans = [] my_dict = {} def is_prime(n): if n == 2: return True elif n < 2: return False for i in range(2, int(sqrt(n))+1): if n%i == 0: return False return True def divisors(n): divisores = [] for i in range(2, n): if n%i == 0: divisores.append(i) return di...
Title: Vasya and Petya's Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number. Petya can ask questions like: "Is the unknown number divisible by number *y*?". The...
```python from math import sqrt n = int(input()) ans = [] my_dict = {} def is_prime(n): if n == 2: return True elif n < 2: return False for i in range(2, int(sqrt(n))+1): if n%i == 0: return False return True def divisors(n): divisores = [] for i in range(2, n): if n%i == 0: divisores.append(i) ...
0
393
A
Nineteen
PROGRAMMING
0
[]
null
null
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ...
The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100.
Print a single integer — the maximum number of "nineteen"s that she can get in her string.
[ "nniinneetteeeenn\n", "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n", "nineteenineteen\n" ]
[ "2", "2", "2" ]
none
500
[ { "input": "nniinneetteeeenn", "output": "2" }, { "input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii", "output": "2" }, { "input": "nineteenineteen", "output": "2" }, { "input": "nssemsnnsitjtihtthij", "output": "0" }, { "input": "eehihnttehtherjsihihn...
1,602,611,917
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
124
0
import math a= input() b= a.count('n') c= a.count('i') d= a.count('e') e= a.count('t') print( min(math.ceil((b+2)//3),c,d//3,e))
Title: Nineteen Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiinetee...
```python import math a= input() b= a.count('n') c= a.count('i') d= a.count('e') e= a.count('t') print( min(math.ceil((b+2)//3),c,d//3,e)) ```
0
281
A
Word Capitalization
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
[ "ApPLe\n", "konjac\n" ]
[ "ApPLe\n", "Konjac\n" ]
none
500
[ { "input": "ApPLe", "output": "ApPLe" }, { "input": "konjac", "output": "Konjac" }, { "input": "a", "output": "A" }, { "input": "A", "output": "A" }, { "input": "z", "output": "Z" }, { "input": "ABACABA", "output": "ABACABA" }, { "input": "...
1,696,346,428
2,147,483,647
PyPy 3
OK
TESTS
25
186
0
# -*- coding: utf-8 -*- """ Created on Tue Oct 3 23:19:43 2023 @author: 袁兆瑞 """ a = input() print(a[0].capitalize() + a[1:])
Title: Word Capitalization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. Input...
```python # -*- coding: utf-8 -*- """ Created on Tue Oct 3 23:19:43 2023 @author: 袁兆瑞 """ a = input() print(a[0].capitalize() + a[1:]) ```
3
10
A
Power Consumption Calculation
PROGRAMMING
900
[ "implementation" ]
A. Power Consumption Calculation
1
256
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T...
The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;...
Output the answer to the problem.
[ "1 3 2 1 5 10\n0 10\n", "2 8 4 2 5 10\n20 30\n50 100\n" ]
[ "30", "570" ]
none
0
[ { "input": "1 3 2 1 5 10\n0 10", "output": "30" }, { "input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570" }, { "input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436", "output": "8445" }, { "input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945", "output": "5287...
1,694,109,847
2,147,483,647
Python 3
OK
TESTS
30
92
0
n,p1,p2,p3,t1,t2=map(int,input().split()) p=0 t=0 for i in range(n): a,b=map(int,input().split()) d=a-t if i==0: p=p+p1*(b-a) if i!=0 and i<n: if d<=t1: p=p+((b-a)+d)*p1 if d>t1 and d<=t1+t2: p=p+((b-a)+t1)*p1+p2*(d-t1) if d>t1+t2: ...
Title: Power Consumption Calculation Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard f...
```python n,p1,p2,p3,t1,t2=map(int,input().split()) p=0 t=0 for i in range(n): a,b=map(int,input().split()) d=a-t if i==0: p=p+p1*(b-a) if i!=0 and i<n: if d<=t1: p=p+((b-a)+d)*p1 if d>t1 and d<=t1+t2: p=p+((b-a)+t1)*p1+p2*(d-t1) if d>...
3.954
5
C
Longest Regular Bracket Sequence
PROGRAMMING
1,900
[ "constructive algorithms", "data structures", "dp", "greedy", "sortings", "strings" ]
C. Longest Regular Bracket Sequence
2
256
This is yet another problem dealing with regular bracket sequences. We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not....
The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106.
Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1".
[ ")((())))(()())\n", "))(\n" ]
[ "6 2\n", "0 1\n" ]
none
0
[ { "input": ")((())))(()())", "output": "6 2" }, { "input": "))(", "output": "0 1" }, { "input": "()(())()", "output": "8 1" }, { "input": "((((()(((", "output": "2 1" }, { "input": "))))()())))", "output": "4 1" }, { "input": "(()())()(())()()())())()(...
1,587,566,265
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
import sys import math t = sys.stdin.read().split("\n") if (len(t) > 1): #t.pop(-1) t = t[0] def check_for_matching(string): o = [] index = 0 #print("=========================") #print("String:" + string) for char in string: index +=1 if char == "(": ...
Title: Longest Regular Bracket Sequence Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: This is yet another problem dealing with regular bracket sequences. We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical exp...
```python import sys import math t = sys.stdin.read().split("\n") if (len(t) > 1): #t.pop(-1) t = t[0] def check_for_matching(string): o = [] index = 0 #print("=========================") #print("String:" + string) for char in string: index +=1 if char ==...
-1
721
B
Passwords
PROGRAMMING
1,100
[ "implementation", "math", "sortings", "strings" ]
null
null
Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration. Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitr...
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds. The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of ...
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
[ "5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n", "4 100\n11\n22\n1\n2\n22\n" ]
[ "1 15\n", "3 4\n" ]
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he ente...
1,000
[ { "input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc", "output": "1 15" }, { "input": "4 100\n11\n22\n1\n2\n22", "output": "3 4" }, { "input": "1 1\na1\na1", "output": "1 1" }, { "input": "1 100\na1\na1", "output": "1 1" }, { "input": "2 1\nabc\nAbc\nAbc", "output": ...
1,576,229,675
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
140
0
n,k=map(int,input().split()) f=[] for i in range(n): s=str(input()) f.append(len(s)) d=len(str(input())) f.append(d) f.append(d+1) f.sort() best_t=f.index(d)+1+f.index(d)//k*5 wor_t=f.index(d+1)+(f.index(d+1)-1)//k*5-1 print(best_t,wor_t)
Title: Passwords Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration. Vanya will enter passwords...
```python n,k=map(int,input().split()) f=[] for i in range(n): s=str(input()) f.append(len(s)) d=len(str(input())) f.append(d) f.append(d+1) f.sort() best_t=f.index(d)+1+f.index(d)//k*5 wor_t=f.index(d+1)+(f.index(d+1)-1)//k*5-1 print(best_t,wor_t) ```
0
11
A
Increasing Sequence
PROGRAMMING
900
[ "constructive algorithms", "implementation", "math" ]
A. Increasing Sequence
1
64
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least...
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
Output the minimal number of moves needed to make the sequence increasing.
[ "4 2\n1 3 3 2\n" ]
[ "3\n" ]
none
0
[ { "input": "4 2\n1 3 3 2", "output": "3" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 1\n2 5", "output": "0" }, { "input": "2 1\n1 2", "output": "0" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 7\n10 20", "output": "0" }, ...
1,574,446,140
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
16
1,000
1,843,200
n,d=map(int,input().split()) a = [int(x) for x in input().split()] c=0 for i in range(0,n-1): if(a[i]>=a[i+1]): while(a[i]>=a[i+1]): a[i+1]+=d c+=1 print(c)
Title: Increasing Sequence Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*...
```python n,d=map(int,input().split()) a = [int(x) for x in input().split()] c=0 for i in range(0,n-1): if(a[i]>=a[i+1]): while(a[i]>=a[i+1]): a[i+1]+=d c+=1 print(c) ```
0
959
A
Mahmoud and Ehab and the even-odd game
PROGRAMMING
800
[ "games", "math" ]
null
null
Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that: - 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab'...
The only line contains an integer *n* (1<=≤<=*n*<=≤<=109), the number at the beginning of the game.
Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise.
[ "1\n", "2\n" ]
[ "Ehab", "Mahmoud" ]
In the first sample, Mahmoud can't choose any integer *a* initially because there is no positive even integer less than or equal to 1 so Ehab wins. In the second sample, Mahmoud has to choose *a* = 2 and subtract it from *n*. It's Ehab's turn and *n* = 0. There is no positive odd integer less than or equal to 0 so Mah...
500
[ { "input": "1", "output": "Ehab" }, { "input": "2", "output": "Mahmoud" }, { "input": "10000", "output": "Mahmoud" }, { "input": "33333", "output": "Ehab" }, { "input": "5", "output": "Ehab" }, { "input": "1000000000", "output": "Mahmoud" }, { ...
1,608,695,131
2,147,483,647
PyPy 3
OK
TESTS
20
155
0
import sys n = int(sys.stdin.readline().split()[0]) if n % 2 == 0: print("Mahmoud") else: print("Ehab")
Title: Mahmoud and Ehab and the even-odd game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a*...
```python import sys n = int(sys.stdin.readline().split()[0]) if n % 2 == 0: print("Mahmoud") else: print("Ehab") ```
3
869
B
The Eternal Immortality
PROGRAMMING
1,100
[ "math" ]
null
null
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this. The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! deno...
The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018).
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
[ "2 4\n", "0 10\n", "107 109\n" ]
[ "2\n", "0\n", "2\n" ]
In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2; In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso...
1,000
[ { "input": "2 4", "output": "2" }, { "input": "0 10", "output": "0" }, { "input": "107 109", "output": "2" }, { "input": "10 13", "output": "6" }, { "input": "998244355 998244359", "output": "4" }, { "input": "999999999000000000 1000000000000000000", ...
1,508,334,781
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
5,529,600
a = int(input("")) b = int(input("")) result = 1 diff = b - a for counter in range (diff+1, b+1): result= result * counter result = str(result) length = len(result) lastDigit = result[length-1] print(lastDigit)
Title: The Eternal Immortality Time Limit: None seconds Memory Limit: None megabytes Problem Description: Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like...
```python a = int(input("")) b = int(input("")) result = 1 diff = b - a for counter in range (diff+1, b+1): result= result * counter result = str(result) length = len(result) lastDigit = result[length-1] print(lastDigit) ```
-1
265
A
Colorful Stones (Simplified Edition)
PROGRAMMING
800
[ "implementation" ]
null
null
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Ini...
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Print the final 1-based position of Liss in a single line.
[ "RGB\nRRR\n", "RRRBGBRBBB\nBBBRR\n", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n" ]
[ "2\n", "3\n", "15\n" ]
none
500
[ { "input": "RGB\nRRR", "output": "2" }, { "input": "RRRBGBRBBB\nBBBRR", "output": "3" }, { "input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB", "output": "15" }, { "input": "G\nRRBBRBRRBR", "output": "1" }, ...
1,682,930,685
2,147,483,647
Python 3
OK
TESTS
19
92
0
class Solution: def __init__(self): pass def solve(self): s = input() t = input() i = 0; j = 0 while j < len(t): if t[j] == s[i]: i += 1 j += 1 print(i + 1) if __name__ == "__main__": sol = Solution() sol.solve()
Title: Colorful Stones (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st...
```python class Solution: def __init__(self): pass def solve(self): s = input() t = input() i = 0; j = 0 while j < len(t): if t[j] == s[i]: i += 1 j += 1 print(i + 1) if __name__ == "__main__": sol = Solution() sol.solve() ```
3
337
A
Puzzles
PROGRAMMING
900
[ "greedy" ]
null
null
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od...
The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop.
Print a single integer — the least possible difference the teacher can obtain.
[ "4 6\n10 12 10 7 5 22\n" ]
[ "5\n" ]
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t...
500
[ { "input": "4 6\n10 12 10 7 5 22", "output": "5" }, { "input": "2 2\n4 4", "output": "0" }, { "input": "2 10\n4 5 6 7 8 9 10 11 12 12", "output": "0" }, { "input": "4 5\n818 136 713 59 946", "output": "759" }, { "input": "3 20\n446 852 783 313 549 965 40 88 86 617...
1,670,511,791
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
92
0
n,m = map(int,input().strip().split()) l = list(map(int,input().strip().split())) l.sort() ans = 100000 for i in range(1,m-n): ans = min(ans,l[i+n-1] - l[i]) print(ans)
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a...
```python n,m = map(int,input().strip().split()) l = list(map(int,input().strip().split())) l.sort() ans = 100000 for i in range(1,m-n): ans = min(ans,l[i+n-1] - l[i]) print(ans) ```
0
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di...
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", ...
1,675,457,394
2,147,483,647
Python 3
OK
TESTS
34
92
4,505,600
T = int(input()) teams = {} for t in range(T): team = input() if team not in teams: teams[team] = 1 else: teams[team] += 1 max_score = 0 winner_team = '' for team in teams: if teams[team] > max_score: max_score = teams[team] winner_team = team print(winner_...
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process...
```python T = int(input()) teams = {} for t in range(T): team = input() if team not in teams: teams[team] = 1 else: teams[team] += 1 max_score = 0 winner_team = '' for team in teams: if teams[team] > max_score: max_score = teams[team] winner_team = team pri...
3.968608
65
A
Harry Potter and Three Spells
PROGRAMMING
1,800
[ "implementation", "math" ]
A. Harry Potter and Three Spells
2
256
A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert *a* grams of sand into *b* grams of lead, the second one allows you to convert *c* grams of lead into *d* grams o...
The first line contains 6 integers *a*, *b*, *c*, *d*, *e*, *f* (0<=≤<=*a*,<=*b*,<=*c*,<=*d*,<=*e*,<=*f*<=≤<=1000).
Print "Ron", if it is possible to get an infinitely large amount of gold having a certain finite amount of sand (and not having any gold and lead at all), i.e., Ron is right. Otherwise, print "Hermione".
[ "100 200 250 150 200 250\n", "100 50 50 200 200 100\n", "100 10 200 20 300 30\n", "0 0 0 0 0 0\n", "1 1 0 1 1 1\n", "1 0 1 2 1 2\n", "100 1 100 1 0 1\n" ]
[ "Ron\n", "Hermione\n", "Hermione\n", "Hermione\n", "Ron\n", "Hermione\n", "Ron\n" ]
Consider the first sample. Let's start with the 500 grams of sand. Apply the first spell 5 times and turn the sand into 1000 grams of lead. Then apply the second spell 4 times to get 600 grams of gold. Let’s take 400 grams from the resulting amount of gold turn them back into sand. We get 500 grams of sand and 200 gram...
500
[ { "input": "100 200 250 150 200 250", "output": "Ron" }, { "input": "100 50 50 200 200 100", "output": "Hermione" }, { "input": "100 10 200 20 300 30", "output": "Hermione" }, { "input": "0 0 0 0 0 0", "output": "Hermione" }, { "input": "1 1 0 1 1 1", "output"...
1,685,952,247
2,147,483,647
Python 3
OK
TESTS
124
92
0
# LUOGU_RID: 112089745 a, b, c, d, e, f = map(int, input().split()); if a * c * e < b * d * f or a == 0 and b * d > 0 or c == 0 and d > 0: print("Ron"); else: print("Hermione");
Title: Harry Potter and Three Spells Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert *a...
```python # LUOGU_RID: 112089745 a, b, c, d, e, f = map(int, input().split()); if a * c * e < b * d * f or a == 0 and b * d > 0 or c == 0 and d > 0: print("Ron"); else: print("Hermione"); ```
3.977
263
A
Beautiful Matrix
PROGRAMMING
800
[ "implementation" ]
null
null
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1....
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
[ "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 0 0 0 0...
1,697,640,122
2,147,483,647
Python 3
OK
TESTS
25
92
0
listt=[] for m in range(5): ans=list(map(int,input().split(" "))) listt.append(ans) moves=0 row=2 col=2 for i in range(0,5): for x in range(0,5): if listt[i][x]==1: co=x ro=i break while ro != row or co != col: if ro != row: if ro<row: ...
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 listt=[] for m in range(5): ans=list(map(int,input().split(" "))) listt.append(ans) moves=0 row=2 col=2 for i in range(0,5): for x in range(0,5): if listt[i][x]==1: co=x ro=i break while ro != row or co != col: if ro != row: if...
3
75
A
Life Without Zeros
PROGRAMMING
1,000
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*...
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }...
1,662,402,456
2,147,483,647
Python 3
OK
TESTS
43
92
0
a = int(input()) b = int(input()) a_bez_0 = a b_bez_0 = b s_bez_0 = a + b # summa bez 0 summa = a + b i = -1 i2 = -1 i3 = -1 lastA = 0 lastB = 0 lastS = 0 while a > 0: lastA = a % 10 # posl cifra if lastA == 0: a_bez_0 = int(str(a_bez_0)[:i] + str(a_bez_0)[i + 1:]) # virezaem 0 cherez ...
Title: Life Without Zeros Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu...
```python a = int(input()) b = int(input()) a_bez_0 = a b_bez_0 = b s_bez_0 = a + b # summa bez 0 summa = a + b i = -1 i2 = -1 i3 = -1 lastA = 0 lastB = 0 lastS = 0 while a > 0: lastA = a % 10 # posl cifra if lastA == 0: a_bez_0 = int(str(a_bez_0)[:i] + str(a_bez_0)[i + 1:]) # virezaem...
3.977
803
B
Distances to Zero
PROGRAMMING
1,200
[ "constructive algorithms" ]
null
null
You are given the array of integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.
The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — length of the array *a*. The second line contains integer elements of the array separated by single spaces (<=-<=109<=≤<=*a**i*<=≤<=109).
Print the sequence *d*0,<=*d*1,<=...,<=*d**n*<=-<=1, where *d**i* is the difference of indices between *i* and nearest *j* such that *a**j*<==<=0. It is possible that *i*<==<=*j*.
[ "9\n2 1 0 3 0 0 3 2 4\n", "5\n0 1 2 3 4\n", "7\n5 6 0 1 -2 3 4\n" ]
[ "2 1 0 1 0 0 1 2 3 ", "0 1 2 3 4 ", "2 1 0 1 2 3 4 " ]
none
0
[ { "input": "9\n2 1 0 3 0 0 3 2 4", "output": "2 1 0 1 0 0 1 2 3 " }, { "input": "5\n0 1 2 3 4", "output": "0 1 2 3 4 " }, { "input": "7\n5 6 0 1 -2 3 4", "output": "2 1 0 1 2 3 4 " }, { "input": "1\n0", "output": "0 " }, { "input": "2\n0 0", "output": "0 0 " ...
1,639,507,467
2,147,483,647
PyPy 3-64
OK
TESTS
164
483
21,401,600
import sys, math input=sys.stdin.readline INF=int(1e9)+7 def solve(): n=int(input()) data=list(map(int, input().split())) result=[INF]*n for i in range(n): if data[i]==0: result[i]=0 idx=i-1 while idx>=0 and data[idx]!=0: result[i...
Title: Distances to Zero Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given the array of integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the give...
```python import sys, math input=sys.stdin.readline INF=int(1e9)+7 def solve(): n=int(input()) data=list(map(int, input().split())) result=[INF]*n for i in range(n): if data[i]==0: result[i]=0 idx=i-1 while idx>=0 and data[idx]!=0: ...
3
765
A
Neverending competitions
PROGRAMMING
900
[ "implementation", "math" ]
null
null
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team ...
In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX-&gt;YYY", where "XXX"...
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
[ "4\nSVO\nSVO-&gt;CDG\nLHR-&gt;SVO\nSVO-&gt;LHR\nCDG-&gt;SVO\n", "3\nSVO\nSVO-&gt;HKT\nHKT-&gt;SVO\nSVO-&gt;RAP\n" ]
[ "home\n", "contest\n" ]
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
500
[ { "input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "output": "home" }, { "input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP", "output": "contest" }, { "input": "1\nESJ\nESJ->TSJ", "output": "contest" }, { "input": "2\nXMR\nFAJ->XMR\nXMR->FAJ", "output": "home" }, ...
1,594,606,980
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
93
6,656,000
n = int(input()) home = input() for num in range(n): x = input() if num == n-1: if x[:3] == home: print('contest') else: print('home')
Title: Neverending competitions Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from thei...
```python n = int(input()) home = input() for num in range(n): x = input() if num == n-1: if x[:3] == home: print('contest') else: print('home') ```
0