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
986
D
Perfect Encoding
PROGRAMMING
3,100
[ "fft", "math" ]
null
null
You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID. To create the system, you choose the parameters of the system — integers $m \ge 1$ and $b_{1}, b_{2}, \ldots, b_{m}$. With these parameters an ID o...
In the only line of input there is one positive integer $n$. The length of the decimal representation of $n$ is no greater than $1.5 \cdot 10^{6}$. The integer does not contain leading zeros.
Print one number — minimal value of $\sum_{i=1}^{m} b_{i}$.
[ "36\n", "37\n", "12345678901234567890123456789\n" ]
[ "10\n", "11\n", "177\n" ]
none
2,500
[ { "input": "36", "output": "10" }, { "input": "37", "output": "11" }, { "input": "12345678901234567890123456789", "output": "177" }, { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "3", "output": "3" }, { "input...
1,527,614,163
6,063
Python 3
WRONG_ANSWER
PRETESTS
0
108
819,200
import sys import math import random import time import decimal line = lambda: list(int(x) for x in input().split()) MOD = int(1e9 + 7) def solve(): a = int(input()) b = [] b.append(a) b.append((a + 1) / 2) b.append((a + 3) / 4) c = 1 res = 10**9 for i in range(0, 4**6): if c >...
Title: Perfect Encoding Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID. To create the system, you choose the paramete...
```python import sys import math import random import time import decimal line = lambda: list(int(x) for x in input().split()) MOD = int(1e9 + 7) def solve(): a = int(input()) b = [] b.append(a) b.append((a + 1) / 2) b.append((a + 3) / 4) c = 1 res = 10**9 for i in range(0, 4**6): ...
0
985
B
Switches and Lamps
PROGRAMMING
1,200
[ "implementation" ]
null
null
You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th switch turns on the *j*-th lamp and *a**i*,<=*j*<==<=0 if the *i*-th switch is not connected to the *j*...
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2000) — the number of the switches and the number of the lamps. The following *n* lines contain *m* characters each. The character *a**i*,<=*j* is equal to '1' if the *i*-th switch turns on the *j*-th lamp and '0' otherwise. It is guar...
Print "YES" if there is a switch that if you will ignore it and press all the other *n*<=-<=1 switches then all *m* lamps will be turned on. Print "NO" if there is no such switch.
[ "4 5\n10101\n01000\n00111\n10000\n", "4 5\n10100\n01000\n00110\n00101\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "4 5\n10101\n01000\n00111\n10000", "output": "YES" }, { "input": "4 5\n10100\n01000\n00110\n00101", "output": "NO" }, { "input": "1 5\n11111", "output": "NO" }, { "input": "10 1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n1", "output": "YES" }, { "input": "1 1\n1", ...
1,526,919,603
5,703
Python 3
WRONG_ANSWER
TESTS
6
124
921,600
import random n, m = [int(i) for i in input().strip().split()] for i in range(n): a = input() if random.randint(0, m)%2==0: print("YES") else: print("NO") ##n = int(input()) ##arr = [int(i) for i in input().strip().split()] ##arr.sort() ##brr = [i for i in arr] ##ans = 0 ##for i in range(n, ...
Title: Switches and Lamps Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th...
```python import random n, m = [int(i) for i in input().strip().split()] for i in range(n): a = input() if random.randint(0, m)%2==0: print("YES") else: print("NO") ##n = int(input()) ##arr = [int(i) for i in input().strip().split()] ##arr.sort() ##brr = [i for i in arr] ##ans = 0 ##for i in...
0
1,009
A
Game Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$. Games in the shop are ordered from left to right, Maxim tries to buy ...
The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game. The third line of the inp...
Print a single integer — the number of games Maxim will buy.
[ "5 4\n2 4 5 2 4\n5 3 4 6\n", "5 2\n20 40 50 20 40\n19 20\n", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n" ]
[ "3\n", "0\n", "4\n" ]
The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti...
0
[ { "input": "5 4\n2 4 5 2 4\n5 3 4 6", "output": "3" }, { "input": "5 2\n20 40 50 20 40\n19 20", "output": "0" }, { "input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "output": "4" }, { "input": "5 1\n1 1 1 1 1\n5", "output": "1" }, { "input": "5 1\n10 1 1 1 1\n...
1,531,662,583
2,147,483,647
Python 3
OK
TESTS
19
109
0
a=[int(q) for q in input().strip().split()] b=[int(q) for q in input().strip().split()] c=[int(q) for q in input().strip().split()] ct=0 while len(b)>0 and len(c)>0: if b[0]<=c[0]: c.remove(c[0]) ct+=1 b.remove(b[0]) print(ct)
Title: Game Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the ...
```python a=[int(q) for q in input().strip().split()] b=[int(q) for q in input().strip().split()] c=[int(q) for q in input().strip().split()] ct=0 while len(b)>0 and len(c)>0: if b[0]<=c[0]: c.remove(c[0]) ct+=1 b.remove(b[0]) print(ct) ```
3
877
B
Nikita and string
PROGRAMMING
1,500
[ "brute force", "dp" ]
null
null
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b".
Print a single integer — the maximum possible size of beautiful string Nikita can get.
[ "abba\n", "bab\n" ]
[ "4", "2" ]
It the first sample the string is already beautiful. In the second sample he needs to delete one of "b" to make it beautiful.
1,000
[ { "input": "abba", "output": "4" }, { "input": "bab", "output": "2" }, { "input": "bbabbbaabbbb", "output": "9" }, { "input": "bbabbbbbaaba", "output": "10" }, { "input": "bbabbbababaa", "output": "9" }, { "input": "aabbaababbab", "output": "8" }...
1,587,460,258
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
307,200
a=input() n=len(a) b=0 c=0 d=[] e=[] for i in range(len(a)): if a[i]=="a": b=b+1 elif a[i]=="b": c=c+1 d.append(b) e.append(c) f=[] for i in range(n): for j in range(i,n): f.append(d[i]+e[j]-e[i]+d[n-1]-d[j]) print(max(f))
Title: Nikita and string Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st ...
```python a=input() n=len(a) b=0 c=0 d=[] e=[] for i in range(len(a)): if a[i]=="a": b=b+1 elif a[i]=="b": c=c+1 d.append(b) e.append(c) f=[] for i in range(n): for j in range(i,n): f.append(d[i]+e[j]-e[i]+d[n-1]-d[j]) print(max(f)) ```
0
0
none
none
none
0
[ "none" ]
null
null
Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below. So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. ...
The first line contains the integer *n* (2<=≤<=*n*<=≤<=100<=000) — the maximum number of sections which can be highlighted on the display.
Print the maximum integer which can be shown on the display of Stepan's newest device.
[ "2\n", "3\n" ]
[ "1\n", "7\n" ]
none
0
[ { "input": "2", "output": "1" }, { "input": "3", "output": "7" }, { "input": "4", "output": "11" }, { "input": "5", "output": "71" }, { "input": "6", "output": "111" }, { "input": "85651", "output": "711111111111111111111111111111111111111111111111...
1,491,408,616
2,116
Python 3
WRONG_ANSWER
TESTS
0
31
4,915,200
def constructnumber(arr): string = "" while arr[9]: string += "9" arr[9] -= 1 while arr[8]: string += "8" arr[8] -= 1 while arr[7]: string += "7" arr[7] -= 1 while arr[6]: string += "6" arr[6] -= 1 while arr[5]: string += "5" arr[5] -= 1 while arr[4]: string += "4" arr[4] -= 1 while a...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below. So, for example, to show the digit 3 on the disp...
```python def constructnumber(arr): string = "" while arr[9]: string += "9" arr[9] -= 1 while arr[8]: string += "8" arr[8] -= 1 while arr[7]: string += "7" arr[7] -= 1 while arr[6]: string += "6" arr[6] -= 1 while arr[5]: string += "5" arr[5] -= 1 while arr[4]: string += "4" arr[4] -= 1...
0
898
A
Rounding
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which int...
The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has.
Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
[ "5\n", "113\n", "1000000000\n", "5432359\n" ]
[ "0\n", "110\n", "1000000000\n", "5432360\n" ]
In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
500
[ { "input": "5", "output": "0" }, { "input": "113", "output": "110" }, { "input": "1000000000", "output": "1000000000" }, { "input": "5432359", "output": "5432360" }, { "input": "999999994", "output": "999999990" }, { "input": "10", "output": "10" ...
1,700,516,745
2,147,483,647
Python 3
OK
TESTS
64
46
0
n = int(input()) r = (n%10) if r <= 5: print (n-r) else: print (n+(10-r))
Title: Rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5...
```python n = int(input()) r = (n%10) if r <= 5: print (n-r) else: print (n+(10-r)) ```
3
103
A
Testing Pants for Sadness
PROGRAMMING
1,100
[ "greedy", "implementation", "math" ]
A. Testing Pants for Sadness
2
256
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 t...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*.
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "2\n1 1\n", "2\n2 2\n", "1\n10\n" ]
[ "2", "5", "10" ]
Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the ...
500
[ { "input": "2\n1 1", "output": "2" }, { "input": "2\n2 2", "output": "5" }, { "input": "1\n10", "output": "10" }, { "input": "3\n2 4 1", "output": "10" }, { "input": "4\n5 5 3 1", "output": "22" }, { "input": "2\n1000000000 1000000000", "output": "...
1,592,732,223
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
248
0
a = int(input()) t = list(map(int,input().split())) s = sum(t) if t.count(1)==a: print(s) else: print(s+(a-1))
Title: Testing Pants for Sadness Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of *n* q...
```python a = int(input()) t = list(map(int,input().split())) s = sum(t) if t.count(1)==a: print(s) else: print(s+(a-1)) ```
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,586,119,719
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
108
0
s = input() if len(s) <= 100: my_array = min([s.count("i") // 1, (s.count("n") // 3) + 1, s.count("e") // 3, s.count("t") // 1]) print(my_array)
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 s = input() if len(s) <= 100: my_array = min([s.count("i") // 1, (s.count("n") // 3) + 1, s.count("e") // 3, s.count("t") // 1]) print(my_array) ```
0
300
A
Array
PROGRAMMING
1,100
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The produ...
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second...
[ "3\n-1 2 0\n", "4\n-1 -2 -3 0\n" ]
[ "1 -1\n1 2\n1 0\n", "1 -1\n2 -3 -2\n1 0\n" ]
none
500
[ { "input": "3\n-1 2 0", "output": "1 -1\n1 2\n1 0" }, { "input": "4\n-1 -2 -3 0", "output": "1 -1\n2 -3 -2\n1 0" }, { "input": "5\n-1 -2 1 2 0", "output": "1 -1\n2 1 2\n2 0 -2" }, { "input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -1...
1,665,778,209
2,147,483,647
PyPy 3
OK
TESTS
20
186
0
n=int(input()) a=list(map(int,input().split())) aa=[] bb=[] cc=[] for i in a: if i<0: aa.append(i) elif i>0: bb.append(i) else: cc.append(i) l=[] g=[] z=[] l.append(aa[0]) minus=0 if len(bb)==0: if (len(aa)-1)%2==0: g=aa[1:] minus=len(g...
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. T...
```python n=int(input()) a=list(map(int,input().split())) aa=[] bb=[] cc=[] for i in a: if i<0: aa.append(i) elif i>0: bb.append(i) else: cc.append(i) l=[] g=[] z=[] l.append(aa[0]) minus=0 if len(bb)==0: if (len(aa)-1)%2==0: g=aa[1:] m...
3
235
A
LCM Challenge
PROGRAMMING
1,600
[ "number theory" ]
null
null
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it. But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find ...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement.
Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*.
[ "9\n", "7\n" ]
[ "504\n", "210\n" ]
The least common multiple of some positive integers is the least positive integer which is multiple for each of them. The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended. For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is ...
500
[ { "input": "9", "output": "504" }, { "input": "7", "output": "210" }, { "input": "1", "output": "1" }, { "input": "5", "output": "60" }, { "input": "6", "output": "60" }, { "input": "33", "output": "32736" }, { "input": "21", "output": ...
1,656,330,584
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
82
92
4,710,400
import sys import math input = sys.stdin.readline from collections import defaultdict n = int(input()) if n <= 3: print(n) else : if n%2 == 1 : print(n*(n-1)*(n-2)) elif n%3 == 0: print((n-1)*(n-2)*(n-3)) else: print(n*(n-1)*(n-3))
Title: LCM Challenge Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it. But I also don't want to use many numbers, so I'll choose three positive...
```python import sys import math input = sys.stdin.readline from collections import defaultdict n = int(input()) if n <= 3: print(n) else : if n%2 == 1 : print(n*(n-1)*(n-2)) elif n%3 == 0: print((n-1)*(n-2)*(n-3)) else: print(n*(n-1)*(n-3)) ```
0
141
A
Amusing Joke
PROGRAMMING
800
[ "implementation", "sortings", "strings" ]
null
null
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O...
The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do...
Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.
[ "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n", "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n", "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n" ]
[ "YES\n", "NO\n", "NO\n" ]
In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left. In the second sample letter "P" is missing from the pile and there's an extra letter "L". In the third sample there's an extra letter "L".
500
[ { "input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS", "output": "YES" }, { "input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI", "output": "NO" }, { "input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER", "output": "NO" }, { "input": "B\nA\nAB", "output": ...
1,688,806,194
2,147,483,647
Python 3
OK
TESTS
54
92
0
h=input() u=input() i=input() funny=h+u slojna=sorted(funny) legko=sorted(i) if slojna==legko: print("YES") else: print("NO") # Sat Jul 08 2023 11:49:53 GMT+0300 (Moscow Standard Time)
Title: Amusing Joke Time Limit: None seconds Memory Limit: None megabytes Problem Description: So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam...
```python h=input() u=input() i=input() funny=h+u slojna=sorted(funny) legko=sorted(i) if slojna==legko: print("YES") else: print("NO") # Sat Jul 08 2023 11:49:53 GMT+0300 (Moscow Standard Time) ```
3
608
A
Saitama Destroys Hotel
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor...
The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively. The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the tim...
Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0.
[ "3 7\n2 1\n3 8\n5 2\n", "5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n" ]
[ "11\n", "79\n" ]
In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done: 1. Move to floor 5: takes 2 seconds. 2. Pick up passenger 3. 3. Move to floor 3: takes 2 seconds. 4. Wait for passenger 2 to arrive: takes 4 seconds. 5. Pick up passenger 2. 6. Go to floor 2: take...
500
[ { "input": "3 7\n2 1\n3 8\n5 2", "output": "11" }, { "input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64", "output": "79" }, { "input": "1 1000\n1000 1000", "output": "2000" }, { "input": "1 1\n1 1", "output": "2" }, { "input": "1 1000\n1 1", "output": "1000" }, ...
1,681,539,065
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
N=input().split() n=int(N[0]) s=int(N[1]) t=0 p=[0]*(s+1) for i in range(0,n): P=input().split() p[int(P[0])]+=int(P[1]) for i in range(s-1,0,-1): t+=1 if t<p[i]: t=p[i] print(t+1)
Title: Saitama Destroys Hotel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only mo...
```python N=input().split() n=int(N[0]) s=int(N[1]) t=0 p=[0]*(s+1) for i in range(0,n): P=input().split() p[int(P[0])]+=int(P[1]) for i in range(s-1,0,-1): t+=1 if t<p[i]: t=p[i] print(t+1) ```
0
224
B
Array
PROGRAMMING
1,500
[ "bitmasks", "implementation", "two pointers" ]
null
null
You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers. Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤...
The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105).
Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them.
[ "4 2\n1 2 2 3\n", "8 3\n1 1 2 2 3 3 4 5\n", "7 4\n4 7 7 4 7 4 7\n" ]
[ "1 2\n", "2 5\n", "-1 -1\n" ]
In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers. In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments. In the third sam...
1,000
[ { "input": "4 2\n1 2 2 3", "output": "1 2" }, { "input": "8 3\n1 1 2 2 3 3 4 5", "output": "2 5" }, { "input": "7 4\n4 7 7 4 7 4 7", "output": "-1 -1" }, { "input": "5 1\n1 7 2 3 2", "output": "1 1" }, { "input": "1 2\n666", "output": "-1 -1" }, { "inp...
1,634,350,106
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
154
0
# 8 3 # 1 1 2 2 3 3 4 5 N, K = list(map(int, input().split())) a = list(map(int, input().split())) # a = [1, 6, 6, 6, 4, 2, 3, 3, 4, 5] # N, K = len(a), 3 l = 0 r = 0 unique_set = set() while len(unique_set) < K and r < N: # O(1) * n unique_set.add(a[r]) r += 1 unique_set = set() l = r wh...
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<...
```python # 8 3 # 1 1 2 2 3 3 4 5 N, K = list(map(int, input().split())) a = list(map(int, input().split())) # a = [1, 6, 6, 6, 4, 2, 3, 3, 4, 5] # N, K = len(a), 3 l = 0 r = 0 unique_set = set() while len(unique_set) < K and r < N: # O(1) * n unique_set.add(a[r]) r += 1 unique_set = set() ...
0
397
A
On Segment's Own Points
PROGRAMMING
0
[ "implementation" ]
null
null
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. The dorm has exactly one straight dryer — a 100 ce...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). The (*i*<=+<=1)-th line contains integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=100) — the endpoints of the corresponding segment for the *i*-th student.
On a single line print a single number *k*, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments.
[ "3\n0 5\n2 8\n1 6\n", "3\n0 10\n1 5\n7 15\n" ]
[ "1\n", "3\n" ]
Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments. In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and...
500
[ { "input": "3\n0 5\n2 8\n1 6", "output": "1" }, { "input": "3\n0 10\n1 5\n7 15", "output": "3" }, { "input": "1\n0 100", "output": "100" }, { "input": "2\n1 9\n1 9", "output": "0" }, { "input": "2\n1 9\n5 10", "output": "4" }, { "input": "2\n1 9\n3 5",...
1,583,057,505
2,147,483,647
Python 3
OK
TESTS
37
109
512,000
n = int(input()) segments = [] for _ in range(n): segments.append(list(map(int, input().split()))) l = segments[0][0] r = segments[0][1] list_of_tuples = [] for i in range(l,r): list_of_tuples.append((i,i+1)) i=1 while i<n: for j in range(segments[i][0],segments[i][1]): if (j,j+1) in lis...
Title: On Segment's Own Points Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some...
```python n = int(input()) segments = [] for _ in range(n): segments.append(list(map(int, input().split()))) l = segments[0][0] r = segments[0][1] list_of_tuples = [] for i in range(l,r): list_of_tuples.append((i,i+1)) i=1 while i<n: for j in range(segments[i][0],segments[i][1]): if (j,j...
3
370
A
Rook, Bishop and King
PROGRAMMING
1,100
[ "graphs", "math", "shortest paths" ]
null
null
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=8 table. A field is represented by a pair of integers (*r*,<=*c*) — the number of the row and the number of...
The input contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*c*1,<=*r*2,<=*c*2<=≤<=8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numb...
Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2). If a piece cannot make such a move, print a 0 instead of the corresponding number.
[ "4 3 1 6\n", "5 5 5 6\n" ]
[ "2 1 3\n", "1 0 1\n" ]
none
500
[ { "input": "4 3 1 6", "output": "2 1 3" }, { "input": "5 5 5 6", "output": "1 0 1" }, { "input": "1 1 8 8", "output": "2 1 7" }, { "input": "1 1 8 1", "output": "1 0 7" }, { "input": "1 1 1 8", "output": "1 0 7" }, { "input": "8 1 1 1", "output": "...
1,643,793,819
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
32
46
0
# inp = lambda :list(map(int, input().split())) c = list(map(int, input().split())) def tower(r1, c1, r2, c2): if r1 - r2 == 0 or c1 - c2 == 0: return 1 return 2 def eleph(r1, c1, r2, c2): if abs(r1-c1)%2 != abs(r2-c2)%2: return 0 if abs(r1-c1) == abs(r2-c2) or r1+c1 == r2 + c2: ...
Title: Rook, Bishop and King Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=...
```python # inp = lambda :list(map(int, input().split())) c = list(map(int, input().split())) def tower(r1, c1, r2, c2): if r1 - r2 == 0 or c1 - c2 == 0: return 1 return 2 def eleph(r1, c1, r2, c2): if abs(r1-c1)%2 != abs(r2-c2)%2: return 0 if abs(r1-c1) == abs(r2-c2) or r1+c1 == r2 ...
0
192
A
Funky Numbers
PROGRAMMING
1,300
[ "binary search", "brute force", "implementation" ]
null
null
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and c...
The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109).
Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
[ "256\n", "512\n" ]
[ "YES\n", "NO\n" ]
In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
500
[ { "input": "256", "output": "YES" }, { "input": "512", "output": "NO" }, { "input": "80", "output": "NO" }, { "input": "828", "output": "YES" }, { "input": "6035", "output": "NO" }, { "input": "39210", "output": "YES" }, { "input": "79712",...
1,626,525,902
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
124
6,963,200
import math funk = [] n = int(input()) for i in range(int(math.sqrt(n))+1): funk.append(i*(i+1)// 2) i = 0 j = len(funk) - 1 while j >= i: if funk[i] + funk[j] > n: j -= 1 elif funk[i] + funk[j] < n: i += 1 else: print("YES") exit() print("NO")
Title: Funky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent...
```python import math funk = [] n = int(input()) for i in range(int(math.sqrt(n))+1): funk.append(i*(i+1)// 2) i = 0 j = len(funk) - 1 while j >= i: if funk[i] + funk[j] > n: j -= 1 elif funk[i] + funk[j] < n: i += 1 else: print("YES") exit() print("NO") ```
0
911
C
Three Garlands
PROGRAMMING
1,400
[ "brute force", "constructive algorithms" ]
null
null
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on. When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th s...
The first line contains three integers *k*1, *k*2 and *k*3 (1<=≤<=*k**i*<=≤<=1500) — time intervals of the garlands.
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES. Otherwise, print NO.
[ "2 2 3\n", "4 2 3\n" ]
[ "YES\n", "NO\n" ]
In the first example Mishka can choose *x*<sub class="lower-index">1</sub> = 1, *x*<sub class="lower-index">2</sub> = 2, *x*<sub class="lower-index">3</sub> = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't...
0
[ { "input": "2 2 3", "output": "YES" }, { "input": "4 2 3", "output": "NO" }, { "input": "1499 1498 1500", "output": "NO" }, { "input": "1500 1500 1500", "output": "NO" }, { "input": "100 4 1", "output": "YES" }, { "input": "4 2 4", "output": "YES" ...
1,590,648,209
2,609
PyPy 3
OK
TESTS
67
1,933
8,089,600
import sys #import math #import random #sys.setrecursionlimit(100000000) input = sys.stdin.readline ############ ---- USER DEFINED INPUT FUNCTIONS ---- ############ def inp(): return(int(input())) def inara(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:l...
Title: Three Garlands Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on. When a garland is switched on, it periodically changes its st...
```python import sys #import math #import random #sys.setrecursionlimit(100000000) input = sys.stdin.readline ############ ---- USER DEFINED INPUT FUNCTIONS ---- ############ def inp(): return(int(input())) def inara(): return(list(map(int,input().split()))) def insr(): s = input() return...
3
792
A
New Bus Route
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct. It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport d...
The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct.
Print two integer numbers — the minimal distance and the quantity of pairs with this distance.
[ "4\n6 -3 0 4\n", "3\n-2 0 2\n" ]
[ "2 1\n", "2 2\n" ]
In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance.
0
[ { "input": "4\n6 -3 0 4", "output": "2 1" }, { "input": "3\n-2 0 2", "output": "2 2" }, { "input": "2\n1 2", "output": "1 1" }, { "input": "2\n1000000000 -1000000000", "output": "2000000000 1" }, { "input": "5\n-979619606 -979619602 -979619604 -979619605 -97961960...
1,637,303,192
92
PyPy 3-64
OK
TESTS
45
249
22,323,200
import sys input = sys.stdin.readline n = int(input()) l = sorted([int(i) for i in input().split()]) res = 10**18 ans = 0 for i in range(n-1): t = l[i+1]-l[i] if t == res: ans += 1 elif t < res: res = t ans = 1 print(res, ans)
Title: New Bus Route Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct. It is possible to get from on...
```python import sys input = sys.stdin.readline n = int(input()) l = sorted([int(i) for i in input().split()]) res = 10**18 ans = 0 for i in range(n-1): t = l[i+1]-l[i] if t == res: ans += 1 elif t < res: res = t ans = 1 print(res, ans) ```
3
732
A
Buy a Shovel
PROGRAMMING
800
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<...
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e...
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
[ "117 3\n", "237 7\n", "15 2\n" ]
[ "9\n", "1\n", "2\n" ]
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels ...
500
[ { "input": "117 3", "output": "9" }, { "input": "237 7", "output": "1" }, { "input": "15 2", "output": "2" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "1000 3", "output": "1" }, { "input": "1000 1", ...
1,678,334,038
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
2
1,000
1,331,200
k,r=map(int,input().split()) x=1 while (k*x)%10!=r: x+=1 print(x)
Title: Buy a Shovel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his ...
```python k,r=map(int,input().split()) x=1 while (k*x)%10!=r: x+=1 print(x) ```
0
56
A
Bar
PROGRAMMING
1,000
[ "implementation" ]
A. Bar
2
256
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can chec...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input da...
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
[ "5\n18\nVODKA\nCOKE\n19\n17\n" ]
[ "2\n" ]
In the sample test the second and fifth clients should be checked.
500
[ { "input": "5\n18\nVODKA\nCOKE\n19\n17", "output": "2" }, { "input": "2\n2\nGIN", "output": "2" }, { "input": "3\nWHISKEY\n3\nGIN", "output": "3" }, { "input": "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWI...
1,580,374,511
2,147,483,647
Python 3
OK
TESTS
28
218
0
lis = ["ABSINTH","BEER","BRANDY","CHAMPAGNE","GIN","RUM","SAKE","TEQUILA","VODKA","WHISKEY","WINE"] n = int(input()) k = 0 for i in range(n): s = input() if s.isnumeric(): s = int(s) if s < 18: k = k + 1 else: if s in lis: k = k + 1 print(k)
Title: Bar Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya h...
```python lis = ["ABSINTH","BEER","BRANDY","CHAMPAGNE","GIN","RUM","SAKE","TEQUILA","VODKA","WHISKEY","WINE"] n = int(input()) k = 0 for i in range(n): s = input() if s.isnumeric(): s = int(s) if s < 18: k = k + 1 else: if s in lis: k = k + 1 print...
3.9455
4
A
Watermelon
PROGRAMMING
800
[ "brute force", "math" ]
A. Watermelon
1
64
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and ...
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
[ "8\n" ]
[ "YES\n" ]
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
0
[ { "input": "8", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "7", "output": "NO"...
1,691,446,160
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
number = input('what is your input?') numberInt = int(number) minValue=1 maxValue=100 if minValue<=numberInt<= maxValue: if numberInt % 2 == 0: print('YES') else: print('NO') else: print('Number range in 1 to 100')
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin...
```python number = input('what is your input?') numberInt = int(number) minValue=1 maxValue=100 if minValue<=numberInt<= maxValue: if numberInt % 2 == 0: print('YES') else: print('NO') else: print('Number range in 1 to 100') ```
0
382
A
Ksenia and Pan Scales
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium. The scales is in equilibrium ...
The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially ...
If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input. If there are multiple answers, print any of them.
[ "AC|T\nL\n", "|ABC\nXYZ\n", "W|T\nF\n", "ABC|\nD\n" ]
[ "AC|TL\n", "XYZ|ABC\n", "Impossible\n", "Impossible\n" ]
none
500
[ { "input": "AC|T\nL", "output": "AC|TL" }, { "input": "|ABC\nXYZ", "output": "XYZ|ABC" }, { "input": "W|T\nF", "output": "Impossible" }, { "input": "ABC|\nD", "output": "Impossible" }, { "input": "A|BC\nDEF", "output": "ADF|BCE" }, { "input": "|\nABC",...
1,566,667,078
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
109
0
x=list(input()) z=input() h=x.index("|") min1=min(h,len(x)-(h+1)) max1=max(h,len(x)-(h+1)) f=len(x)-1+len(z) if(f%2!=0 or min1+len(z)<max1): print("Impossible") else: if(f/2>max1): if(max1==len(x)-(h+1)): x[-1]+=z[0:int(((f/2)-max1))] else: x[h-1]+=z[0:int(((...
Title: Ksenia and Pan Scales Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all ...
```python x=list(input()) z=input() h=x.index("|") min1=min(h,len(x)-(h+1)) max1=max(h,len(x)-(h+1)) f=len(x)-1+len(z) if(f%2!=0 or min1+len(z)<max1): print("Impossible") else: if(f/2>max1): if(max1==len(x)-(h+1)): x[-1]+=z[0:int(((f/2)-max1))] else: x[h-1]+=...
0
631
B
Print Check
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
null
null
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the pr...
The first line of the input contains three integers *n*, *m* and *k* (1<=<=≤<=<=*n*,<=<=*m*<=<=≤<=5000, *n*·*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=100<=000) — the dimensions of the sheet and the number of operations, respectively. Each of the next *k* lines contains the description of exactly one query: - 1 *r**i* *a**i* ...
Print *n* lines containing *m* integers each — the resulting table after all operations are applied.
[ "3 3 3\n1 1 3\n2 2 1\n1 2 2\n", "5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1\n" ]
[ "3 1 3 \n2 2 2 \n0 1 0 \n", "1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 \n" ]
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
1,000
[ { "input": "3 3 3\n1 1 3\n2 2 1\n1 2 2", "output": "3 1 3 \n2 2 2 \n0 1 0 " }, { "input": "5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1", "output": "1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 " }, { "input": "5 5 4\n1 2 1\n1 4 1\n2 2 1\n2 4 1", "output": "0 1 0 1 0 \n1 1 1 1 1 \n0 1 0 1 0 \n1...
1,457,025,112
2,212
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
10
1,000
1,536,000
mx = [] ops = [] nx=list(map(int,input().split())) n=nx[0] m=nx[1] k=nx[2] for i in range (0,n): mx.append([0]*m) for i in range (0,k): ops.append(list(map(int,input().split()))) if ops[i][0]==1: for j in range (0,m): mx[ops[i][1]-1][j]=ops[i][2] else: for j in ...
Title: Print Check Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built a...
```python mx = [] ops = [] nx=list(map(int,input().split())) n=nx[0] m=nx[1] k=nx[2] for i in range (0,n): mx.append([0]*m) for i in range (0,k): ops.append(list(map(int,input().split()))) if ops[i][0]==1: for j in range (0,m): mx[ops[i][1]-1][j]=ops[i][2] else: ...
0
676
A
Nicholas and Permutation
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize th...
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation. The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position.
Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
[ "5\n4 5 1 3 2\n", "7\n1 6 5 3 4 7 2\n", "6\n6 5 4 3 2 1\n" ]
[ "3\n", "6\n", "5\n" ]
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2. In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2. In the third sample, the distance between the minimum and the maximum elements is already maximum possib...
500
[ { "input": "5\n4 5 1 3 2", "output": "3" }, { "input": "7\n1 6 5 3 4 7 2", "output": "6" }, { "input": "6\n6 5 4 3 2 1", "output": "5" }, { "input": "2\n1 2", "output": "1" }, { "input": "2\n2 1", "output": "1" }, { "input": "3\n2 3 1", "output": "...
1,685,950,052
2,147,483,647
PyPy 3-64
OK
TESTS
159
62
0
n = int(input()) x = [int(x) for x in input().split()] minpos = x.index(min(x)) maxpos = x.index(max(x)) if(minpos>maxpos): d1 = (n-1)-(minpos) d2 = maxpos-0 print((minpos-maxpos)+max(d1,d2)) else: d1 = (n-1)-(maxpos) d2 = minpos-0 print((maxpos-minpos)+max(d1,d2))
Title: Nicholas and Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integ...
```python n = int(input()) x = [int(x) for x in input().split()] minpos = x.index(min(x)) maxpos = x.index(max(x)) if(minpos>maxpos): d1 = (n-1)-(minpos) d2 = maxpos-0 print((minpos-maxpos)+max(d1,d2)) else: d1 = (n-1)-(maxpos) d2 = minpos-0 print((maxpos-minpos)+max(d1,d2)) ```
3
550
B
Preparing Olympiad
PROGRAMMING
1,400
[ "bitmasks", "brute force" ]
null
null
You have *n* problems. You have estimated the difficulty of the *i*-th one as integer *c**i*. Now you want to prepare a problemset for a contest, using some of the problems you've made. A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contes...
The first line contains four integers *n*, *l*, *r*, *x* (1<=≤<=*n*<=≤<=15, 1<=≤<=*l*<=≤<=*r*<=≤<=109, 1<=≤<=*x*<=≤<=106) — the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easies...
Print the number of ways to choose a suitable problemset for the contest.
[ "3 5 6 1\n1 2 3\n", "4 40 50 10\n10 20 30 25\n", "5 25 35 10\n10 10 20 10 20\n" ]
[ "2\n", "2\n", "6\n" ]
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems. In the second example, two sets of problems are suitable — the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30. In the third ...
750
[ { "input": "3 5 6 1\n1 2 3", "output": "2" }, { "input": "4 40 50 10\n10 20 30 25", "output": "2" }, { "input": "5 25 35 10\n10 10 20 10 20", "output": "6" }, { "input": "4 15 60 10\n10 20 30 25", "output": "6" }, { "input": "1 10 20 1\n15", "output": "0" },...
1,692,088,409
2,147,483,647
Python 3
OK
TESTS
30
233
0
n, l, r, x = map(int, input().split()) a = list(map(int, input().split())) ans = 0 #find all subsets using bitmasking and find values and compare with restrictions for i in range(1 << n): mx = -1 mn = 1000000 sum_val = 0 for j in range(n): if i & (1 << j): sum_val += a[j] ...
Title: Preparing Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have *n* problems. You have estimated the difficulty of the *i*-th one as integer *c**i*. Now you want to prepare a problemset for a contest, using some of the problems you've made. A problemset for the contest ...
```python n, l, r, x = map(int, input().split()) a = list(map(int, input().split())) ans = 0 #find all subsets using bitmasking and find values and compare with restrictions for i in range(1 << n): mx = -1 mn = 1000000 sum_val = 0 for j in range(n): if i & (1 << j): sum_val += a[j]...
3
0
none
none
none
0
[ "none" ]
null
null
Limak has a grid that consists of 2 rows and *n* columns. The *j*-th cell in the *i*-th row contains an integer *t**i*,<=*j* which can be positive, negative or zero. A non-empty rectangle of cells is called nice if and only if the sum of numbers in its cells is equal to 0. Limak wants to choose some nice rectangles a...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=300<=000) — the number of columns in the grid. The next two lines contain numbers in the grid. The *i*-th of those two lines contains *n* integers *t**i*,<=1,<=*t**i*,<=2,<=...,<=*t**i*,<=*n* (<=-<=109<=≤<=*t**i*,<=*j*<=≤<=109).
Print one integer, denoting the maximum possible number of cell-disjoint nice rectangles.
[ "6\n70 70 70 70 70 -15\n90 -60 -30 30 -30 15\n", "4\n0 -1 0 0\n0 0 1 0\n", "3\n1000000000 999999999 -1000000000\n999999999 -1000000000 -999999998\n" ]
[ "3\n", "6\n", "1\n" ]
In the first sample, there are four nice rectangles: Limak can't choose all of them because they are not disjoint. He should take three nice rectangles: those denoted as blue frames on the drawings. In the second sample, it's optimal to choose six nice rectangles, each consisting of one cell with a number 0. In the ...
0
[ { "input": "6\n70 70 70 70 70 -15\n90 -60 -30 30 -30 15", "output": "3" }, { "input": "4\n0 -1 0 0\n0 0 1 0", "output": "6" }, { "input": "3\n1000000000 999999999 -1000000000\n999999999 -1000000000 -999999998", "output": "1" }, { "input": "1\n0\n0", "output": "2" }, {...
1,689,647,186
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
31
0
print("_RANDOM_GUESS_1689647186.5794013")# 1689647186.5794203
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak has a grid that consists of 2 rows and *n* columns. The *j*-th cell in the *i*-th row contains an integer *t**i*,<=*j* which can be positive, negative or zero. A non-empty rectangle of cells is called nice if and only if th...
```python print("_RANDOM_GUESS_1689647186.5794013")# 1689647186.5794203 ```
0
1,007
A
Reorder the Array
PROGRAMMING
1,300
[ "combinatorics", "data structures", "math", "sortings", "two pointers" ]
null
null
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $[10, 20, 30, 40]$, we can ...
The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array.
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
[ "7\n10 1 1 1 5 5 3\n", "5\n1 1 1 1 1\n" ]
[ "4\n", "0\n" ]
In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4. In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
500
[ { "input": "7\n10 1 1 1 5 5 3", "output": "4" }, { "input": "5\n1 1 1 1 1", "output": "0" }, { "input": "6\n300000000 200000000 300000000 200000000 1000000000 300000000", "output": "3" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "9" }, { "input": "1\n1", ...
1,654,396,633
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
31
0
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) l = a[::-1] a.sort() c = 0 for i in range(n): if(l[i] == a[i]): c += 1 print(n - c)
Title: Reorder the Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find t...
```python import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) l = a[::-1] a.sort() c = 0 for i in range(n): if(l[i] == a[i]): c += 1 print(n - c) ```
0
701
B
Cells Not Under Attack
PROGRAMMING
1,200
[ "data structures", "math" ]
null
null
Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another. The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there ...
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=*min*(100<=000,<=*n*2)) — the size of the board and the number of rooks. Each of the next *m* lines contains integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the number of the row and the number of the col...
Print *m* integer, the *i*-th of them should be equal to the number of cells that are not under attack after first *i* rooks are put.
[ "3 3\n1 1\n3 1\n2 2\n", "5 2\n1 5\n5 1\n", "100000 1\n300 400\n" ]
[ "4 2 0 \n", "16 9 \n", "9999800001 \n" ]
On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack.
750
[ { "input": "3 3\n1 1\n3 1\n2 2", "output": "4 2 0 " }, { "input": "5 2\n1 5\n5 1", "output": "16 9 " }, { "input": "100000 1\n300 400", "output": "9999800001 " }, { "input": "10 4\n2 8\n1 8\n9 8\n6 9", "output": "81 72 63 48 " }, { "input": "30 30\n3 13\n27 23\n18...
1,589,790,356
2,147,483,647
PyPy 3
OK
TESTS
40
1,543
30,208,000
m,n=map(int,input().split()) s,q=m,m row=[0]*(m+1) co=[0]*(m+1) for i in range(n): a,b=map(int,input().split()) if row[a]==0: row[a]=1 s=s-1 if co[b]==0: co[b]=1 q=q-1 if i!=n-1: print(s*q,end=" ") else: print(s*q)
Title: Cells Not Under Attack Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another. The cell of the field is under rook's a...
```python m,n=map(int,input().split()) s,q=m,m row=[0]*(m+1) co=[0]*(m+1) for i in range(n): a,b=map(int,input().split()) if row[a]==0: row[a]=1 s=s-1 if co[b]==0: co[b]=1 q=q-1 if i!=n-1: print(s*q,end=" ") else: print(s*q) ``...
3
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportio...
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ...
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39...
1,694,182,579
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
122
0
n=int(input()) proportion=input().split() orange_volume=0 for i in range(0,n): orange_volume+=int(proportion[i]) print(orange_volume/3)
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*...
```python n=int(input()) proportion=input().split() orange_volume=0 for i in range(0,n): orange_volume+=int(proportion[i]) print(orange_volume/3) ```
0
369
C
Valera and Elections
PROGRAMMING
1,600
[ "dfs and similar", "graphs", "trees" ]
null
null
The city Valera lives in is going to hold elections to the city Parliament. The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, fo...
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of districts in the city. Then *n*<=-<=1 lines follow. Each line contains the description of a city road as three positive integers *x**i*, *y**i*, *t**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 1<=≤<=*t**i*<=≤<=2) — the districts connected by the *...
In the first line print a single non-negative number *k* — the minimum size of the required subset of candidates. Then on the second line print *k* space-separated integers *a*1,<=*a*2,<=... *a**k* — the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print a...
[ "5\n1 2 2\n2 3 2\n3 4 2\n4 5 2\n", "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1\n", "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2\n" ]
[ "1\n5 \n", "1\n3 \n", "4\n5 4 3 2 \n" ]
none
1,500
[ { "input": "5\n1 2 2\n2 3 2\n3 4 2\n4 5 2", "output": "1\n5 " }, { "input": "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1", "output": "1\n3 " }, { "input": "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2", "output": "4\n5 4 3 2 " }, { "input": "5\n1 5 1\n5 4 2\n4 3 1\n3 2 2", "output": "1\n2 " }, { ...
1,580,853,166
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
14,336,000
def R(): return map(int, input().split()) def I(): return int(input()) def S(): return str(input()) def L(): return list(R()) from collections import Counter import math import sys from itertools import permutations n=I() white=[0]*n con=[0]*n for i in range(n): con[i]=[] for i in range(...
Title: Valera and Elections Time Limit: None seconds Memory Limit: None megabytes Problem Description: The city Valera lives in is going to hold elections to the city Parliament. The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other...
```python def R(): return map(int, input().split()) def I(): return int(input()) def S(): return str(input()) def L(): return list(R()) from collections import Counter import math import sys from itertools import permutations n=I() white=[0]*n con=[0]*n for i in range(n): con[i]=[] for i...
0
676
E
The Last Fight Between Human and AI
PROGRAMMING
2,400
[ "math" ]
null
null
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet. The following game was chosen for the fights: initially there is a polynom...
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=|*k*|<=≤<=10<=000) — the size of the polynomial and the integer *k*. The *i*-th of the following *n*<=+<=1 lines contain character '?' if the coefficient near *x**i*<=-<=1 is yet undefined or the integer value *a**i*, if the coeffi...
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
[ "1 2\n-1\n?\n", "2 100\n-10000\n0\n1\n", "4 5\n?\n1\n?\n1\n?\n" ]
[ "Yes\n", "Yes", "No" ]
In the first sample, computer set *a*<sub class="lower-index">0</sub> to  - 1 on the first move, so if human can set coefficient *a*<sub class="lower-index">1</sub> to 0.5 and win. In the second sample, all coefficients are already set and the resulting polynomial is divisible by *x* - 100, so the human has won.
2,250
[ { "input": "1 2\n-1\n?", "output": "Yes" }, { "input": "2 100\n-10000\n0\n1", "output": "Yes" }, { "input": "4 5\n?\n1\n?\n1\n?", "output": "No" }, { "input": "68 -9959\n-3666\n-3501\n9169\n5724\n1478\n-643\n-3039\n-5537\n-4295\n-1856\n-6720\n6827\n-39\n-9509\n-7005\n1942\n-5...
1,678,985,400
6,000
PyPy 3
WRONG_ANSWER
TESTS
8
93
0
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, k = map(int, input().split()) a = [input().rstrip().decode() for _ in range(n + 1)] inf = pow(10, 9) + 1 b = [inf if i == "?" else int(i) for i in a] c = 0 for i in b: if i ^ inf: c += 1 if not k: ans = "...
Title: The Last Fight Between Human and AI Time Limit: None seconds Memory Limit: None megabytes Problem Description: 100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and ro...
```python import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, k = map(int, input().split()) a = [input().rstrip().decode() for _ in range(n + 1)] inf = pow(10, 9) + 1 b = [inf if i == "?" else int(i) for i in a] c = 0 for i in b: if i ^ inf: c += 1 if not k: ...
0
399
B
Red and Blue Balls
PROGRAMMING
0
[]
null
null
User ainta has a stack of *n* red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack. - While the top ball inside the stack is red, pop the ball from the top of the stack. - Then replace the blue ball on the top with a red ball. - And finally push some blue balls...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=50) — the number of balls inside the stack. The second line contains a string *s* (|*s*|<==<=*n*) describing the initial state of the stack. The *i*-th character of the string *s* denotes the color of the *i*-th ball (we'll number the balls from top to bottom of th...
Print the maximum number of operations ainta can repeatedly apply. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3\nRBR\n", "4\nRBBR\n", "5\nRBBRR\n" ]
[ "2\n", "6\n", "6\n" ]
The first example is depicted below. The explanation how user ainta applies the first operation. He pops out one red ball, changes the color of the ball in the middle from blue to red, and pushes one blue ball. The explanation how user ainta applies the second operation. He will not pop out red balls, he simply chang...
1,000
[ { "input": "3\nRBR", "output": "2" }, { "input": "4\nRBBR", "output": "6" }, { "input": "5\nRBBRR", "output": "6" }, { "input": "5\nRBRBR", "output": "10" }, { "input": "10\nRRBRRBBRRR", "output": "100" }, { "input": "10\nBRBRRRRRRR", "output": "5"...
1,501,423,535
2,147,483,647
Python 3
OK
TESTS
34
62
4,608,000
n = int(input()) s = input() ans = 0 for i in range(len(s)): ch = s[i] if ch == 'B': ans |= 1 << i print(ans)
Title: Red and Blue Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: User ainta has a stack of *n* red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack. - While the top ball inside the stack is red, pop the ball from the top of ...
```python n = int(input()) s = input() ans = 0 for i in range(len(s)): ch = s[i] if ch == 'B': ans |= 1 << i print(ans) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,607,768,021
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
186
0
n=input() s=0 t=0 for i in n: if i.isupper(): s+=1 elif i.islower(): t+=1 if s>=t: print(n.upper()) else: print(n.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python n=input() s=0 t=0 for i in n: if i.isupper(): s+=1 elif i.islower(): t+=1 if s>=t: print(n.upper()) else: print(n.lower()) ```
0
270
A
Fancy Fence
PROGRAMMING
1,100
[ "geometry", "implementation", "math" ]
null
null
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuska...
The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
[ "3\n30\n60\n90\n" ]
[ "NO\nYES\nYES\n" ]
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second test case, the fence is a r...
500
[ { "input": "3\n30\n60\n90", "output": "NO\nYES\nYES" }, { "input": "6\n1\n2\n3\n170\n179\n25", "output": "NO\nNO\nNO\nYES\nYES\nNO" } ]
1,664,179,477
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
t = int(input()) for i in range(t): a = 0 angle = int(input()) for j in range(3, 30): if (angle == (180*(j-2))/j): print("YES") a = 1 break if (a == 0): print("NO")
Title: Fancy Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can...
```python t = int(input()) for i in range(t): a = 0 angle = int(input()) for j in range(3, 30): if (angle == (180*(j-2))/j): print("YES") a = 1 break if (a == 0): print("NO") ```
0
4
C
Registration System
PROGRAMMING
1,300
[ "data structures", "hashing", "implementation" ]
C. Registration system
5
64
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. ...
The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.
Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.
[ "4\nabacaba\nacaba\nabacaba\nacab\n", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n" ]
[ "OK\nOK\nabacaba1\nOK\n", "OK\nfirst1\nOK\nsecond1\nOK\nthird1\n" ]
none
0
[ { "input": "4\nabacaba\nacaba\nabacaba\nacab", "output": "OK\nOK\nabacaba1\nOK" }, { "input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird", "output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1" }, { "input": "1\nn", "output": "OK" }, { "input": "2\nu\nu", "output": "OK\nu1" ...
1,690,048,851
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
62
0
n = int(input()) Name = [] f = 0 for a in range(n - 1): name = input() if f == 0: Name += [name] name = input() f += 1 lengthName = len(name) c = 0 b = 0 while b != len(Name): if name == Name[c] and len(name) == lengthName: name += "1" ...
Title: Registration System Time Limit: 5 seconds Memory Limit: 64 megabytes Problem Description: A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to imple...
```python n = int(input()) Name = [] f = 0 for a in range(n - 1): name = input() if f == 0: Name += [name] name = input() f += 1 lengthName = len(name) c = 0 b = 0 while b != len(Name): if name == Name[c] and len(name) == lengthName: name...
-1
774
D
Lie or Truth
PROGRAMMING
1,500
[ "*special", "constructive algorithms", "implementation", "sortings" ]
null
null
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,<=*a*2,<=...,<=*a**n*. While Vasya was walking, his little brother Stepan played with Vasya's cub...
The first line contains three integers *n*, *l*, *r* (1<=≤<=*n*<=≤<=105, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of integers written on cubes in the Vasya's order. ...
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
[ "5 2 4\n3 4 2 3 1\n3 2 3 4 1\n", "3 1 2\n1 2 3\n3 1 2\n", "4 2 4\n1 1 1 1\n1 1 1 1\n" ]
[ "TRUTH\n", "LIE\n", "TRUTH\n" ]
In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and...
0
[ { "input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1", "output": "TRUTH" }, { "input": "3 1 2\n1 2 3\n3 1 2", "output": "LIE" }, { "input": "4 2 4\n1 1 1 1\n1 1 1 1", "output": "TRUTH" }, { "input": "5 1 3\n2 2 2 1 2\n2 2 2 1 2", "output": "TRUTH" }, { "input": "7 1 4\n2 5 5 5...
1,491,409,368
2,868
Python 3
OK
TESTS
52
140
14,950,400
n, l, r = map(int, input().split()) l -= 1 r -= 1 a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(n): if (b[i] != a[i]) and (i < l or i > r): print("LIE") break else: print("TRUTH")
Title: Lie or Truth Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,...
```python n, l, r = map(int, input().split()) l -= 1 r -= 1 a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(n): if (b[i] != a[i]) and (i < l or i > r): print("LIE") break else: print("TRUTH") ```
3
172
C
Bus
PROGRAMMING
1,500
[ "*special", "implementation", "sortings" ]
null
null
There is a bus stop near the university. The lessons are over, and *n* students come to the stop. The *i*-th student will appear at the bus stop at time *t**i* (all *t**i*'s are distinct). We shall assume that the stop is located on the coordinate axis *Ox*, at point *x*<==<=0, and the bus goes along the ray *Ox*, tha...
The first line contains two space-separated integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of students and the number of passengers the bus can transport, correspondingly. Next *n* lines contain descriptions of the students, one per line. Each line contains a pair of integers *t**i*,<=*x**i* (1<=≤<=*t**i*<=≤...
Print *n* numbers *w*1,<=*w*2,<=...,<=*w**n*, *w**i* — the moment of time when the *i*-th student got off the bus. Print the numbers on one line and separate them with single spaces.
[ "1 10\n3 5\n", "2 1\n3 5\n4 5\n", "5 4\n3 5\n4 5\n5 5\n6 5\n7 1\n", "20 4\n28 13\n31 13\n35 6\n36 4\n52 6\n53 4\n83 2\n84 4\n87 1\n93 6\n108 4\n113 6\n116 1\n125 2\n130 2\n136 13\n162 2\n166 4\n184 1\n192 2\n" ]
[ "8\n", "8 19\n", "11 11 11 11 20\n", "51 51 43 40 93 89 86 89 114 121 118 121 137 139 139 152 195 199 193 195\n" ]
In the first sample the bus waits for the first student for 3 units of time and drives him to his destination in additional 5 units of time. So the student leaves the bus at the moment of time 3 + 5 = 8. In the second sample the capacity of the bus equals 1, that's why it will drive the first student alone. This stude...
1,500
[ { "input": "1 10\n3 5", "output": "8" }, { "input": "2 1\n3 5\n4 5", "output": "8 19" }, { "input": "5 4\n3 5\n4 5\n5 5\n6 5\n7 1", "output": "11 11 11 11 20" }, { "input": "20 4\n28 13\n31 13\n35 6\n36 4\n52 6\n53 4\n83 2\n84 4\n87 1\n93 6\n108 4\n113 6\n116 1\n125 2\n130 2\...
1,651,327,818
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
15
1,000
7,987,200
def solution_task3(): data = input().split(" ") n = int(data[0]) m = int(data[1]) students = dict() for i in range(n): data = input().split(" ") students[int(data[0])] = int(data[1]) current_passengers = 0 total_time = 0 students_per_time = [ti for ti in student...
Title: Bus Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a bus stop near the university. The lessons are over, and *n* students come to the stop. The *i*-th student will appear at the bus stop at time *t**i* (all *t**i*'s are distinct). We shall assume that the stop is located ...
```python def solution_task3(): data = input().split(" ") n = int(data[0]) m = int(data[1]) students = dict() for i in range(n): data = input().split(" ") students[int(data[0])] = int(data[1]) current_passengers = 0 total_time = 0 students_per_time = [ti for ti ...
0
352
A
Jeff and Digits
PROGRAMMING
1,000
[ "brute force", "implementation", "math" ]
null
null
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got? Jeff must make the number without leading zero. At that, we assume that numbe...
The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card.
In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
[ "4\n5 0 5 0\n", "11\n5 5 5 5 5 5 5 5 0 5 5\n" ]
[ "0\n", "5555555550\n" ]
In the first test you can make only one number that is a multiple of 90 — 0. In the second test you can make number 5555555550, it is a multiple of 90.
500
[ { "input": "4\n5 0 5 0", "output": "0" }, { "input": "11\n5 5 5 5 5 5 5 5 0 5 5", "output": "5555555550" }, { "input": "7\n5 5 5 5 5 5 5", "output": "-1" }, { "input": "1\n5", "output": "-1" }, { "input": "1\n0", "output": "0" }, { "input": "11\n5 0 5 ...
1,685,865,880
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
62
0
n = int(input()) a = 0 b = 0 s = input().split() for i in s: if i == "5": a += 1 if i == "0": b += 1 if a >= 9 : if b > 0: print("5"*9,"0"*b,sep="") else: print(-1) else: if b > 0: print(0) else: print(-1)
Title: Jeff and Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make fr...
```python n = int(input()) a = 0 b = 0 s = input().split() for i in s: if i == "5": a += 1 if i == "0": b += 1 if a >= 9 : if b > 0: print("5"*9,"0"*b,sep="") else: print(-1) else: if b > 0: print(0) else: print(-1) `...
0
0
none
none
none
0
[ "none" ]
null
null
The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest integer that is divisor of both *x* and *y*, it is denoted as . For example, for array *a*<==<={...
The first line contains number *n* (1<=≤<=*n*<=≤<=500) — the length of array *a*. The second line contains *n*2 space-separated numbers — the elements of the GCD table of *G* for array *a*. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. I...
In the single line print *n* positive integers — the elements of array *a*. If there are multiple possible solutions, you are allowed to print any of them.
[ "4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n", "1\n42\n", "2\n1 1 1 1\n" ]
[ "4 3 6 2", "42 ", "1 1 " ]
none
0
[ { "input": "4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "output": "2 3 4 6 " }, { "input": "1\n42", "output": "42 " }, { "input": "2\n1 1 1 1", "output": "1 1 " }, { "input": "2\n54748096 1 641009859 1", "output": "54748096 641009859 " }, { "input": "3\n1 7 923264237 374...
1,464,898,753
3,373
Python 3
OK
TESTS
54
811
23,859,200
import fractions import collections n = int(input()) l = sorted(map(int, input().split(" ")), reverse = True) aux = [] cont = collections.Counter(l) r = [] for i in l: if not cont[i]: continue r.append(i) cont[i] -= 1 for j in aux: '''print(str(i) + " "...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest intege...
```python import fractions import collections n = int(input()) l = sorted(map(int, input().split(" ")), reverse = True) aux = [] cont = collections.Counter(l) r = [] for i in l: if not cont[i]: continue r.append(i) cont[i] -= 1 for j in aux: '''print(st...
3
535
B
Tavas and SaDDas
PROGRAMMING
1,100
[ "bitmasks", "brute force", "combinatorics", "implementation" ]
null
null
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You ar...
The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109).
Print the index of *n* among all lucky numbers.
[ "4\n", "7\n", "77\n" ]
[ "1\n", "2\n", "6\n" ]
none
1,000
[ { "input": "4", "output": "1" }, { "input": "7", "output": "2" }, { "input": "77", "output": "6" }, { "input": "4", "output": "1" }, { "input": "474744", "output": "83" }, { "input": "777774", "output": "125" }, { "input": "447", "outpu...
1,610,286,670
2,147,483,647
PyPy 3
OK
TESTS
33
108
0
a = int(input()) b = str(a) h = 0 t = len(b) for x in range(t): if b[x] == "4": h += (2**(t-1-x))*1 else: h += (2**(t-1-x))*2 print(h)
Title: Tavas and SaDDas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone...
```python a = int(input()) b = str(a) h = 0 t = len(b) for x in range(t): if b[x] == "4": h += (2**(t-1-x))*1 else: h += (2**(t-1-x))*2 print(h) ```
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,686,847,217
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
def abbreviate_words(text): words = text.split() abbreviated_text = [] for word in words: if len(word) > 10: abbreviation = word[0] + str(len(word) - 2) + word[-1] abbreviated_text.append(abbreviation) else: abbreviated_text.append(word) retu...
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python def abbreviate_words(text): words = text.split() abbreviated_text = [] for word in words: if len(word) > 10: abbreviation = word[0] + str(len(word) - 2) + word[-1] abbreviated_text.append(abbreviation) else: abbreviated_text.append(word) ...
0
554
A
Kyoya and Photobooks
PROGRAMMING
900
[ "brute force", "math", "strings" ]
null
null
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho...
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters.
Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.
[ "a\n", "hi\n" ]
[ "51\n", "76\n" ]
In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets.
250
[ { "input": "a", "output": "51" }, { "input": "hi", "output": "76" }, { "input": "y", "output": "51" }, { "input": "kgan", "output": "126" }, { "input": "zoabkyuvus", "output": "276" }, { "input": "spyemhyznjieyhhbk", "output": "451" }, { "i...
1,669,886,266
2,147,483,647
Python 3
OK
TESTS
33
46
0
s = (input()) print((len(s)+1)*25+1)
Title: Kyoya and Photobooks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos b...
```python s = (input()) print((len(s)+1)*25+1) ```
3
802
G
Fake News (easy)
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z).
Output YES if the string *s* contains heidi as a subsequence and NO otherwise.
[ "abcheaibcdi\n", "hiedi\n" ]
[ "YES", "NO" ]
A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
0
[ { "input": "abcheaibcdi", "output": "YES" }, { "input": "hiedi", "output": "NO" }, { "input": "ihied", "output": "NO" }, { "input": "diehi", "output": "NO" }, { "input": "deiih", "output": "NO" }, { "input": "iheid", "output": "NO" }, { "in...
1,660,525,382
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
1,000
0
s = input() if s.count('h') >= 1 and s.count('e') >= 1 and s.count('i') >= 2 and s.count('d') >= 1: h_index = [] e_index = [] i_index = [] d_index = [] for i in range(len(s)): if s[i] == 'h': h_index.append(i) elif s[i] == 'e': e_index.append(i) elif ...
Title: Fake News (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ...
```python s = input() if s.count('h') >= 1 and s.count('e') >= 1 and s.count('i') >= 2 and s.count('d') >= 1: h_index = [] e_index = [] i_index = [] d_index = [] for i in range(len(s)): if s[i] == 'h': h_index.append(i) elif s[i] == 'e': e_index.append(i) ...
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,645,697,927
2,147,483,647
Python 3
OK
TESTS
81
92
0
n = int(input()) d = 0 ; e = 0; f = 0 for i in range(n): a,b,c = map(int,input().split()) d += a ; e += b ; f += c if d == 0 and e == 0 and f == 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 n = int(input()) d = 0 ; e = 0; f = 0 for i in range(n): a,b,c = map(int,input().split()) d += a ; e += b ; f += c if d == 0 and e == 0 and f == 0: print("YES") else: print("NO") ```
3.977
899
C
Dividing the numbers
PROGRAMMING
1,300
[ "constructive algorithms", "graphs", "math" ]
null
null
Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible. Help Petya to split the integers. Each of *n* integers should be exactly in one group.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has.
Print the smallest possible absolute difference in the first line. In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
[ "4\n", "2\n" ]
[ "0\n2 1 4 \n", "1\n1 1 \n" ]
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0. In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and on...
1,500
[ { "input": "4", "output": "0\n2 1 4 " }, { "input": "2", "output": "1\n1 1 " }, { "input": "3", "output": "0\n1\n3 " }, { "input": "5", "output": "1\n3\n1 2 5 " }, { "input": "59998", "output": "1\n29999 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 4...
1,679,597,585
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
n = int(input()) sigma = int(n*(n+1)/2) dif = sigma%2 grupo1 = [] grupo2 = [] i = n sum = 0 while sum < sigma//2 and i > 0: print(sum, " ", sigma//2) if (sum + i <= sigma//2): sum += i grupo2.append(i) print(1) else: grupo1.append(i) print(2) i -= 1 print(len(g...
Title: Dividing the numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible. Help P...
```python n = int(input()) sigma = int(n*(n+1)/2) dif = sigma%2 grupo1 = [] grupo2 = [] i = n sum = 0 while sum < sigma//2 and i > 0: print(sum, " ", sigma//2) if (sum + i <= sigma//2): sum += i grupo2.append(i) print(1) else: grupo1.append(i) print(2) i -= 1 p...
0
596
B
Wilbur and Array
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is ...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input. The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109).
Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*.
[ "5\n1 2 3 4 5\n", "4\n1 2 2 1\n" ]
[ "5", "3" ]
In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes. In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
1,000
[ { "input": "5\n1 2 3 4 5", "output": "5" }, { "input": "4\n1 2 2 1", "output": "3" }, { "input": "3\n1 2 4", "output": "4" }, { "input": "6\n1 2 3 6 5 4", "output": "8" }, { "input": "10\n2 1 4 3 6 5 8 7 10 9", "output": "19" }, { "input": "7\n12 6 12 ...
1,447,608,143
2,843
Python 3
WRONG_ANSWER
PRETESTS
2
46
0
n=int(input()) r=[int(j) for j in input().split()] q=0 t=True for j in range(1,n): if t==True: if r[j]>r[j-1]: q=q+1 else: if r[j]<r[j-1]: q=q+1 t=False else: if r[j]<r[j-1]: q=q+1 else: ...
Title: Wilbur and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+...
```python n=int(input()) r=[int(j) for j in input().split()] q=0 t=True for j in range(1,n): if t==True: if r[j]>r[j-1]: q=q+1 else: if r[j]<r[j-1]: q=q+1 t=False else: if r[j]<r[j-1]: q=q+1 else: ...
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,662,443,013
2,147,483,647
Python 3
OK
TESTS
102
61
0
n=str(input()) m=str(input()) o=' ' for i in range(len(m)): if n[i]==m[i]: o+='0' else: o+='1' print(o)
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 n=str(input()) m=str(input()) o=' ' for i in range(len(m)): if n[i]==m[i]: o+='0' else: o+='1' print(o) ```
3.98475
8
A
Train and Peter
PROGRAMMING
1,200
[ "strings" ]
A. Train and Peter
1
64
Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour. The boy start...
The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order. The second lin...
Output one of the four words without inverted commas: - «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fanta...
[ "atob\na\nb\n", "aaacaaa\naca\naa\n" ]
[ "forward\n", "both\n" ]
It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.
0
[ { "input": "atob\na\nb", "output": "forward" }, { "input": "aaacaaa\naca\naa", "output": "both" }, { "input": "aaa\naa\naa", "output": "fantasy" }, { "input": "astalavista\nastla\nlavista", "output": "fantasy" }, { "input": "abacabadabacaba\nabacaba\nabacaba", ...
1,546,247,101
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
218
0
str = input() a = input() b = input() flag = 0 if a in str and b in str: flag += 1 if a in str[:-1] and b in str[:-1]: flag += 2 if flag == 0: print('fantasy') elif flag == 1: print('forward') elif flag == 2: print('backward') else: print('both')
Title: Train and Peter Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the...
```python str = input() a = input() b = input() flag = 0 if a in str and b in str: flag += 1 if a in str[:-1] and b in str[:-1]: flag += 2 if flag == 0: print('fantasy') elif flag == 1: print('forward') elif flag == 2: print('backward') else: print('both') ```
0
52
A
123-sequence
PROGRAMMING
900
[ "implementation" ]
A. 123-sequence
2
256
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3).
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
[ "9\n1 3 2 2 2 1 1 2 3\n" ]
[ "5\n" ]
In the example all the numbers equal to 1 and 3 should be replaced by 2.
500
[ { "input": "9\n1 3 2 2 2 1 1 2 3", "output": "5" }, { "input": "6\n3 3 2 2 1 3", "output": "3" }, { "input": "12\n3 1 3 1 2 1 3 2 2 1 2 1", "output": "7" }, { "input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2", "output": "10" }, { "input": "2\n2 1", "output": "1" ...
1,676,667,309
2,147,483,647
Python 3
OK
TESTS
23
342
11,059,200
print(int(input()) - max((map(input().split().count, map(str, range(1, 4))))))
Title: 123-sequence Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each...
```python print(int(input()) - max((map(input().split().count, map(str, range(1, 4)))))) ```
3.893901
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex...
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at...
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ...
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1...
1,696,317,778
2,147,483,647
Python 3
OK
TESTS
71
92
0
stops = int(input()) capacity = 0 inside = 0 for i in range(stops): a, b = map(int, input().split(" ")) inside = inside - a + b capacity = max(capacity, inside) print(capacity)
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ...
```python stops = int(input()) capacity = 0 inside = 0 for i in range(stops): a, b = map(int, input().split(" ")) inside = inside - a + b capacity = max(capacity, inside) print(capacity) ```
3
714
A
Meeting of Old Friends
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya. Filya works a lot and he plans to ...
The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
[ "1 10 9 20 1\n", "1 100 50 200 75\n" ]
[ "2\n", "50\n" ]
In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
500
[ { "input": "1 10 9 20 1", "output": "2" }, { "input": "1 100 50 200 75", "output": "50" }, { "input": "6 6 5 8 9", "output": "1" }, { "input": "1 1000000000 1 1000000000 1", "output": "999999999" }, { "input": "5 100 8 8 8", "output": "0" }, { "input":...
1,541,314,046
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
a,b,c,d,e=map(int,raw_input().split()) a=max(a,c) b=min(b,d) print max(0,b-a+1)
Title: Meeting of Old Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusi...
```python a,b,c,d,e=map(int,raw_input().split()) a=max(a,c) b=min(b,d) print max(0,b-a+1) ```
-1
8
B
Obsession with Robots
PROGRAMMING
1,400
[ "constructive algorithms", "graphs", "implementation" ]
B. Obsession with Robots
2
64
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a ...
The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100.
In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).
[ "LLUUUR\n", "RRUULLDD\n" ]
[ "OK\n", "BUG\n" ]
none
0
[ { "input": "LLUUUR", "output": "OK" }, { "input": "RRUULLDD", "output": "BUG" }, { "input": "L", "output": "OK" }, { "input": "R", "output": "OK" }, { "input": "R", "output": "OK" }, { "input": "RR", "output": "OK" }, { "input": "DL", "...
1,625,754,754
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
squares=[[0,0]] x=y=0 check=True def readInput(direction,x,y): if direction=='R': return [x+1,y] elif direction=='L': return [x-1,y] elif direction=='U': return [x,y+1] elif direction=='D': return [x,y-1] path=input() for d in path: x,y=direction(d,x...
Title: Obsession with Robots Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path fr...
```python squares=[[0,0]] x=y=0 check=True def readInput(direction,x,y): if direction=='R': return [x+1,y] elif direction=='L': return [x-1,y] elif direction=='U': return [x,y+1] elif direction=='D': return [x,y-1] path=input() for d in path: x,y=dir...
-1
0
none
none
none
0
[ "none" ]
null
null
The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph *G*. It is required to find a subset of vertices *C* of the maximum size such that any two of them are connected by an edge in graph *G*. Sounds simple, doesn't ...
The first line contains the integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of points. Each of the next *n* lines contains two numbers *x**i*, *w**i* (0<=≤<=*x**i*<=≤<=109,<=1<=≤<=*w**i*<=≤<=109) — the coordinate and the weight of a point. All *x**i* are different.
Print a single number — the number of vertexes in the maximum clique of the given graph.
[ "4\n2 3\n3 1\n6 1\n0 2\n" ]
[ "3\n" ]
If you happen to know how to solve this problem without using the specific properties of the graph formulated in the problem statement, then you are able to get a prize of one million dollars! The picture for the sample test.
0
[ { "input": "4\n2 3\n3 1\n6 1\n0 2", "output": "3" }, { "input": "1\n42 23", "output": "1" }, { "input": "2\n1 5\n2 6", "output": "1" }, { "input": "2\n1 5\n12 6", "output": "2" }, { "input": "1\n0 1", "output": "1" }, { "input": "1\n1000000000 10000000...
1,577,926,663
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
13
561
16,384,000
def solve(): from sys import stdin f_i = stdin n = int(f_i.readline()) points = [] for i in range(n): x, w = map(int, f_i.readline().split()) points.append((x - w, x + w)) points.sort() ans = 0 t = points[0][0] for start, end in points: ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph *G*. It is required to find a subset of vertices *C* of the maximum siz...
```python def solve(): from sys import stdin f_i = stdin n = int(f_i.readline()) points = [] for i in range(n): x, w = map(int, f_i.readline().split()) points.append((x - w, x + w)) points.sort() ans = 0 t = points[0][0] for start, end in ...
0
219
D
Choosing Capital for Treeland
PROGRAMMING
1,700
[ "dfs and similar", "dp", "graphs", "trees" ]
null
null
The country Treeland consists of *n* cities, some pairs of them are connected with unidirectional roads. Overall there are *n*<=-<=1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to any other one. The council of the elders has recently decid...
The first input line contains integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of cities in Treeland. Next *n*<=-<=1 lines contain the descriptions of the roads, one road per line. A road is described by a pair of integers *s**i*,<=*t**i* (1<=≤<=*s**i*,<=*t**i*<=≤<=*n*; *s**i*<=≠<=*t**i*) — the numbers of cities, connect...
In the first line print the minimum number of roads to be inversed if the capital is chosen optimally. In the second line print all possible ways to choose the capital — a sequence of indexes of cities in the increasing order.
[ "3\n2 1\n2 3\n", "4\n1 4\n2 4\n3 4\n" ]
[ "0\n2 \n", "2\n1 2 3 \n" ]
none
2,000
[ { "input": "3\n2 1\n2 3", "output": "0\n2 " }, { "input": "4\n1 4\n2 4\n3 4", "output": "2\n1 2 3 " }, { "input": "2\n1 2", "output": "0\n1 " }, { "input": "8\n1 2\n3 2\n4 3\n4 5\n6 5\n6 7\n8 7", "output": "3\n4 6 8 " }, { "input": "10\n2 3\n1 8\n9 5\n5 4\n6 10\n4...
1,628,502,946
2,147,483,647
PyPy 3
OK
TESTS
34
2,182
104,857,600
from collections import deque, defaultdict import sys from types import GeneratorType input = sys.stdin.readline def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: ...
Title: Choosing Capital for Treeland Time Limit: None seconds Memory Limit: None megabytes Problem Description: The country Treeland consists of *n* cities, some pairs of them are connected with unidirectional roads. Overall there are *n*<=-<=1 roads in the country. We know that if we don't take the direction of the...
```python from collections import deque, defaultdict import sys from types import GeneratorType input = sys.stdin.readline def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while T...
3
893
C
Rumor
PROGRAMMING
1,300
[ "dfs and similar", "graphs", "greedy" ]
null
null
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it. Now he tries to solve a quest. The task is to come to a settlement named Ove...
The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends. The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor. ...
Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.
[ "5 2\n2 5 3 4 8\n1 4\n4 5\n", "10 0\n1 2 3 4 5 6 7 8 9 10\n", "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n" ]
[ "10\n", "55\n", "15\n" ]
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor. In the second example Vova has to bribe everyone. In the third example ...
0
[ { "input": "5 2\n2 5 3 4 8\n1 4\n4 5", "output": "10" }, { "input": "10 0\n1 2 3 4 5 6 7 8 9 10", "output": "55" }, { "input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10", "output": "15" }, { "input": "1 0\n0", "output": "0" }, { "input": "1 0\n10000000...
1,599,853,624
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n, m = map(int,input().split()) ans = 0 b = [] for i in range(n): b.append(i) a = list(map(int,input().split())) if m == 0: print(sum(a)) quit() for i in range(m): x, y = map(int,input().split()) ans += min(x, y) print(ans)
Title: Rumor Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte...
```python n, m = map(int,input().split()) ans = 0 b = [] for i in range(n): b.append(i) a = list(map(int,input().split())) if m == 0: print(sum(a)) quit() for i in range(m): x, y = map(int,input().split()) ans += min(x, y) print(ans) ```
-1
343
B
Alternating Current
PROGRAMMING
1,600
[ "data structures", "greedy", "implementation" ]
null
null
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended u...
The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.
Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.
[ "-++-\n", "+-\n", "++\n", "-\n" ]
[ "Yes\n", "No\n", "Yes\n", "No\n" ]
The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full rev...
1,000
[ { "input": "-++-", "output": "Yes" }, { "input": "+-", "output": "No" }, { "input": "++", "output": "Yes" }, { "input": "-", "output": "No" }, { "input": "+-+-", "output": "No" }, { "input": "-+-", "output": "No" }, { "input": "-++-+--+", ...
1,676,687,569
2,147,483,647
PyPy 3-64
OK
TESTS
62
996
10,444,800
signals = input() def wires(strg): transformed_signals = "" for i in range(len(signals)): if i % 2 == 0: if signals[i] == "+": transformed_signals += "A" else: transformed_signals += "B" else: if signals[i] == "+": ...
Title: Alternating Current Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it...
```python signals = input() def wires(strg): transformed_signals = "" for i in range(len(signals)): if i % 2 == 0: if signals[i] == "+": transformed_signals += "A" else: transformed_signals += "B" else: if signals[i] =...
3
397
A
On Segment's Own Points
PROGRAMMING
0
[ "implementation" ]
null
null
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. The dorm has exactly one straight dryer — a 100 ce...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). The (*i*<=+<=1)-th line contains integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=100) — the endpoints of the corresponding segment for the *i*-th student.
On a single line print a single number *k*, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments.
[ "3\n0 5\n2 8\n1 6\n", "3\n0 10\n1 5\n7 15\n" ]
[ "1\n", "3\n" ]
Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments. In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and...
500
[ { "input": "3\n0 5\n2 8\n1 6", "output": "1" }, { "input": "3\n0 10\n1 5\n7 15", "output": "3" }, { "input": "1\n0 100", "output": "100" }, { "input": "2\n1 9\n1 9", "output": "0" }, { "input": "2\n1 9\n5 10", "output": "4" }, { "input": "2\n1 9\n3 5",...
1,580,820,078
2,147,483,647
Python 3
OK
TESTS
37
109
307,200
num_of_student = int(input()) sush = list() for i in range(0, num_of_student): inp = input() inp_spl = inp.split(" ") sush.append(int(inp_spl[0])) sush.append(int(inp_spl[1])) one_range = [0 for i in range(0, max(sush)+1)] for i in range(0, num_of_student*2, 2): for j in range(sush[i], sush[i+1])...
Title: On Segment's Own Points Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some...
```python num_of_student = int(input()) sush = list() for i in range(0, num_of_student): inp = input() inp_spl = inp.split(" ") sush.append(int(inp_spl[0])) sush.append(int(inp_spl[1])) one_range = [0 for i in range(0, max(sush)+1)] for i in range(0, num_of_student*2, 2): for j in range(sush[i], ...
3
760
B
Frodo and pillows
PROGRAMMING
1,500
[ "binary search", "greedy" ]
null
null
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit ge...
The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed.
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
[ "4 6 2\n", "3 10 3\n", "3 6 1\n" ]
[ "2\n", "4\n", "3\n" ]
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds. In the second example Frodo can take at most four pillows, giving three pillows to each of the others. In the third exa...
1,000
[ { "input": "4 6 2", "output": "2" }, { "input": "3 10 3", "output": "4" }, { "input": "3 6 1", "output": "3" }, { "input": "3 3 3", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "1 1000000000 1", "output": "1000000000" }, { ...
1,506,533,902
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
# x is the number of pillows Frodo wants def is_ok(x, y): if y > (x - 1): val = (((x-1) * x) >> 1) + y - (x - 1) else: val = (y * (x - 1 + x - y)) >> 1 return val hobbits, pillows, k = [int(x) for x in input().split()] l = 1 r = pillows while l <= ...
Title: Frodo and pillows Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as ma...
```python # x is the number of pillows Frodo wants def is_ok(x, y): if y > (x - 1): val = (((x-1) * x) >> 1) + y - (x - 1) else: val = (y * (x - 1 + x - y)) >> 1 return val hobbits, pillows, k = [int(x) for x in input().split()] l = 1 r = pillows w...
0
408
B
Garland
PROGRAMMING
1,200
[ "implementation" ]
null
null
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter. The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each pie...
The first line contains a non-empty sequence of *n* (1<=≤<=*n*<=≤<=1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color. The second line contains a non-empty sequence of *m* (1<=≤<=*m*<=≤<=1000) small English letters that correspond to the colors of the ...
Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.
[ "aaabbac\naabbccac\n", "a\nz\n" ]
[ "6\n", "-1" ]
In the first test sample Vasya can make an garland of area 6: he can use both sheets of color *b*, three (but not four) sheets of color *a* and cut a single sheet of color *c* in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6. In the second test sample Vasya cannot mak...
1,000
[ { "input": "aaabbac\naabbccac", "output": "6" }, { "input": "a\nz", "output": "-1" }, { "input": "r\nr", "output": "1" }, { "input": "stnsdn\nndnndsn", "output": "4" }, { "input": "yqfqfp\ntttwtqq", "output": "-1" }, { "input": "zzbbrrtrtzr\ntbbtrrrzr"...
1,601,048,700
2,147,483,647
PyPy 3
OK
TESTS
21
186
0
n = input() m = input() total_c = 0 for i in m: n_count = n.count(i) if n_count==0: total_c = 0 break total_c+=min(n_count,m.count(i)) m = m.replace(i,'') if total_c==0: total_c-=1 print(total_c)
Title: Garland Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter....
```python n = input() m = input() total_c = 0 for i in m: n_count = n.count(i) if n_count==0: total_c = 0 break total_c+=min(n_count,m.count(i)) m = m.replace(i,'') if total_c==0: total_c-=1 print(total_c) ```
3
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,644,348,019
2,147,483,647
PyPy 3-64
OK
TESTS
32
154
0
n = int(input()) s = input().split() even_counter=0 temp, temp2 = 0, 0 for i in range(n): if int(s[i])%2 == 0: even_counter+=1 temp = i+1 else: temp2 = i+1 if even_counter>len(s)//2: print(temp2) else: print(temp)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python n = int(input()) s = input().split() even_counter=0 temp, temp2 = 0, 0 for i in range(n): if int(s[i])%2 == 0: even_counter+=1 temp = i+1 else: temp2 = i+1 if even_counter>len(s)//2: print(temp2) else: print(temp) ```
3.9615
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ...
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Print a single line containing a positive integer *m* — the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" ...
1,598,252,090
2,147,483,647
Python 3
OK
TESTS
10
93
6,656,000
def fact(n): sums = 1 for i in range(2, n + 1): sums *= i return sums n = 2 * (int(input()) - 1) print(fact(n) // fact(n // 2) // fact(n - n // 2))
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t...
```python def fact(n): sums = 1 for i in range(2, n + 1): sums *= i return sums n = 2 * (int(input()) - 1) print(fact(n) // fact(n // 2) // fact(n - n // 2)) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,621,622,658
2,147,483,647
Python 3
OK
TESTS
30
124
0
# author : Leandro # problem : A. Word # platform : Codeforces # date : 2021-05-21 line = input() lower = 0 for c in line: lower += int(c.islower()) solution = line.upper() if lower < len(line) - lower else line.lower() print(solution)
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 # author : Leandro # problem : A. Word # platform : Codeforces # date : 2021-05-21 line = input() lower = 0 for c in line: lower += int(c.islower()) solution = line.upper() if lower < len(line) - lower else line.lower() print(solution) ```
3.969
821
C
Okabe and Boxes
PROGRAMMING
1,500
[ "data structures", "greedy", "trees" ]
null
null
Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack. Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the sta...
The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of boxes. Each of the next 2*n* lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer *x* (1<=≤<=*x*<=≤<=*n*) follows, indicating that Daru should add the box with number *x* to the top of...
Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands.
[ "3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n", "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n" ]
[ "1\n", "2\n" ]
In the first sample, Daru should reorder the boxes after adding box 3 to the stack. In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack.
1,500
[ { "input": "3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove", "output": "1" }, { "input": "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove", "output": "2" }, { "input": "4\nadd 1\nadd 3\nremove\nadd 4\nadd 2\nremove\nremove\nremov...
1,541,157,905
2,345
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
3,000
52,736,000
import sys def main(input): n = int(next(input)) result = 0 last_rebuild = -1 required_box = 1 boxes = set() add_time = [0] * 2 * n for i in range(2 * n): query = next(input).split() if query[0] == 'add': id = int(query[1]) add_time[id] = i boxes.add((i, id)) else: las...
Title: Okabe and Boxes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack. Okabe, being a control freak, gives Daru 2*n* commands: *n* of which a...
```python import sys def main(input): n = int(next(input)) result = 0 last_rebuild = -1 required_box = 1 boxes = set() add_time = [0] * 2 * n for i in range(2 * n): query = next(input).split() if query[0] == 'add': id = int(query[1]) add_time[id] = i boxes.add((i, id)) else:...
0
416
C
Booking System
PROGRAMMING
1,600
[ "binary search", "dp", "greedy", "implementation" ]
null
null
Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are *n* booking requests received by now. Each request is characterized by two numbers: *c**i*...
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of requests from visitors. Then *n* lines follow. Each line contains two integers: *c**i*,<=*p**i* (1<=≤<=*c**i*,<=*p**i*<=≤<=1000) — the size of the group of visitors who will come by the *i*-th request and the total sum of money they w...
In the first line print two integers: *m*,<=*s* — the number of accepted requests and the total money you get from these requests, correspondingly. Then print *m* lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this...
[ "3\n10 50\n2 100\n5 30\n3\n4 6 9\n" ]
[ "2 130\n2 1\n3 2\n" ]
none
1,500
[ { "input": "3\n10 50\n2 100\n5 30\n3\n4 6 9", "output": "2 130\n2 1\n3 2" }, { "input": "1\n1 1\n1\n1", "output": "1 1\n1 1" }, { "input": "1\n2 1\n1\n1", "output": "0 0" }, { "input": "2\n10 10\n5 5\n1\n5", "output": "1 5\n2 1" }, { "input": "2\n10 10\n5 5\n1\n10...
1,397,402,485
2,485
Python 3
WRONG_ANSWER
TESTS
4
61
0
n=int(input()) P=[] for i in range(n): x,y=map(int,input().split()) P.append((y,x,i)) k=int(input()) L=list(map(int,input().split())) for i in range(k): L[i]=(L[i],i) L.sort() P.sort() ans=0 Taken=[False]*k r=0 Ans=[-1]*n for i in range(n): for j in range(k): if(L[j][0]>=P[i...
Title: Booking System Time Limit: None seconds Memory Limit: None megabytes Problem Description: Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. ...
```python n=int(input()) P=[] for i in range(n): x,y=map(int,input().split()) P.append((y,x,i)) k=int(input()) L=list(map(int,input().split())) for i in range(k): L[i]=(L[i],i) L.sort() P.sort() ans=0 Taken=[False]*k r=0 Ans=[-1]*n for i in range(n): for j in range(k): if(L[...
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,672,156,757
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n=int(input()) if 1<=n<=100: for i in range(0, n): w=str(input()) if len(w)>10 and w.isalpha()==True and w.isupper()==False and 1<=len(w)<=100: print(w[0]+str(len(w))+w[-1]) elif len(w)<10 and w.isupper()==False and w.isalpha()==True and 1<=len(w)<=100: print(w...
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python n=int(input()) if 1<=n<=100: for i in range(0, n): w=str(input()) if len(w)>10 and w.isalpha()==True and w.isupper()==False and 1<=len(w)<=100: print(w[0]+str(len(w))+w[-1]) elif len(w)<10 and w.isupper()==False and w.isalpha()==True and 1<=len(w)<=100: ...
0
991
E
Bus Number
PROGRAMMING
1,800
[ "brute force", "combinatorics", "math" ]
null
null
This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. ...
The first line contains one integer $n$ ($1 \leq n \leq 10^{18}$) — the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with $0$.
Output a single integer — the amount of possible variants of the real bus number.
[ "97\n", "2028\n" ]
[ "2\n", "13\n" ]
In the first sample, only variants $97$ and $79$ are possible. In the second sample, the variants (in the increasing order) are the following: $208$, $280$, $802$, $820$, $2028$, $2082$, $2208$, $2280$, $2802$, $2820$, $8022$, $8202$, $8220$.
2,000
[ { "input": "97", "output": "2" }, { "input": "2028", "output": "13" }, { "input": "1", "output": "1" }, { "input": "10", "output": "1" }, { "input": "168", "output": "6" }, { "input": "999999", "output": "6" }, { "input": "98765432002345678...
1,657,784,381
2,147,483,647
Python 3
OK
TESTS
61
46
102,400
from collections import Counter from itertools import product s = input() ds = Counter(s) fac = [1 for i in range(100)] for i in range(1, 100): fac[i] = fac[i-1] * i res = 0 for possib in product(*[zip([k] * n, range(1, n+1)) for k, n in ds.items()]): possib = list(possib) non_zero_...
Title: Bus Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the loses...
```python from collections import Counter from itertools import product s = input() ds = Counter(s) fac = [1 for i in range(100)] for i in range(1, 100): fac[i] = fac[i-1] * i res = 0 for possib in product(*[zip([k] * n, range(1, n+1)) for k, n in ds.items()]): possib = list(possib) ...
3
416
B
Art Union
PROGRAMMING
1,300
[ "brute force", "dp", "implementation" ]
null
null
A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of *n* painters who decided to organize their work as follows. Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color...
The first line of the input contains integers *m*,<=*n* (1<=≤<=*m*<=≤<=50000,<=1<=≤<=*n*<=≤<=5), where *m* is the number of pictures and *n* is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains *n* integers *t**i*1,<=*t**i*2,<=...,<=*t**in* (1<=≤<=*t**ij*<=≤<=1000), ...
Print the sequence of *m* integers *r*1,<=*r*2,<=...,<=*r**m*, where *r**i* is the moment when the *n*-th painter stopped working on the *i*-th picture.
[ "5 1\n1\n2\n3\n4\n5\n", "4 2\n2 5\n3 1\n5 3\n10 1\n" ]
[ "1 3 6 10 15 ", "7 8 13 21 " ]
none
1,000
[ { "input": "5 1\n1\n2\n3\n4\n5", "output": "1 3 6 10 15 " }, { "input": "4 2\n2 5\n3 1\n5 3\n10 1", "output": "7 8 13 21 " }, { "input": "1 1\n66", "output": "66 " }, { "input": "2 2\n1 1\n1 1", "output": "2 3 " }, { "input": "2 2\n10 1\n10 1", "output": "11 2...
1,560,295,834
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
num = map(int, raw_input().split()) m = num[0] n = num[1] matriz=[] for i in range(m): lista=[] matriz.append(lista) for i in range(m): valor = map(int, raw_input().split()) for j in range(n): matriz[i].append(valor[j]) for i in range(m): for j in range(n): if ((i == 0 and j ==...
Title: Art Union Time Limit: None seconds Memory Limit: None megabytes Problem Description: A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of *n* painters who decided to organize their work as follows. Each painter uses only the color that was assigned t...
```python num = map(int, raw_input().split()) m = num[0] n = num[1] matriz=[] for i in range(m): lista=[] matriz.append(lista) for i in range(m): valor = map(int, raw_input().split()) for j in range(n): matriz[i].append(valor[j]) for i in range(m): for j in range(n): if ((i == ...
-1
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,656,686,338
2,147,483,647
Python 3
OK
TESTS
79
46
0
(left_handers, right_handers, ambidexters) = map(int, input().split(' ')) if left_handers > right_handers: if left_handers >= right_handers + ambidexters: print((right_handers + ambidexters) * 2) else: print(left_handers * 2 + (right_handers + ambidexters - left_handers)// 2 * 2) elif right_ha...
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 (left_handers, right_handers, ambidexters) = map(int, input().split(' ')) if left_handers > right_handers: if left_handers >= right_handers + ambidexters: print((right_handers + ambidexters) * 2) else: print(left_handers * 2 + (right_handers + ambidexters - left_handers)// 2 * 2) eli...
3
888
B
Buggy Robot
PROGRAMMING
1,000
[ "greedy" ]
null
null
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform: - U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — mo...
The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100). The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R.
Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell.
[ "4\nLDUR\n", "5\nRRRUU\n", "6\nLLRRRR\n" ]
[ "4\n", "0\n", "4\n" ]
none
0
[ { "input": "4\nLDUR", "output": "4" }, { "input": "5\nRRRUU", "output": "0" }, { "input": "6\nLLRRRR", "output": "4" }, { "input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR", "output": "76" }, { "input": "89\nLDL...
1,623,835,260
2,147,483,647
PyPy 3
OK
TESTS
25
109
0
n = int(input()) daf = input() cu = daf.count('U') cd = daf.count('D') cl = daf.count('L') cr = daf.count('R') print((min(cu, cd) + min(cl, cr)) * 2)
Title: Buggy Robot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform: - U — move from the ce...
```python n = int(input()) daf = input() cu = daf.count('U') cd = daf.count('D') cl = daf.count('L') cr = daf.count('R') print((min(cu, cd) + min(cl, cr)) * 2) ```
3
699
A
Launch of Collider
PROGRAMMING
1,000
[ "implementation" ]
null
null
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dis...
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles. The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right....
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen.
[ "4\nRLRL\n2 4 6 10\n", "3\nLLR\n40 50 60\n" ]
[ "1\n", "-1\n" ]
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
500
[ { "input": "4\nRLRL\n2 4 6 10", "output": "1" }, { "input": "3\nLLR\n40 50 60", "output": "-1" }, { "input": "4\nRLLR\n46 230 264 470", "output": "92" }, { "input": "6\nLLRLLL\n446 492 650 844 930 970", "output": "97" }, { "input": "8\nRRLLLLLL\n338 478 512 574 59...
1,595,528,273
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
46
2,000
38,297,600
n = int(input()) s = input() arr = list(map(int, input().split())) mn = float('inf') for i in range(n): if s[i] == 'R': for j in range(i+1, n): if s[j] == 'L': mn = min(mn, arr[j] - arr[i]) break if mn == float('inf'): print(-1) else: pr...
Title: Launch of Collider Time Limit: None seconds Memory Limit: None megabytes Problem Description: There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be...
```python n = int(input()) s = input() arr = list(map(int, input().split())) mn = float('inf') for i in range(n): if s[i] == 'R': for j in range(i+1, n): if s[j] == 'L': mn = min(mn, arr[j] - arr[i]) break if mn == float('inf'): print(-1) els...
0
102
B
Sum of Digits
PROGRAMMING
1,000
[ "implementation" ]
B. Sum of Digits
2
265
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-...
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
[ "0\n", "10\n", "991\n" ]
[ "0\n", "1\n", "3\n" ]
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transform...
1,000
[ { "input": "0", "output": "0" }, { "input": "10", "output": "1" }, { "input": "991", "output": "3" }, { "input": "99", "output": "2" }, { "input": "100", "output": "1" }, { "input": "123456789", "output": "2" }, { "input": "32", "output...
1,683,114,991
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
# 输入数字 print("请输入数字:") n = input() number = int(n) if len(n) == 1: print(n) else: if 0 <= number <= 10 ** 100000 and n[0] != '0': while len(n) > 1: numsum = sum(int(num) for num in n) n = str(numsum) print(n) else: print("请输入在0到10的十万次方且不包含任何前导零的数字") n ...
Title: Sum of Digits Time Limit: 2 seconds Memory Limit: 265 megabytes Problem Description: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came...
```python # 输入数字 print("请输入数字:") n = input() number = int(n) if len(n) == 1: print(n) else: if 0 <= number <= 10 ** 100000 and n[0] != '0': while len(n) > 1: numsum = sum(int(num) for num in n) n = str(numsum) print(n) else: print("请输入在0到10的十万次方且不包含任何前导零的数字") ...
-1
877
B
Nikita and string
PROGRAMMING
1,500
[ "brute force", "dp" ]
null
null
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b".
Print a single integer — the maximum possible size of beautiful string Nikita can get.
[ "abba\n", "bab\n" ]
[ "4", "2" ]
It the first sample the string is already beautiful. In the second sample he needs to delete one of "b" to make it beautiful.
1,000
[ { "input": "abba", "output": "4" }, { "input": "bab", "output": "2" }, { "input": "bbabbbaabbbb", "output": "9" }, { "input": "bbabbbbbaaba", "output": "10" }, { "input": "bbabbbababaa", "output": "9" }, { "input": "aabbaababbab", "output": "8" }...
1,644,242,372
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
s=input() p=[[0,0]] o=0 ans=-float("inf") u=0 for ch in s: p.append(p[-1][:]) if ch=="a": p[-1][0]+=1 o+=1 else : p[-1][1]+=1 u+=1 for i in range(len(s)-1): for j in range(i+1,len(s)+1): a=p[i+1][0] b=p[j][1]-p[i+1][1] c=o-p[j][0] ...
Title: Nikita and string Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st ...
```python s=input() p=[[0,0]] o=0 ans=-float("inf") u=0 for ch in s: p.append(p[-1][:]) if ch=="a": p[-1][0]+=1 o+=1 else : p[-1][1]+=1 u+=1 for i in range(len(s)-1): for j in range(i+1,len(s)+1): a=p[i+1][0] b=p[j][1]-p[i+1][1] c=...
0
620
B
Grandfather Dovlet’s calculator
PROGRAMMING
1,000
[ "implementation" ]
null
null
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)). Max starts to type all the values from *a* to *b*. After typi...
The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max.
Print the only integer *a* — the total number of printed segments.
[ "1 3\n", "10 15\n" ]
[ "12\n", "39\n" ]
none
0
[ { "input": "1 3", "output": "12" }, { "input": "10 15", "output": "39" }, { "input": "1 100", "output": "928" }, { "input": "100 10000", "output": "188446" }, { "input": "213 221442", "output": "5645356" }, { "input": "1 1000000", "output": "287333...
1,561,094,947
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
0
A={'0':6,'1':2,'2':5,'3':5,'4':4,'5':5,'6':6,'7':3,'8':7,'9':6} count = 0 a,b=list(map(int,input().split())) for val in range(a,b+1): Str=str(val) for v in Str: count += A[v] print(count)
Title: Grandfather Dovlet’s calculator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](...
```python A={'0':6,'1':2,'2':5,'3':5,'4':4,'5':5,'6':6,'7':3,'8':7,'9':6} count = 0 a,b=list(map(int,input().split())) for val in range(a,b+1): Str=str(val) for v in Str: count += A[v] print(count) ```
0
8
A
Train and Peter
PROGRAMMING
1,200
[ "strings" ]
A. Train and Peter
1
64
Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour. The boy start...
The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order. The second lin...
Output one of the four words without inverted commas: - «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fanta...
[ "atob\na\nb\n", "aaacaaa\naca\naa\n" ]
[ "forward\n", "both\n" ]
It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.
0
[ { "input": "atob\na\nb", "output": "forward" }, { "input": "aaacaaa\naca\naa", "output": "both" }, { "input": "aaa\naa\naa", "output": "fantasy" }, { "input": "astalavista\nastla\nlavista", "output": "fantasy" }, { "input": "abacabadabacaba\nabacaba\nabacaba", ...
1,659,247,949
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
t1=input() s1=input() s2=input() t1=t1[::-1] ans=0 k1=t1.find() if k1!=-1: k2=t1.find(s2,k1+len(t1)) if k2!=0:ans+=1 if ans==1:print('forward') elif ans==2:print('backward') elif ans==3:print('both') else:print('fantasy')
Title: Train and Peter Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the...
```python t1=input() s1=input() s2=input() t1=t1[::-1] ans=0 k1=t1.find() if k1!=-1: k2=t1.find(s2,k1+len(t1)) if k2!=0:ans+=1 if ans==1:print('forward') elif ans==2:print('backward') elif ans==3:print('both') else:print('fantasy') ```
-1
926
C
Is This a Zebra?
PROGRAMMING
1,700
[ "implementation" ]
null
null
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of *n* pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of *n* zeros and ones, where 0 means that the corresponding column is all white, and 1 m...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the width of the photo. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=1) — the description of the photo. If *a**i* is zero, the *i*-th column is all black. If *a**i* is one, then the *i*-th column is ...
If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower).
[ "9\n0 0 0 1 1 1 0 0 0\n", "7\n0 0 0 1 1 1 1\n", "5\n1 1 1 1 1\n", "8\n1 1 1 0 0 0 1 1\n", "9\n1 1 0 1 1 0 1 1 0\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n", "NO\n" ]
The first two examples are described in the statements. In the third example all pixels are white, so the photo can be a photo of zebra. In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is e...
0
[ { "input": "9\n0 0 0 1 1 1 0 0 0", "output": "YES" }, { "input": "7\n0 0 0 1 1 1 1", "output": "NO" }, { "input": "5\n1 1 1 1 1", "output": "YES" }, { "input": "8\n1 1 1 0 0 0 1 1", "output": "NO" }, { "input": "9\n1 1 0 1 1 0 1 1 0", "output": "NO" }, { ...
1,521,359,278
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
7,065,600
n = input() b = map(eval, raw_input().split(" ")) c = [1] for i in range(1, n): if (b[i] == b[i-1]): c[-1] += 1 else : c.append(1) for i in range(1, len(c)) : if (c[i] != c[i-1]) : print("NO") exit() print("YES")
Title: Is This a Zebra? Time Limit: None seconds Memory Limit: None megabytes Problem Description: A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of *n* pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo ...
```python n = input() b = map(eval, raw_input().split(" ")) c = [1] for i in range(1, n): if (b[i] == b[i-1]): c[-1] += 1 else : c.append(1) for i in range(1, len(c)) : if (c[i] != c[i-1]) : print("NO") exit() print("YES") ```
-1
868
A
Bark to Unlock
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters. Mu-mu's enemy Kashtanka wants to unlock Mu-mu's p...
The first line contains two lowercase English letters — the password on the phone. The second line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of words Kashtanka knows. The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to b...
Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "ya\n4\nah\noy\nto\nha\n", "hp\n2\nht\ntp\n", "ah\n1\nha\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES". In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" produ...
250
[ { "input": "ya\n4\nah\noy\nto\nha", "output": "YES" }, { "input": "hp\n2\nht\ntp", "output": "NO" }, { "input": "ah\n1\nha", "output": "YES" }, { "input": "bb\n4\nba\nab\naa\nbb", "output": "YES" }, { "input": "bc\n4\nca\nba\nbb\ncc", "output": "YES" }, { ...
1,601,374,805
2,147,483,647
PyPy 3
OK
TESTS
90
156
0
s = input() n = int(input()) words = [input() for word in range(n)] ans = 'NO' if s in words: ans = 'YES' start, end = False, False for word in words: if word[0] == s[1]: start = True if word[1] == s[0]: end = True if start and end: break if start and end: ans ...
Title: Bark to Unlock Time Limit: None seconds Memory Limit: None megabytes Problem Description: As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a passw...
```python s = input() n = int(input()) words = [input() for word in range(n)] ans = 'NO' if s in words: ans = 'YES' start, end = False, False for word in words: if word[0] == s[1]: start = True if word[1] == s[0]: end = True if start and end: break if start and end:...
3
616
D
Longest k-Good Segment
PROGRAMMING
1,600
[ "binary search", "data structures", "two pointers" ]
null
null
The array *a* with *n* integers is given. Let's call the sequence of one or more consecutive elements in *a* segment. Also let's call the segment k-good if it contains no more than *k* different values. Find any longest k-good segment. As the input/output can reach huge size it is recommended to use fast input/output...
The first line contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=5·105) — the number of elements in *a* and the parameter *k*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=106) — the elements of the array *a*.
Print two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in *a* are numbered from 1 to *n* from left to right.
[ "5 5\n1 2 3 4 5\n", "9 3\n6 5 1 2 3 2 1 4 5\n", "3 1\n1 2 3\n" ]
[ "1 5\n", "3 7\n", "1 1\n" ]
none
0
[ { "input": "5 5\n1 2 3 4 5", "output": "1 5" }, { "input": "9 3\n6 5 1 2 3 2 1 4 5", "output": "3 7" }, { "input": "3 1\n1 2 3", "output": "1 1" }, { "input": "1 1\n747391", "output": "1 1" }, { "input": "5 2\n171230 171230 171230 171230 171230", "output": "1 ...
1,654,234,478
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
12
1,000
35,737,600
n,k = map(int, input().split()) A = list(map(int, input().split())) from collections import Counter j = 0 S = set() C = Counter() ans = 0 l, r = -1, -1 for i in range(n): while j < n and len(S|{A[j]}) <= k: S.add(A[j]) C[A[j]] += 1 j += 1 if j-i > ans: ans = j-i...
Title: Longest k-Good Segment Time Limit: None seconds Memory Limit: None megabytes Problem Description: The array *a* with *n* integers is given. Let's call the sequence of one or more consecutive elements in *a* segment. Also let's call the segment k-good if it contains no more than *k* different values. Find any...
```python n,k = map(int, input().split()) A = list(map(int, input().split())) from collections import Counter j = 0 S = set() C = Counter() ans = 0 l, r = -1, -1 for i in range(n): while j < n and len(S|{A[j]}) <= k: S.add(A[j]) C[A[j]] += 1 j += 1 if j-i > ans: ...
0
465
B
Inbox (100500)
PROGRAMMING
1,000
[ "implementation" ]
null
null
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread. Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox. The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read.
Print a single number — the minimum number of operations needed to make all the letters read.
[ "5\n0 1 0 1 0\n", "5\n1 1 0 0 1\n", "2\n0 0\n" ]
[ "3\n", "4\n", "0\n" ]
In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one. In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter. In the third sample all letters are already...
1,000
[ { "input": "5\n0 1 0 1 0", "output": "3" }, { "input": "5\n1 1 0 0 1", "output": "4" }, { "input": "2\n0 0", "output": "0" }, { "input": "9\n1 0 1 0 1 0 1 0 1", "output": "9" }, { "input": "5\n1 1 1 1 1", "output": "5" }, { "input": "14\n0 0 1 1 1 0 1 ...
1,642,587,581
2,147,483,647
PyPy 3-64
OK
TESTS
44
109
0
n = int(input()) mails = input() if mails.count('1') == 0: print(0) else: res = 0 mails = [x for x in mails.split('0') if x.count('1') >= 1] for i in mails: res += i.count('1') print(res + len(mails) - 1)
Title: Inbox (100500) Time Limit: None seconds Memory Limit: None megabytes Problem Description: Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread. Alexey's mail program can either show a list of all letters or show the content of a single letter. As soo...
```python n = int(input()) mails = input() if mails.count('1') == 0: print(0) else: res = 0 mails = [x for x in mails.split('0') if x.count('1') >= 1] for i in mails: res += i.count('1') print(res + len(mails) - 1) ```
3
936
A
Save Energy!
PROGRAMMING
1,700
[ "binary search", "implementation", "math" ]
null
null
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after *k* minutes after turning on. During cooking, Julia goes to the kitchen every *d* minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. T...
The single line contains three integers *k*, *d* and *t* (1<=≤<=*k*,<=*d*,<=*t*<=≤<=1018).
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10<=-<=9. Namely, let's assume that your answer is *x* and the answer of the jury is *y*. The checker program will consider your answer correct if .
[ "3 2 6\n", "4 2 20\n" ]
[ "6.5\n", "20.0\n" ]
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cce5d3f2f46552034d5ae5d487725705429ec7a5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Then the chicken will be coo...
500
[ { "input": "3 2 6", "output": "6.5" }, { "input": "4 2 20", "output": "20.0" }, { "input": "8 10 9", "output": "10.0" }, { "input": "43 50 140", "output": "150.5" }, { "input": "251 79 76", "output": "76.0" }, { "input": "892 67 1000", "output": "1...
1,555,775,928
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
109
0
a,b,c=map(int,input().split()) ans=0 r=a%b+a ws=a%b*1.5+a aa=c//r ans+=ws*aa c-=aa*r yhn=min(c,a) ans+=yhn c-=yhn yhn=min(c,a%b) c=0 ans+=yhn print(ans)
Title: Save Energy! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after *k* minutes after turning on. During cooking, Julia goes to the kitchen every *d* mi...
```python a,b,c=map(int,input().split()) ans=0 r=a%b+a ws=a%b*1.5+a aa=c//r ans+=ws*aa c-=aa*r yhn=min(c,a) ans+=yhn c-=yhn yhn=min(c,a%b) c=0 ans+=yhn print(ans) ```
0
888
C
K-Dominant Character
PROGRAMMING
1,400
[ "binary search", "implementation", "two pointers" ]
null
null
You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*. You have to find minimum *k* such that there exists at least one *k*-dominant character.
The first line contains string *s* consisting of lowercase Latin letters (1<=≤<=|*s*|<=≤<=100000).
Print one number — the minimum value of *k* such that there exists at least one *k*-dominant character.
[ "abacaba\n", "zzzzz\n", "abcde\n" ]
[ "2\n", "1\n", "3\n" ]
none
0
[ { "input": "abacaba", "output": "2" }, { "input": "zzzzz", "output": "1" }, { "input": "abcde", "output": "3" }, { "input": "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab", "output": "8" }, { "input": "daabcdabbab...
1,610,218,569
2,147,483,647
PyPy 3
OK
TESTS
51
170
3,276,800
import string from collections import defaultdict s=input() window=defaultdict(list) character_set=string.ascii_lowercase n,ans=len(s),len(s) for idx,char in enumerate(character_set): prev=-1 consider=-10**9-7 for jdx,x in enumerate(s): if x==char: consider=max(consider,jdx-pr...
Title: K-Dominant Character Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*. You have to find minimum *k* s...
```python import string from collections import defaultdict s=input() window=defaultdict(list) character_set=string.ascii_lowercase n,ans=len(s),len(s) for idx,char in enumerate(character_set): prev=-1 consider=-10**9-7 for jdx,x in enumerate(s): if x==char: consider=max(consi...
3
459
B
Pashmak and Flowers
PROGRAMMING
1,300
[ "combinatorics", "implementation", "sortings" ]
null
null
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty diff...
The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
[ "2\n1 2\n", "3\n1 4 5\n", "5\n3 1 2 3 1\n" ]
[ "1 1", "4 1", "2 4" ]
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
500
[ { "input": "2\n1 2", "output": "1 1" }, { "input": "3\n1 4 5", "output": "4 1" }, { "input": "5\n3 1 2 3 1", "output": "2 4" }, { "input": "2\n1 1", "output": "0 1" }, { "input": "3\n1 1 1", "output": "0 3" }, { "input": "4\n1 1 1 1", "output": "0 ...
1,696,585,910
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
26,521,600
import math from sys import stdin stream = None try: stream = open('file.txt', 'r') except: stream = stdin n = int(stream.readline()) n_arr = [int(i) for i in stream.readline().split()] def ncr(n, r): f = math.factorial return f(n) // f(r) // f(n - r) minn = min(n_arr) maxn = max(n_arr) comb = (n_...
Title: Pashmak and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have th...
```python import math from sys import stdin stream = None try: stream = open('file.txt', 'r') except: stream = stdin n = int(stream.readline()) n_arr = [int(i) for i in stream.readline().split()] def ncr(n, r): f = math.factorial return f(n) // f(r) // f(n - r) minn = min(n_arr) maxn = max(n_arr) ...
0
710
B
Optimal Point on a Line
PROGRAMMING
1,400
[ "brute force", "sortings" ]
null
null
You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal.
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line. The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points.
Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
[ "4\n1 2 3 4\n" ]
[ "2\n" ]
none
0
[ { "input": "4\n1 2 3 4", "output": "2" }, { "input": "5\n-1 -10 2 6 7", "output": "2" }, { "input": "10\n-68 10 87 22 30 89 82 -97 -52 25", "output": "22" }, { "input": "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -...
1,621,150,310
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> #define ll long long int using namespace std; int main() { ll n;cin>>n; double x,total=0; for(ll i=0;i<n;i++){ cin>>x;total+=x; } double y = (double)total/n; ll z = total/n; //cout<<y-z<<endl; if(y>0){ if(y-z<=0.5){ cout<<z<<endl; ...
Title: Optimal Point on a Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=...
```python #include <bits/stdc++.h> #define ll long long int using namespace std; int main() { ll n;cin>>n; double x,total=0; for(ll i=0;i<n;i++){ cin>>x;total+=x; } double y = (double)total/n; ll z = total/n; //cout<<y-z<<endl; if(y>0){ if(y-z<=0.5){ cout<<z<...
-1
921
05
Labyrinth-5
PROGRAMMING
3,200
[]
null
null
See the problem statement here: [http://codeforces.com/contest/921/problem/01](//codeforces.com/contest/921/problem/01).
none
none
[]
[]
none
83.362
[]
1,517,503,936
3,136
Python 3
PARTIAL
TESTS
1
46
5,529,600
ans = """ for-350 for-351 move-down move-right move-up move-right end move-down move-down for-351 move-left move-down move-left move-up end move-down move-down end """ print(ans)
Title: Labyrinth-5 Time Limit: None seconds Memory Limit: None megabytes Problem Description: See the problem statement here: [http://codeforces.com/contest/921/problem/01](//codeforces.com/contest/921/problem/01). Input Specification: none Output Specification: none Note: none
```python ans = """ for-350 for-351 move-down move-right move-up move-right end move-down move-down for-351 move-left move-down move-left move-up end move-down move-down end """ print(ans) ```
2
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they...
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "...
1,675,411,633
2,147,483,647
Python 3
OK
TESTS
48
46
0
z = list(map(int, input().split())) print( max(z) - min(z))
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ...
```python z = list(map(int, input().split())) print( max(z) - min(z)) ```
3
877
A
Alex and broken contest
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest ...
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.
Print "YES", if problem is from this contest, and "NO" otherwise.
[ "Alex_and_broken_contest\n", "NikitaAndString\n", "Danil_and_Olya\n" ]
[ "NO", "YES", "NO" ]
none
500
[ { "input": "Alex_and_broken_contest", "output": "NO" }, { "input": "NikitaAndString", "output": "YES" }, { "input": "Danil_and_Olya", "output": "NO" }, { "input": "Slava____and_the_game", "output": "YES" }, { "input": "Olya_and_energy_drinks", "output": "YES" ...
1,611,095,798
398
PyPy 3
OK
TESTS
55
108
0
s = str(input()) c = 0 c += s.count('Danil') c += s.count('Olya') c += s.count('Slava') c += s.count('Ann') c += s.count('Nikita') if c == 1: print('YES') else: print('NO')
Title: Alex and broken contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems,...
```python s = str(input()) c = 0 c += s.count('Danil') c += s.count('Olya') c += s.count('Slava') c += s.count('Ann') c += s.count('Nikita') if c == 1: print('YES') else: print('NO') ```
3
110
A
Nearly Lucky Number
PROGRAMMING
800
[ "implementation" ]
A. Nearly Lucky Number
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
500
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { ...
1,694,661,032
2,147,483,647
Python 3
OK
TESTS
34
92
0
# -*- coding: utf-8 -*- """ Created on Thu Sep 14 11:07:49 2023 @author: ljy """ n=input() luc=0 for i in range(len(n)): if n[i]=='4' or n[i]=='7': luc+=1 #print(luc) if luc==4 or luc==7: print('YES') else:print('NO')
Title: Nearly Lucky Number Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python # -*- coding: utf-8 -*- """ Created on Thu Sep 14 11:07:49 2023 @author: ljy """ n=input() luc=0 for i in range(len(n)): if n[i]=='4' or n[i]=='7': luc+=1 #print(luc) if luc==4 or luc==7: print('YES') else:print('NO') ```
3.977
122
A
Lucky Division
PROGRAMMING
1,000
[ "brute force", "number theory" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ...
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
[ "47\n", "16\n", "78\n" ]
[ "YES\n", "YES\n", "NO\n" ]
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
500
[ { "input": "47", "output": "YES" }, { "input": "16", "output": "YES" }, { "input": "78", "output": "NO" }, { "input": "48", "output": "YES" }, { "input": "100", "output": "YES" }, { "input": "107", "output": "NO" }, { "input": "77", "ou...
1,693,062,555
2,147,483,647
Python 3
OK
TESTS
36
92
0
n=(input()) x=1 for i in range(len(n)): if n[i]=='4': x=x elif n[i]=='7': x=x else: x=0 if int(n)%4==0 or int(n)%7==0 or int(n)%44==0 or int(n)%47==0 or int(n)%74==0 or int(n)%77==0 or int(n)%444==0 or int(n)%777==0 or int(n)%447==0 or int(n)%474==0 or int(n)%747==0 or int(...
Title: Lucky Division Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python n=(input()) x=1 for i in range(len(n)): if n[i]=='4': x=x elif n[i]=='7': x=x else: x=0 if int(n)%4==0 or int(n)%7==0 or int(n)%44==0 or int(n)%47==0 or int(n)%74==0 or int(n)%77==0 or int(n)%444==0 or int(n)%777==0 or int(n)%447==0 or int(n)%474==0 or int(n)%747=...
3
764
B
Timofey and cubes
PROGRAMMING
900
[ "constructive algorithms", "implementation" ]
null
null
Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Sup...
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order.
Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique.
[ "7\n4 3 7 6 9 1 2\n", "8\n6 1 4 2 5 6 9 2\n" ]
[ "2 3 9 6 7 1 4", "2 1 6 2 5 4 9 6" ]
Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing ha...
1,000
[ { "input": "7\n4 3 7 6 9 1 2", "output": "2 3 9 6 7 1 4" }, { "input": "8\n6 1 4 2 5 6 9 2", "output": "2 1 6 2 5 4 9 6" }, { "input": "1\n1424", "output": "1424" }, { "input": "9\n-7 9 -4 9 -6 11 15 2 -10", "output": "-10 9 15 9 -6 11 -4 2 -7" }, { "input": "2\n2...
1,620,211,967
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
204,800
n=int(input()) a=list(map(int,input().split())) out="" if(n%2!=0): out=str(a[n//2]) # print(out) for i in range((n//2)-1,-1,-1): if(i%2==0): out=str(a[-i-1])+out+str(a[i]) else: out=str(a[i])+out+str(a[-i-1]) # print(out) print(" ".join(out))
Title: Timofey and cubes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other p...
```python n=int(input()) a=list(map(int,input().split())) out="" if(n%2!=0): out=str(a[n//2]) # print(out) for i in range((n//2)-1,-1,-1): if(i%2==0): out=str(a[-i-1])+out+str(a[i]) else: out=str(a[i])+out+str(a[-i-1]) # print(out) print(" ".join(out)) ```
0
112
A
Petya and Strings
PROGRAMMING
800
[ "implementation", "strings" ]
A. Petya and Strings
2
256
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr...
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
[ "aaaa\naaaA\n", "abs\nAbz\n", "abcdefg\nAbCdEfF\n" ]
[ "0\n", "-1\n", "1\n" ]
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
500
[ { "input": "aaaa\naaaA", "output": "0" }, { "input": "abs\nAbz", "output": "-1" }, { "input": "abcdefg\nAbCdEfF", "output": "1" }, { "input": "asadasdasd\nasdwasdawd", "output": "-1" }, { "input": "aslkjlkasdd\nasdlkjdajwi", "output": "1" }, { "input":...
1,698,596,729
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
def draw_st(text1, text2): if text1 == text2: return 0 elif text1 > text2: return 1 else: return -1 text1 = input().lower() text2 = input().lower result = draw_st(text1, text2) print(result)
Title: Petya and Strings Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ...
```python def draw_st(text1, text2): if text1 == text2: return 0 elif text1 > text2: return 1 else: return -1 text1 = input().lower() text2 = input().lower result = draw_st(text1, text2) print(result) ```
-1
233
A
Perfect Permutation
PROGRAMMING
800
[ "implementation", "math" ]
null
null
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He lik...
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
[ "1\n", "2\n", "4\n" ]
[ "-1\n", "2 1 \n", "2 1 4 3 \n" ]
none
500
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "2 1 " }, { "input": "4", "output": "2 1 4 3 " }, { "input": "3", "output": "-1" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "2 1 4 3 6 5 " }, { "input": "7", ...
1,692,251,617
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
156
0
n=int(input()) if n%2>0: print(-1) v=1 nn=n//2 for i in range(nn): print(v+1,end=" ") print(v,end=" ") v+=1
Title: Perfect Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ...
```python n=int(input()) if n%2>0: print(-1) v=1 nn=n//2 for i in range(nn): print(v+1,end=" ") print(v,end=" ") v+=1 ```
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,678,920,868
2,147,483,647
Python 3
OK
TESTS
32
92
0
##nums = map(int, input().split()) ##s1 = list(map(int, input().split())) ##s1 = list(map(int, ' '.join(input()).split())) n = int(input()) s = list(map(int, input().split())) ch = Nch = nch = Nnch = 0 for i in range(len(s)): if s[i]%2 == 0: ch +=1 Nch = i + 1 else: nch += 1...
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python ##nums = map(int, input().split()) ##s1 = list(map(int, input().split())) ##s1 = list(map(int, ' '.join(input()).split())) n = int(input()) s = list(map(int, input().split())) ch = Nch = nch = Nnch = 0 for i in range(len(s)): if s[i]%2 == 0: ch +=1 Nch = i + 1 else: ...
3.977
451
A
Game With Sticks
PROGRAMMING
900
[ "implementation" ]
null
null
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid show...
The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game.
[ "2 2\n", "2 3\n", "3 3\n" ]
[ "Malvika\n", "Malvika\n", "Akshat\n" ]
Explanation of the first sample: The grid has four intersection points, numbered from 1 to 4. If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this. Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remov...
500
[ { "input": "2 2", "output": "Malvika" }, { "input": "2 3", "output": "Malvika" }, { "input": "3 3", "output": "Akshat" }, { "input": "20 68", "output": "Malvika" }, { "input": "1 1", "output": "Akshat" }, { "input": "1 2", "output": "Akshat" }, ...
1,683,377,776
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
31
0
def f(): L=[] p1="Akshat" p2="Malvika" n,m=list(map(int,input().split())) if n==m: if n%2==0: print(p2) else: print(p1) elif min(n,m)%2==0: print(p2) f()
Title: Game With Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid...
```python def f(): L=[] p1="Akshat" p2="Malvika" n,m=list(map(int,input().split())) if n==m: if n%2==0: print(p2) else: print(p1) elif min(n,m)%2==0: print(p2) f() ```
0
873
B
Balanced Substring
PROGRAMMING
1,500
[ "dp", "implementation" ]
null
null
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring. You have to deter...
The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*. The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*.
If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring.
[ "8\n11010111\n", "3\n111\n" ]
[ "4\n", "0\n" ]
In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible. In the second example it's impossible to find a non-empty balanced substring.
0
[ { "input": "8\n11010111", "output": "4" }, { "input": "3\n111", "output": "0" }, { "input": "11\n00001000100", "output": "2" }, { "input": "10\n0100000000", "output": "2" }, { "input": "13\n0001000011010", "output": "6" }, { "input": "14\n0000010010101...
1,508,501,237
2,147,483,647
Python 3
OK
TESTS
53
124
14,131,200
n = input() s = input() res = 0 ans = 0 dp = {} dp[0] = -1 for i in range(int(n)): if s[i] == '1': res += 1 else: res -= 1 if res not in dp: dp[res] = i else: ans = max(ans, i - dp[res]) print(ans)
Title: Balanced Substring Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called...
```python n = input() s = input() res = 0 ans = 0 dp = {} dp[0] = -1 for i in range(int(n)): if s[i] == '1': res += 1 else: res -= 1 if res not in dp: dp[res] = i else: ans = max(ans, i - dp[res]) print(ans) ```
3
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character...
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "...
1,691,609,427
2,147,483,647
PyPy 3-64
OK
TESTS
44
62
0
s=input() start="a" x=0 for i in s: x=x+min(abs(ord(start)-ord(i)),26-abs(ord(start)-ord(i))) start=i print(x)
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devis...
```python s=input() start="a" x=0 for i in s: x=x+min(abs(ord(start)-ord(i)),26-abs(ord(start)-ord(i))) start=i print(x) ```
3
268
B
Buttons
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the seque...
A single line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of buttons the lock has.
In a single line print the number of times Manao has to push a button in the worst-case scenario.
[ "2\n", "3\n" ]
[ "3\n", "7\n" ]
Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes.
1,000
[ { "input": "2", "output": "3" }, { "input": "3", "output": "7" }, { "input": "4", "output": "14" }, { "input": "1", "output": "1" }, { "input": "10", "output": "175" }, { "input": "2000", "output": "1333335000" }, { "input": "1747", "ou...
1,674,858,006
2,147,483,647
Python 3
OK
TESTS
24
92
0
n = int(input()) ans = 0 counter = n-1 for i in range (1, n): ans += (i * counter) counter -= 1 ans += n print(ans)
Title: Buttons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the loc...
```python n = int(input()) ans = 0 counter = n-1 for i in range (1, n): ans += (i * counter) counter -= 1 ans += n print(ans) ```
3
676
C
Vasya and String
PROGRAMMING
1,500
[ "binary search", "dp", "strings", "two pointers" ]
null
null
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than *k* characters of the original strin...
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only.
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters.
[ "4 2\nabba\n", "8 1\naabaabaa\n" ]
[ "4\n", "5\n" ]
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
1,500
[ { "input": "4 2\nabba", "output": "4" }, { "input": "8 1\naabaabaa", "output": "5" }, { "input": "1 0\na", "output": "1" }, { "input": "1 1\nb", "output": "1" }, { "input": "1 0\nb", "output": "1" }, { "input": "1 1\na", "output": "1" }, { ...
1,692,179,201
2,147,483,647
Python 3
OK
TESTS
117
93
102,400
def max_beauty_string(n, k, s): max_beauty = 0 window_start = 0 a_count = 0 b_count = 0 for window_end in range(n): if s[window_end] == 'a': a_count += 1 else: b_count += 1 # Check if we need to shrink the window while min(a_count, b_count) >...
Title: Vasya and String Time Limit: None seconds Memory Limit: None megabytes Problem Description: High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequ...
```python def max_beauty_string(n, k, s): max_beauty = 0 window_start = 0 a_count = 0 b_count = 0 for window_end in range(n): if s[window_end] == 'a': a_count += 1 else: b_count += 1 # Check if we need to shrink the window while min(a_count, ...
3
653
A
Bear and Three Balls
PROGRAMMING
900
[ "brute force", "implementation", "sortings" ]
null
null
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: - No two friends can get balls of the same size. - No two friends can get balls of sizes th...
The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball.
Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes).
[ "4\n18 55 16 17\n", "6\n40 41 43 44 44 44\n", "8\n5 972 3 4 1 4 970 971\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17. In the second sample, there is no way to give gifts to three friends without breaking the rules. In the third sample, there is even more than one way to choose bal...
500
[ { "input": "4\n18 55 16 17", "output": "YES" }, { "input": "6\n40 41 43 44 44 44", "output": "NO" }, { "input": "8\n5 972 3 4 1 4 970 971", "output": "YES" }, { "input": "3\n959 747 656", "output": "NO" }, { "input": "4\n1 2 2 3", "output": "YES" }, { ...
1,680,589,564
2,147,483,647
Python 3
OK
TESTS
84
46
0
# take input values N = int(input()) T = list(map(int, input().split())) # remove duplicate house numbers and sort the list T = sorted(set(T)) # iterate over the sorted list and check for three consecutive houses for i in range(len(T)-2): if T[i+2] - T[i] <= 2: print("YES") exit() # if we can't f...
Title: Bear and Three Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make fri...
```python # take input values N = int(input()) T = list(map(int, input().split())) # remove duplicate house numbers and sort the list T = sorted(set(T)) # iterate over the sorted list and check for three consecutive houses for i in range(len(T)-2): if T[i+2] - T[i] <= 2: print("YES") exit() # if ...
3
639
C
Bear and Polynomials
PROGRAMMING
2,200
[ "hashing", "implementation", "math" ]
null
null
Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials. He considers a polynomial valid if its degree is *n* and its coefficients are integers not exceeding *k* by the absolute value. More formally: Let *a*0,<=*a*1,<=...,<=*a**n* denote the coefficients, so . Then, a polynomi...
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200<=000,<=1<=≤<=*k*<=≤<=109) — the degree of the polynomial and the limit for absolute values of coefficients. The second line contains *n*<=+<=1 integers *a*0,<=*a*1,<=...,<=*a**n* (|*a**i*|<=≤<=*k*,<=*a**n*<=≠<=0) — describing a valid polynomial . It's...
Print the number of ways to change one coefficient to get a valid polynomial *Q* that *Q*(2)<==<=0.
[ "3 1000000000\n10 -9 -3 5\n", "3 12\n10 -9 -3 5\n", "2 20\n14 -7 19\n" ]
[ "3\n", "2\n", "0\n" ]
In the first sample, we are given a polynomial *P*(*x*) = 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup>. Limak can change one coefficient in three ways: 1. He can set *a*<sub class="lower-index">0</sub> =  - 10. Then he would get *Q*(*x*) =  - 10 - 9*x* - 3*x*<sup class="upp...
1,000
[ { "input": "3 1000000000\n10 -9 -3 5", "output": "3" }, { "input": "3 12\n10 -9 -3 5", "output": "2" }, { "input": "2 20\n14 -7 19", "output": "0" }, { "input": "5 5\n0 -4 -2 -2 0 5", "output": "1" }, { "input": "6 10\n-2 -1 7 -3 2 7 -6", "output": "2" }, ...
1,465,131,665
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
4,915,200
def convert_to_binary(coef): res = [] n = len(coef) carry = 0 i = 0 while i < n + 1000: if i >= n and not carry: break cur = carry if i < n: cur += coef[i] mod = cur % 2 div = cur // 2 # print(cur, div, mod) res.appe...
Title: Bear and Polynomials Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials. He considers a polynomial valid if its degree is *n* and its coefficients are integers not exceeding *k* by the abs...
```python def convert_to_binary(coef): res = [] n = len(coef) carry = 0 i = 0 while i < n + 1000: if i >= n and not carry: break cur = carry if i < n: cur += coef[i] mod = cur % 2 div = cur // 2 # print(cur, div, mod) ...
0
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,686,000,716
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
31
0
# n = [int(x) for x in input().split(' ')][0] n = int(input()) # x = [x for x in input().split(' ')] x = input() print(n) print(x) max_left = 0 while max_left < n and x[max_left] == '<': max_left += 1 max_right = 0 while x[n - max_right - 1] == '>' and max_right < n - max_left: max_right += 1 print(max_l...
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 # n = [int(x) for x in input().split(' ')][0] n = int(input()) # x = [x for x in input().split(' ')] x = input() print(n) print(x) max_left = 0 while max_left < n and x[max_left] == '<': max_left += 1 max_right = 0 while x[n - max_right - 1] == '>' and max_right < n - max_left: max_right += 1 p...
0
898
A
Rounding
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which int...
The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has.
Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
[ "5\n", "113\n", "1000000000\n", "5432359\n" ]
[ "0\n", "110\n", "1000000000\n", "5432360\n" ]
In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
500
[ { "input": "5", "output": "0" }, { "input": "113", "output": "110" }, { "input": "1000000000", "output": "1000000000" }, { "input": "5432359", "output": "5432360" }, { "input": "999999994", "output": "999999990" }, { "input": "10", "output": "10" ...
1,584,673,500
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
16
109
512,000
n = input() if len(n)==1: if int(n)>5: print("10") elif int(n)<=5: print("0") elif len(n)>1: if n[len(n)-1]=="0": print(n) elif int(n[len(n)-1])>5: a = int(n[len(n)-2])+1 print(n[0:len(n)-2]+str(a)+"0") elif int(n[len(n)-1])<=5: print(n[0:len(n)-1]+"0")
Title: Rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5...
```python n = input() if len(n)==1: if int(n)>5: print("10") elif int(n)<=5: print("0") elif len(n)>1: if n[len(n)-1]=="0": print(n) elif int(n[len(n)-1])>5: a = int(n[len(n)-2])+1 print(n[0:len(n)-2]+str(a)+"0") elif int(n[len(n)-1])<=5: print(n[0:len(n)-1]+"0") ```
0