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
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,575,700,071
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n=input() l=[] for i in range(0,len(n)): if n[i]=="h" || n[i]=="e" || n[i]=="l" || n[i]=="o": l.add(i); l=sorted(l) ans="" for i in range(0,len(l)): if i not in ans: ans=ans+n[i] if(ans=="hello"): print("Yes") else: print("No"
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python n=input() l=[] for i in range(0,len(n)): if n[i]=="h" || n[i]=="e" || n[i]=="l" || n[i]=="o": l.add(i); l=sorted(l) ans="" for i in range(0,len(l)): if i not in ans: ans=ans+n[i] if(ans=="hello"): print("Yes") else: print("No" ```
-1
940
B
Our Tanya is Crying Out Loud
PROGRAMMING
1,400
[ "dp", "greedy" ]
null
null
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations: 1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*....
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109). The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109). The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109).
Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1.
[ "9\n2\n3\n1\n", "5\n5\n2\n20\n", "19\n3\n4\n2\n" ]
[ "6\n", "8\n", "12\n" ]
In the first testcase, the optimal strategy is as follows: - Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin. The total cost is 6 coins. In the second test case the optimal strategy is to subtra...
1,250
[ { "input": "9\n2\n3\n1", "output": "6" }, { "input": "5\n5\n2\n20", "output": "8" }, { "input": "19\n3\n4\n2", "output": "12" }, { "input": "1845999546\n999435865\n1234234\n2323423", "output": "1044857680578777" }, { "input": "1604353664\n1604353665\n9993432\n1", ...
1,520,997,375
2,147,483,647
Python 3
OK
TESTS
58
62
5,632,000
n=int(input()) k=int(input()) a=int(input()) b=int(input()) sum=0 while(n!=1): if(k>1): if(n%k==0): f=n//k h=n-f n=f sum+=min(h*a,b) else: if(n>k): sum+=a*(n%k) n=n-n%k else: sum+=a*(n-1) n=1 else: sum+=(n-1)*a n=1 print(sum)
Title: Our Tanya is Crying Out Loud Time Limit: None seconds Memory Limit: None megabytes Problem Description: Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perf...
```python n=int(input()) k=int(input()) a=int(input()) b=int(input()) sum=0 while(n!=1): if(k>1): if(n%k==0): f=n//k h=n-f n=f sum+=min(h*a,b) else: if(n>k): sum+=a*(n%k) n=n-n%k else: sum+=a*(n-1) n=1 else: sum+=(n-1)*a n=1 print(sum) ```
3
548
A
Mike and Fax
PROGRAMMING
1,100
[ "brute force", "implementation", "strings" ]
null
null
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages ...
The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000). The second line contains integer *k* (1<=≤<=*k*<=≤<=1000).
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
[ "saba\n2\n", "saddastavvat\n2\n" ]
[ "NO\n", "YES\n" ]
Palindrome is a string reading the same forward and backward. In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
500
[ { "input": "saba\n2", "output": "NO" }, { "input": "saddastavvat\n2", "output": "YES" }, { "input": "aaaaaaaaaa\n3", "output": "NO" }, { "input": "aaaaaa\n3", "output": "YES" }, { "input": "abaacca\n2", "output": "NO" }, { "input": "a\n1", "output"...
1,434,750,451
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
0
s = input() k = int(input()) if int(len(s)) % k == 0 & 1 <= int(len(s) >= 1000) & 1 <= k <= 1000: for i in range(k): a = i*k b = (i+1)*k if s[a:b] != s[a:b][::-1]: print("NO") break else: print("YES") else: print("NO")
Title: Mike and Fax Time Limit: None seconds Memory Limit: None megabytes Problem Description: While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*. He is not sure ...
```python s = input() k = int(input()) if int(len(s)) % k == 0 & 1 <= int(len(s) >= 1000) & 1 <= k <= 1000: for i in range(k): a = i*k b = (i+1)*k if s[a:b] != s[a:b][::-1]: print("NO") break else: print("YES") else: print("NO") ```
0
466
A
Cheap Travel
PROGRAMMING
1,200
[ "implementation" ]
null
null
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu...
The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket.
Print a single integer — the minimum sum in rubles that Ann will need to spend.
[ "6 2 1 2\n", "5 2 2 3\n" ]
[ "6\n", "8\n" ]
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets.
500
[ { "input": "6 2 1 2", "output": "6" }, { "input": "5 2 2 3", "output": "8" }, { "input": "10 3 5 1", "output": "4" }, { "input": "1000 1 1000 1000", "output": "1000000" }, { "input": "1000 3 1000 1000", "output": "334000" }, { "input": "1 1 1 1", "...
1,690,377,969
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
62
0
import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) def main(): ...
Title: Cheap Travel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl...
```python import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) def...
0
478
C
Table Decorations
PROGRAMMING
1,800
[ "greedy" ]
null
null
You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *t* of tables can be decorated if we know number of balloons of each color? Your task is to write a pro...
The single line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.
Print a single integer *t* — the maximum number of tables that can be decorated in the required manner.
[ "5 4 3\n", "1 1 1\n", "2 3 3\n" ]
[ "4\n", "1\n", "2\n" ]
In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively.
1,500
[ { "input": "5 4 3", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 3 3", "output": "2" }, { "input": "0 1 0", "output": "0" }, { "input": "0 3 3", "output": "2" }, { "input": "4 0 4", "output": "2" }, { "input": "100000...
1,684,001,308
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
def decorate_tables(r: int, g: int, b: int) -> int: if r < 0 or g < 0 or b < 0: raise ValueError("Invalid input. All input values must be non-negative integers.") # Sort the colors in descending order colors = sorted([r, g, b], reverse=True) tables = 0 # Greedy approach: pick the t...
Title: Table Decorations Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *...
```python def decorate_tables(r: int, g: int, b: int) -> int: if r < 0 or g < 0 or b < 0: raise ValueError("Invalid input. All input values must be non-negative integers.") # Sort the colors in descending order colors = sorted([r, g, b], reverse=True) tables = 0 # Greedy approach: ...
0
638
B
Making Genome in Berland
PROGRAMMING
1,500
[ "*special", "dfs and similar", "strings" ]
null
null
Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct En...
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragmen...
In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them.
[ "3\nbcd\nab\ncdef\n", "4\nx\ny\nz\nw\n" ]
[ "abcdef\n", "xyzw\n" ]
none
1,000
[ { "input": "3\nbcd\nab\ncdef", "output": "abcdef" }, { "input": "4\nx\ny\nz\nw", "output": "xyzw" }, { "input": "25\nef\nfg\ngh\nhi\nij\njk\nkl\nlm\nmn\nno\nab\nbc\ncd\nde\nop\npq\nqr\nrs\nst\ntu\nuv\nvw\nwx\nxy\nyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "1\nf...
1,458,504,184
28,984
Python 3
WRONG_ANSWER
PRETESTS
2
61
5,120,000
n = int(input()) partOfStrings = list() endStrList = list() endString = str(" ") for i in range (n): partOfStrings.append(input()) for elem in partOfStrings: if elem in endString: continue else: if elem[0] != endString[len(endString)-1] and elem[len(elem)-1] != endString[0]: ...
Title: Making Genome in Berland Time Limit: None seconds Memory Limit: None megabytes Problem Description: Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can...
```python n = int(input()) partOfStrings = list() endStrList = list() endString = str(" ") for i in range (n): partOfStrings.append(input()) for elem in partOfStrings: if elem in endString: continue else: if elem[0] != endString[len(endString)-1] and elem[len(elem)-1] != endString[...
0
688
A
Opponents
PROGRAMMING
800
[ "implementation" ]
null
null
Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Ar...
The first line of the input contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100) — the number of opponents and the number of days, respectively. The *i*-th of the following *d* lines contains a string of length *n* consisting of characters '0' and '1'. The *j*-th character of this string is '0' if the *j*-th op...
Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents.
[ "2 2\n10\n00\n", "4 1\n0100\n", "4 5\n1101\n1111\n0110\n1011\n1111\n" ]
[ "2\n", "1\n", "2\n" ]
In the first and the second samples, Arya will beat all present opponents each of the *d* days. In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.
500
[ { "input": "2 2\n10\n00", "output": "2" }, { "input": "4 1\n0100", "output": "1" }, { "input": "4 5\n1101\n1111\n0110\n1011\n1111", "output": "2" }, { "input": "3 2\n110\n110", "output": "2" }, { "input": "10 6\n1111111111\n0100110101\n1111111111\n0000011010\n1111...
1,678,678,127
2,147,483,647
PyPy 3-64
OK
TESTS
56
77
0
n,m = map(int, input().split()) s = (''.join(["1"]*n)) ans,cnt=-1,0 for _ in range(m): tmp = str(input().strip()) if s==tmp: ans=max(ans,cnt) cnt = 0 else: cnt += 1 ans= max(ans,cnt) print(ans)
Title: Opponents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of th...
```python n,m = map(int, input().split()) s = (''.join(["1"]*n)) ans,cnt=-1,0 for _ in range(m): tmp = str(input().strip()) if s==tmp: ans=max(ans,cnt) cnt = 0 else: cnt += 1 ans= max(ans,cnt) print(ans) ```
3
938
B
Run For Your Prize
PROGRAMMING
1,100
[ "brute force", "greedy" ]
null
null
You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these tw...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
Print one integer — the minimum number of seconds it will take to collect all prizes.
[ "3\n2 3 9\n", "2\n2 999995\n" ]
[ "8\n", "5\n" ]
In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8. In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.
0
[ { "input": "3\n2 3 9", "output": "8" }, { "input": "2\n2 999995", "output": "5" }, { "input": "1\n20", "output": "19" }, { "input": "6\n2 3 500000 999997 999998 999999", "output": "499999" }, { "input": "1\n999999", "output": "1" }, { "input": "1\n5100...
1,598,681,560
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
77
204,800
n=int(input()) ar = list(map(int, input().strip().split(' '))) lst1=list(filter(lambda x: (x<=500000) , ar)) lst2=list(filter(lambda x: (x>500000) , ar)) lst1.append(1) lst2.append(1000000) m=0 for i in range(len(lst1)): if lst1[i]>m: m=lst1[i] mi=min(lst2) mi=1000000-mi if mi>m: prin...
Title: Run For Your Prize Time Limit: None seconds Memory Limit: None megabytes Problem Description: You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are di...
```python n=int(input()) ar = list(map(int, input().strip().split(' '))) lst1=list(filter(lambda x: (x<=500000) , ar)) lst2=list(filter(lambda x: (x>500000) , ar)) lst1.append(1) lst2.append(1000000) m=0 for i in range(len(lst1)): if lst1[i]>m: m=lst1[i] mi=min(lst2) mi=1000000-mi if mi>m:...
0
155
A
I_love_\%username\%
PROGRAMMING
800
[ "brute force" ]
null
null
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e...
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ...
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
[ "5\n100 50 200 150 200\n", "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n" ]
[ "2\n", "4\n" ]
In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
500
[ { "input": "5\n100 50 200 150 200", "output": "2" }, { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242", "output": "4" }, { "input": "1\n6", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "5\n100 36 53 7 81", "output": "2" ...
1,674,559,373
2,147,483,647
Python 3
OK
TESTS
37
92
0
a = int(input()) b = list(map(int, input().split())) res = {"max": b[0], "min": b[0]} k = 0 for i in range(1, len(b)): if b[i] > res["max"]: k += 1 res["max"] = b[i] elif b[i] < res["min"]: k += 1 res['min'] = b[i] print(k)
Title: I_love_\%username\% Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the re...
```python a = int(input()) b = list(map(int, input().split())) res = {"max": b[0], "min": b[0]} k = 0 for i in range(1, len(b)): if b[i] > res["max"]: k += 1 res["max"] = b[i] elif b[i] < res["min"]: k += 1 res['min'] = b[i] print(k) ```
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,637,748,883
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
s=input() c=0 for i in s: if s.lower()==s.upper(): c+=1 print(s.lower()) elif s.lower()>s.upper(): print(s.lower()) else s.upper()>s.lower(): print(s.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python s=input() c=0 for i in s: if s.lower()==s.upper(): c+=1 print(s.lower()) elif s.lower()>s.upper(): print(s.lower()) else s.upper()>s.lower(): print(s.upper()) ```
-1
955
A
Feed the cat
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points. At any time Andrew can visit the store where tasty buns are...
The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening. The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102).
Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4. Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if .
[ "19 00\n255 1 100 1\n", "17 41\n1000 6 15 11\n" ]
[ "25200.0000\n", "1365.0000\n" ]
In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles. In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15...
500
[ { "input": "19 00\n255 1 100 1", "output": "25200.0000" }, { "input": "17 41\n1000 6 15 11", "output": "1365.0000" }, { "input": "16 34\n61066 14 50 59", "output": "43360.0000" }, { "input": "18 18\n23331 86 87 41", "output": "49590.0000" }, { "input": "10 48\n684...
1,614,070,305
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
93
0
hh,mm=map(int,input().split()) H,D,C,N=map(int,input().split()) t=20*60-hh*60+mm t=max(t,0) H1=H+D*t c1=H1//N if(H1%N!=0): c1+=1 m1=(C*0.8)*c1 c2=H//N if(H%N!=0): c1+=1 m2=C*c2 m1=round(m1,4) m2=round(m2,4) print('%.4f'%min(m1,m2))
Title: Feed the cat Time Limit: None seconds Memory Limit: None megabytes Problem Description: After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without foo...
```python hh,mm=map(int,input().split()) H,D,C,N=map(int,input().split()) t=20*60-hh*60+mm t=max(t,0) H1=H+D*t c1=H1//N if(H1%N!=0): c1+=1 m1=(C*0.8)*c1 c2=H//N if(H%N!=0): c1+=1 m2=C*c2 m1=round(m1,4) m2=round(m2,4) print('%.4f'%min(m1,m2)) ```
0
120
A
Elevator
PROGRAMMING
1,000
[ "brute force", "implementation", "math" ]
null
null
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n...
The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the...
Print character "R" if the VIP is right-handed or "L" if he is left-handed.
[ "front\n1\n" ]
[ "L\n" ]
none
0
[ { "input": "front\n1", "output": "L" }, { "input": "back\n1", "output": "R" }, { "input": "front\n2", "output": "R" }, { "input": "back\n2", "output": "L" } ]
1,593,034,285
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
154
6,656,000
s=str(input()) a=(input()) ans=0 if s=="front" and a=="1": ans="L" elif s=="front" and a=="2": ans="R" elif s=="back" and a=="1": ans="R" else: ans="L" print(ans)
Title: Elevator Time Limit: None seconds Memory Limit: None megabytes Problem Description: A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through...
```python s=str(input()) a=(input()) ans=0 if s=="front" and a=="1": ans="L" elif s=="front" and a=="2": ans="R" elif s=="back" and a=="1": ans="R" else: ans="L" print(ans) ```
-1
315
A
Sereja and Bottles
PROGRAMMING
1,400
[ "brute force" ]
null
null
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle.
In a single line print a single integer — the answer to the problem.
[ "4\n1 1\n2 2\n3 3\n4 4\n", "4\n1 2\n2 3\n3 4\n4 1\n" ]
[ "4\n", "0\n" ]
none
500
[ { "input": "4\n1 1\n2 2\n3 3\n4 4", "output": "4" }, { "input": "4\n1 2\n2 3\n3 4\n4 1", "output": "0" }, { "input": "3\n2 828\n4 392\n4 903", "output": "3" }, { "input": "4\n2 3\n1 772\n3 870\n3 668", "output": "2" }, { "input": "5\n1 4\n6 6\n4 3\n3 4\n4 758", ...
1,652,087,891
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
0
n = int(input()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] dic = {} for x,y in zip(a,b): if x!=y: dic[y] = True ct = 0 for bottle in a: if bottle not in dic: ct+=1 print(ct)
Title: Sereja and Bottles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the *i*-th...
```python n = int(input()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] dic = {} for x,y in zip(a,b): if x!=y: dic[y] = True ct = 0 for bottle in a: if bottle not in dic: ct+=1 print(ct) ```
0
17
A
Noldbach problem
PROGRAMMING
1,000
[ "brute force", "math", "number theory" ]
A. Noldbach problem
2
64
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Nold...
The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000).
Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO.
[ "27 2\n", "45 7\n" ]
[ "YES", "NO" ]
In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.
0
[ { "input": "27 2", "output": "YES" }, { "input": "45 7", "output": "NO" }, { "input": "2 0", "output": "YES" }, { "input": "15 1", "output": "YES" }, { "input": "17 1", "output": "YES" }, { "input": "34 5", "output": "NO" }, { "input": "37 ...
1,688,120,711
2,147,483,647
Python 3
OK
TESTS
35
92
0
# your code goes here# your code goes here def prime(n): sieve=[True]*(n+1) sieve[0],sieve[1]=False,False for i in range(2,n+1): if sieve[i]: for j in range(i*i,n+1,i): sieve[j]=False return [[i for i in range(n+1) if sieve[i]],sieve] n,k=list(map(int,input().split())) neighbouring,prime=prime(n...
Title: Noldbach problem Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a prob...
```python # your code goes here# your code goes here def prime(n): sieve=[True]*(n+1) sieve[0],sieve[1]=False,False for i in range(2,n+1): if sieve[i]: for j in range(i*i,n+1,i): sieve[j]=False return [[i for i in range(n+1) if sieve[i]],sieve] n,k=list(map(int,input().split())) neighbouring,pri...
3.977
897
B
Chtholly's request
PROGRAMMING
1,300
[ "brute force" ]
null
null
— I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation with...
The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109).
Output single integer — answer to the problem.
[ "2 100\n", "5 30\n" ]
[ "33\n", "15\n" ]
In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
1,000
[ { "input": "2 100", "output": "33" }, { "input": "5 30", "output": "15" }, { "input": "42147 412393322", "output": "251637727" }, { "input": "77809 868097296", "output": "440411873" }, { "input": "5105 443422097", "output": "363192634" }, { "input": "7...
1,575,871,322
2,147,483,647
PyPy 3
OK
TESTS
26
170
2,150,400
k,p = map(int,input().split()) ans=0 for i in range(1,k+1): s=str(i) s= s[:]+s[::-1] ans+=int(s) print(ans%p)
Title: Chtholly's request Time Limit: None seconds Memory Limit: None megabytes Problem Description: — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thi...
```python k,p = map(int,input().split()) ans=0 for i in range(1,k+1): s=str(i) s= s[:]+s[::-1] ans+=int(s) print(ans%p) ```
3
705
A
Hulk
PROGRAMMING
800
[ "implementation" ]
null
null
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se...
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate.
Print Dr.Banner's feeling in one line.
[ "1\n", "2\n", "3\n" ]
[ "I hate it\n", "I hate that I love it\n", "I hate that I love that I hate it\n" ]
none
500
[ { "input": "1", "output": "I hate it" }, { "input": "2", "output": "I hate that I love it" }, { "input": "3", "output": "I hate that I love that I hate it" }, { "input": "4", "output": "I hate that I love that I hate that I love it" }, { "input": "5", "output"...
1,696,603,965
2,147,483,647
Python 3
OK
TESTS
21
46
0
n = int(input()) for i in range(n): print(('I hate' if i%2 == 0 else 'I love'), end=(' it' if i+1 == n else ' that '))
Title: Hulk Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and...
```python n = int(input()) for i in range(n): print(('I hate' if i%2 == 0 else 'I love'), end=(' it' if i+1 == n else ' that ')) ```
3
637
B
Chat Order
PROGRAMMING
1,200
[ "*special", "binary search", "constructive algorithms", "data structures", "sortings" ]
null
null
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then...
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
[ "4\nalex\nivan\nroman\nivan\n", "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n" ]
[ "ivan\nroman\nalex\n", "alina\nmaria\nekaterina\ndarya\n" ]
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows: 1. alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows: 1. ivan 1. alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows: 1. roman 1...
1,000
[ { "input": "4\nalex\nivan\nroman\nivan", "output": "ivan\nroman\nalex" }, { "input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina", "output": "alina\nmaria\nekaterina\ndarya" }, { "input": "1\nwdi", "output": "wdi" }, { "input": "2\nypg\nypg", "outpu...
1,676,018,362
2,147,483,647
PyPy 3-64
OK
TESTS
95
1,372
38,400,000
from collections import deque c = set() msg = deque() for _ in range(int(input())): s = input() msg.append(s) while len(msg) > 0: cur = msg.pop() if not(cur in c): c.add(cur) print(cur, flush=False)
Title: Chat Order Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The rela...
```python from collections import deque c = set() msg = deque() for _ in range(int(input())): s = input() msg.append(s) while len(msg) > 0: cur = msg.pop() if not(cur in c): c.add(cur) print(cur, flush=False) ```
3
401
C
Team
PROGRAMMING
1,400
[ "constructive algorithms", "greedy", "implementation" ]
null
null
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing ...
The first line contains two integers: *n* (1<=≤<=*n*<=≤<=106) — the number of cards containing number 0; *m* (1<=≤<=*m*<=≤<=106) — the number of cards containing number 1.
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
[ "1 2\n", "4 8\n", "4 10\n", "1 5\n" ]
[ "101\n", "110110110101\n", "11011011011011\n", "-1\n" ]
none
1,500
[ { "input": "1 2", "output": "101" }, { "input": "4 8", "output": "110110110101" }, { "input": "4 10", "output": "11011011011011" }, { "input": "1 5", "output": "-1" }, { "input": "3 4", "output": "1010101" }, { "input": "3 10", "output": "-1" }, ...
1,630,296,985
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
109
20,172,800
# Author Name: Ajay Meena # Codeforce : https://codeforces.com/profile/majay1638 import sys import math import bisect import heapq from bisect import bisect_right from sys import stdin, stdout # -------------- INPUT FUNCTIONS ------------------ def get_ints_in_variables(): return map( int, sys.stdin...
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each t...
```python # Author Name: Ajay Meena # Codeforce : https://codeforces.com/profile/majay1638 import sys import math import bisect import heapq from bisect import bisect_right from sys import stdin, stdout # -------------- INPUT FUNCTIONS ------------------ def get_ints_in_variables(): return map( int,...
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,620,042,088
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
0
n=int(input()) s=0 while (n): n/=10 s+=1 print(s-1)
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 n=int(input()) s=0 while (n): n/=10 s+=1 print(s-1) ```
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,692,189,443
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
102,400
n = int(input()) count=0 while(n > 9): digit_sum = 0 while(n>0): digit_sum = digit_sum + n%10 n=n//10 n = digit_sum count+=1 print(count)
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 n = int(input()) count=0 while(n > 9): digit_sum = 0 while(n>0): digit_sum = digit_sum + n%10 n=n//10 n = digit_sum count+=1 print(count) ```
0
673
A
Bear and Game
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=......
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=... *t**n*<=≤<=90), given in the increasing order.
Print the number of minutes Limak will watch the game.
[ "3\n7 20 88\n", "9\n16 20 30 40 50 60 70 80 90\n", "9\n15 20 30 40 50 60 70 80 90\n" ]
[ "35\n", "15\n", "90\n" ]
In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the w...
500
[ { "input": "3\n7 20 88", "output": "35" }, { "input": "9\n16 20 30 40 50 60 70 80 90", "output": "15" }, { "input": "9\n15 20 30 40 50 60 70 80 90", "output": "90" }, { "input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88", ...
1,548,901,118
2,147,483,647
Python 3
OK
TESTS
34
109
0
n = int(input()) l = list(map(int, input().split())) # if l[0] > 15: # print(15) # else: # for i in range(1, len(l)): # if l[i] > l[i-1] + 15: # print(l[i-1] + 15) # break # if i == len(l) - 1: # print(90) l = [0] + l + [90] for i in range(1, len(l)): if l[i] > l[i-1] + 15: print...
Title: Bear and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Lim...
```python n = int(input()) l = list(map(int, input().split())) # if l[0] > 15: # print(15) # else: # for i in range(1, len(l)): # if l[i] > l[i-1] + 15: # print(l[i-1] + 15) # break # if i == len(l) - 1: # print(90) l = [0] + l + [90] for i in range(1, len(l)): if l[i] > l[i-1] + 15...
3
960
A
Check the string
PROGRAMMING
1,200
[ "implementation" ]
null
null
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string. B now gi...
The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
Print "YES" or "NO", according to the condition.
[ "aaabccc\n", "bbacc\n", "aabc\n" ]
[ "YES\n", "NO\n", "YES\n" ]
Consider first example: the number of 'c' is equal to the number of 'a'. Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct. Consider third example: the number of 'c' is equal to the number of 'b'.
500
[ { "input": "aaabccc", "output": "YES" }, { "input": "bbacc", "output": "NO" }, { "input": "aabc", "output": "YES" }, { "input": "aabbcc", "output": "YES" }, { "input": "aaacccbb", "output": "NO" }, { "input": "abc", "output": "YES" }, { "in...
1,611,632,751
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
77
0
word = input() a = 0 b = 0 c = 0 stop = False for i in range(len(word)-1): if ord(word[i]) >= ord(word[i+1]): stop = True break if word[i] == 'a': a += 1 if word[i] == 'b': b += 1 if word[i] == 'c': c += 1 if not stop and a >= 1 and b >= 1: ...
Title: Check the string Time Limit: None seconds Memory Limit: None megabytes Problem Description: A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b...
```python word = input() a = 0 b = 0 c = 0 stop = False for i in range(len(word)-1): if ord(word[i]) >= ord(word[i+1]): stop = True break if word[i] == 'a': a += 1 if word[i] == 'b': b += 1 if word[i] == 'c': c += 1 if not stop and a >= 1 and b ...
0
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,642,839,068
2,147,483,647
Python 3
OK
TESTS
35
92
0
a , b =map(int , input().split()) mas=a*b print(mas//2)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python a , b =map(int , input().split()) mas=a*b print(mas//2) ```
3.977
958
B1
Maximum Control (easy)
PROGRAMMING
1,000
[ "implementation" ]
null
null
The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect s...
The first line of the input contains an integer *N* (2<=≤<=*N*<=≤<=1000) – the number of planets in the galaxy. The next *N*<=-<=1 lines describe the hyperspace tunnels between the planets. Each of the *N*<=-<=1 lines contains two space-separated integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*N*) indicating that there is ...
A single integer denoting the number of remote planets.
[ "5\n4 1\n4 2\n1 3\n1 5\n", "4\n1 2\n4 3\n1 4\n" ]
[ "3\n", "2\n" ]
In the first example, only planets 2, 3 and 5 are connected by a single tunnel. In the second example, the remote planets are 2 and 3. Note that this problem has only two versions – easy and medium.
0
[ { "input": "5\n4 1\n4 2\n1 3\n1 5", "output": "3" }, { "input": "4\n1 2\n4 3\n1 4", "output": "2" }, { "input": "10\n4 3\n2 6\n10 1\n5 7\n5 8\n10 6\n5 9\n9 3\n2 9", "output": "4" } ]
1,611,501,024
2,147,483,647
Python 3
OK
TESTS
9
77
307,200
resole = [] result = 0 for i in range(int(input()) - 1): resole.extend(list(map(lambda x: int(x), input().split(' ')))) resole.sort() for i in range(1, len(resole) - 1): if not resole[i + 1] == resole[i] and not resole[i - 1] == resole[i]: result += 1 if not resole[len(resole) - 1] == reso...
Title: Maximum Control (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in s...
```python resole = [] result = 0 for i in range(int(input()) - 1): resole.extend(list(map(lambda x: int(x), input().split(' ')))) resole.sort() for i in range(1, len(resole) - 1): if not resole[i + 1] == resole[i] and not resole[i - 1] == resole[i]: result += 1 if not resole[len(resole) - ...
3
884
B
Japanese Crosswords Strike Back
PROGRAMMING
1,100
[ "implementation" ]
null
null
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect. For example: - If *x*<==<...
The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding.
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
[ "2 4\n1 3\n", "3 10\n3 3 2\n", "2 10\n1 3\n" ]
[ "NO\n", "YES\n", "NO\n" ]
none
0
[ { "input": "2 4\n1 3", "output": "NO" }, { "input": "3 10\n3 3 2", "output": "YES" }, { "input": "2 10\n1 3", "output": "NO" }, { "input": "1 1\n1", "output": "YES" }, { "input": "1 10\n10", "output": "YES" }, { "input": "1 10000\n10000", "output":...
1,509,115,350
2,250
Python 3
OK
TESTS
66
109
7,372,800
(n, length) = map(int, input().split()) lst = [] for x in input().split(): lst.append(int(x)) k = sum(lst) + len(lst) - 1 if k == length: print("YES") else: print("NO")
Title: Japanese Crosswords Strike Back Time Limit: None seconds Memory Limit: None megabytes Problem Description: A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely ...
```python (n, length) = map(int, input().split()) lst = [] for x in input().split(): lst.append(int(x)) k = sum(lst) + len(lst) - 1 if k == length: print("YES") else: print("NO") ```
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,617,869,299
2,147,483,647
Python 3
OK
TESTS
32
154
0
evens=[] odds=[] n=int(input()) li=list(map(int,input().split(" "))) for x in li: if x%2==0: evens.append(x) else: odds.append(x) if len(evens)==1: print(li.index(evens[0])+1) else: print(li.index(odds[0])+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 evens=[] odds=[] n=int(input()) li=list(map(int,input().split(" "))) for x in li: if x%2==0: evens.append(x) else: odds.append(x) if len(evens)==1: print(li.index(evens[0])+1) else: print(li.index(odds[0])+1) ```
3.9615
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,695,417,016
2,147,483,647
PyPy 3-64
OK
TESTS
36
186
2,867,200
import sys import math import bisect import re def input(): return sys.stdin.readline().rstrip("\r\n") def main(): #length = int(input()) n = int(input()) #string = input() ans = 0 #numbers = [*map(int, input().split())] lucky = [4,7,44,47,74,77,444,447,474,477,744,747,777] pr...
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 import sys import math import bisect import re def input(): return sys.stdin.readline().rstrip("\r\n") def main(): #length = int(input()) n = int(input()) #string = input() ans = 0 #numbers = [*map(int, input().split())] lucky = [4,7,44,47,74,77,444,447,474,477,744,747,77...
3
879
B
Table Tennis
PROGRAMMING
1,200
[ "data structures", "implementation" ]
null
null
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner. For each of t...
The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all ...
Output a single integer — power of the winner.
[ "2 2\n1 2\n", "4 2\n3 1 2 4\n", "6 2\n6 5 3 1 2 4\n", "2 10000000000\n2 1\n" ]
[ "2 ", "3 ", "6 ", "2\n" ]
Games in the second sample: 3 plays with 1. 3 wins. 1 goes to the end of the line. 3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner.
1,000
[ { "input": "2 2\n1 2", "output": "2 " }, { "input": "4 2\n3 1 2 4", "output": "3 " }, { "input": "6 2\n6 5 3 1 2 4", "output": "6 " }, { "input": "2 10000000000\n2 1", "output": "2" }, { "input": "4 4\n1 3 4 2", "output": "4 " }, { "input": "2 21474836...
1,572,863,033
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
109
0
first = input().split() second = input().split() intFirst = [] for x in first: intFirst.append(int(x)) intSecond = [] for y in second: intSecond.append(int(y)) numberPlayers = intFirst[0] wins = intFirst[1] winList = [] winner = 0 i = 0 if numberPlayers < wins: winner = max(intSecond) ...
Title: Table Tennis Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so o...
```python first = input().split() second = input().split() intFirst = [] for x in first: intFirst.append(int(x)) intSecond = [] for y in second: intSecond.append(int(y)) numberPlayers = intFirst[0] wins = intFirst[1] winList = [] winner = 0 i = 0 if numberPlayers < wins: winner = max(i...
0
66
A
Petya and Java
PROGRAMMING
1,300
[ "implementation", "strings" ]
A. Petya and Java
2
256
Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is the best choice. The main argument in favor of choosing Java was that it has a very large integer data type, called BigInteger. But h...
The first line contains a positive number *n*. It consists of no more than 100 digits and doesn't contain any leading zeros. The number *n* can't be represented as an empty string. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Print the first type from the list "byte, short, int, long, BigInteger", that can store the natural number *n*, in accordance with the data given above.
[ "127\n", "130\n", "123456789101112131415161718192021222324\n" ]
[ "byte\n", "short\n", "BigInteger\n" ]
none
500
[ { "input": "127", "output": "byte" }, { "input": "130", "output": "short" }, { "input": "123456789101112131415161718192021222324", "output": "BigInteger" }, { "input": "6", "output": "byte" }, { "input": "16", "output": "byte" }, { "input": "126", ...
1,533,578,467
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
218
0
def petya_and_java(number): if number in range(-128, 128): return "byte" elif number in range(-32768, 32768): return "short" elif number in range(-2147483648, 2147483648): return "int" elif number(-9223372036854775808, 9223372036854775808): return "long" elif...
Title: Petya and Java Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is the best choice. The main argument in ...
```python def petya_and_java(number): if number in range(-128, 128): return "byte" elif number in range(-32768, 32768): return "short" elif number in range(-2147483648, 2147483648): return "int" elif number(-9223372036854775808, 9223372036854775808): return "long"...
-1
822
A
I'm bored with life
PROGRAMMING
800
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo...
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
500
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "ou...
1,668,577,187
2,147,483,647
Python 3
OK
TESTS
59
46
0
import math a,b=map(int,input().split()) x=min(a,b) print(math.factorial(x))
Title: I'm bored with life Time Limit: None seconds Memory Limit: None megabytes Problem Description: Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi...
```python import math a,b=map(int,input().split()) x=min(a,b) print(math.factorial(x)) ```
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,677,237,495
2,147,483,647
Python 3
OK
TESTS
117
140
204,800
n, k = map(int, input().split()) s = input() dp = [0, 0] ans = 0 for i in range(n): dp[ord(s[i]) - ord('a')] += 1 if min(dp) > k: dp[ord(s[i - ans]) - ord('a')] -= 1 else: ans += 1 print(ans)
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 n, k = map(int, input().split()) s = input() dp = [0, 0] ans = 0 for i in range(n): dp[ord(s[i]) - ord('a')] += 1 if min(dp) > k: dp[ord(s[i - ans]) - ord('a')] -= 1 else: ans += 1 print(ans) ```
3
237
A
Free Cash
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is...
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
[ "4\n8 0\n8 10\n8 10\n8 45\n", "3\n0 12\n10 11\n22 22\n" ]
[ "2\n", "1\n" ]
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so ...
500
[ { "input": "4\n8 0\n8 10\n8 10\n8 45", "output": "2" }, { "input": "3\n0 12\n10 11\n22 22", "output": "1" }, { "input": "5\n12 8\n15 27\n15 27\n16 2\n19 52", "output": "2" }, { "input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23", "output": "3" }, { "input": "...
1,642,556,954
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
8
1,402
3,276,800
mx = 1 ls = [] for _ in range(int(input())): i, j = map(str, input().split()) ls.append(i + j) for i in set(ls): mx = max(mx, ls.count(i)) print(mx)
Title: Free Cash Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l...
```python mx = 1 ls = [] for _ in range(int(input())): i, j = map(str, input().split()) ls.append(i + j) for i in set(ls): mx = max(mx, ls.count(i)) print(mx) ```
0
912
A
Tricky Alchemy
PROGRAMMING
800
[ "implementation" ]
null
null
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ...
The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal. The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained.
Print a single integer — the minimum number of crystals that Grisha should acquire in addition.
[ "4 3\n2 1 1\n", "3 9\n1 1 3\n", "12345678 87654321\n43043751 1000000000 53798715\n" ]
[ "2\n", "1\n", "2147483648\n" ]
In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.
500
[ { "input": "4 3\n2 1 1", "output": "2" }, { "input": "3 9\n1 1 3", "output": "1" }, { "input": "12345678 87654321\n43043751 1000000000 53798715", "output": "2147483648" }, { "input": "12 12\n3 5 2", "output": "0" }, { "input": "770 1390\n170 442 311", "output"...
1,516,339,101
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
5,632,000
n , k = map(int, input().split()) print(n if k == 1 else 2 ** (len(bin(n)) - 2) - 1)
Title: Tricky Alchemy Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obta...
```python n , k = map(int, input().split()) print(n if k == 1 else 2 ** (len(bin(n)) - 2) - 1) ```
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,591,553,646
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
216
0
# -*- coding: utf-8 -*- """ Created on Sun Jun 7 23:21:18 2020 @author: Anmol Singla """ def funk(a): return(int(a*(a+1)/2)) from math import sqrt n=int(input()) true=0 for i in range(1,int(sqrt(n))+1): x=funk(i) y=(n-x) if(funk(int(sqrt(int(2*y))))==y): print("YES") ...
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 # -*- coding: utf-8 -*- """ Created on Sun Jun 7 23:21:18 2020 @author: Anmol Singla """ def funk(a): return(int(a*(a+1)/2)) from math import sqrt n=int(input()) true=0 for i in range(1,int(sqrt(n))+1): x=funk(i) y=(n-x) if(funk(int(sqrt(int(2*y))))==y): print("YES")...
0
268
A
Games
PROGRAMMING
800
[ "brute force" ]
null
null
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ...
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
In a single line print the number of games where the host team is going to play in the guest uniform.
[ "3\n1 2\n2 4\n3 4\n", "4\n100 42\n42 100\n5 42\n100 5\n", "2\n1 2\n1 2\n" ]
[ "1\n", "5\n", "0\n" ]
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea...
500
[ { "input": "3\n1 2\n2 4\n3 4", "output": "1" }, { "input": "4\n100 42\n42 100\n5 42\n100 5", "output": "5" }, { "input": "2\n1 2\n1 2", "output": "0" }, { "input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52", "output": "6" }, { "input": "10\n68 42\n1 35\n25 70\n...
1,681,126,713
2,147,483,647
Python 3
OK
TESTS
31
62
0
n = int(input()) team = [] res = 0 for _ in range(n): team.append(input().split()) for i, array in enumerate(team): color = array[0] for j, elem in enumerate(team): if i != j and elem[1] == color: res += 1 print(res)
Title: Games Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W...
```python n = int(input()) team = [] res = 0 for _ in range(n): team.append(input().split()) for i, array in enumerate(team): color = array[0] for j, elem in enumerate(team): if i != j and elem[1] == color: res += 1 print(res) ```
3
224
A
Parallelepiped
PROGRAMMING
1,100
[ "brute force", "geometry", "math" ]
null
null
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Print a single number — the sum of all edges of the parallelepiped.
[ "1 1 1\n", "4 6 6\n" ]
[ "12\n", "28\n" ]
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
500
[ { "input": "1 1 1", "output": "12" }, { "input": "4 6 6", "output": "28" }, { "input": "20 10 50", "output": "68" }, { "input": "9 4 36", "output": "56" }, { "input": "324 9 36", "output": "184" }, { "input": "1333 93 129", "output": "308" }, {...
1,648,293,353
2,147,483,647
Python 3
OK
TESTS
27
62
0
import math data = input().split() A1, A2, A3 = int(data[0]), int(data[1]), int(data[2]) H = int(math.sqrt((A2 * A3) // A1)) W = A3 // H L = A1 // W print(4*L + 4*W + 4*H)
Title: Parallelepiped Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. Input S...
```python import math data = input().split() A1, A2, A3 = int(data[0]), int(data[1]), int(data[2]) H = int(math.sqrt((A2 * A3) // A1)) W = A3 // H L = A1 // W print(4*L + 4*W + 4*H) ```
3
804
B
Minimum number of steps
PROGRAMMING
1,400
[ "combinatorics", "greedy", "implementation", "math" ]
null
null
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<...
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Print the minimum number of steps modulo 109<=+<=7.
[ "ab\n", "aab\n" ]
[ "1\n", "3\n" ]
The first example: "ab"  →  "bba". The second example: "aab"  →  "abba"  →  "bbaba"  →  "bbbbaa".
1,000
[ { "input": "ab", "output": "1" }, { "input": "aab", "output": "3" }, { "input": "aaaaabaabababaaaaaba", "output": "17307" }, { "input": "abaabaaabbabaabab", "output": "1795" }, { "input": "abbaa", "output": "2" }, { "input": "abbaaabaabaaaaabbbbaababaa...
1,668,698,134
2,147,483,647
Python 3
OK
TESTS
32
327
2,867,200
ab = input() value = 1 count = 0 mod = (10 ** 9) + 7 for e in ab: if e == 'b': count = (value + count - 1) % mod else: value = (value * 2) % mod print(count)
Title: Minimum number of steps Time Limit: None seconds Memory Limit: None megabytes Problem Description: We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substr...
```python ab = input() value = 1 count = 0 mod = (10 ** 9) + 7 for e in ab: if e == 'b': count = (value + count - 1) % mod else: value = (value * 2) % mod print(count) ```
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,621,378,004
2,147,483,647
Python 3
OK
TESTS
58
77
0
cadena = input() cadArr = [char for char in cadena] search = 'heidi' found = False for i in cadArr: if len(search)==0: yes = print('YES') found = True break cAct = search[0] if i == cAct: s1 = search[1:] search = s1 if len(search) != 0 and fo...
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 cadena = input() cadArr = [char for char in cadena] search = 'heidi' found = False for i in cadArr: if len(search)==0: yes = print('YES') found = True break cAct = search[0] if i == cAct: s1 = search[1:] search = s1 if len(search) !...
3
266
B
Queue at the School
PROGRAMMING
800
[ "constructive algorithms", "graph matchings", "implementation", "shortest paths" ]
null
null
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea...
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find. The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *...
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
[ "5 1\nBGGBG\n", "5 2\nBGGBG\n", "4 1\nGGGB\n" ]
[ "GBGGB\n", "GGBGB\n", "GGGB\n" ]
none
500
[ { "input": "5 1\nBGGBG", "output": "GBGGB" }, { "input": "5 2\nBGGBG", "output": "GGBGB" }, { "input": "4 1\nGGGB", "output": "GGGB" }, { "input": "2 1\nBB", "output": "BB" }, { "input": "2 1\nBG", "output": "GB" }, { "input": "6 2\nBBGBBG", "outpu...
1,695,638,491
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
# -*- coding: utf-8 -*- """ Created on Mon Sep 25 17:15:12 2023 @author: 25419 """ list1=input().split() line=input() l=int(list1[0]) t=int(list1[1]) pr=0 while pr<t: pr=pr+1 for i in range(l-1): if line[i]=='B' and line[i+1]=='G': line[i]='G' line[i+1]='B' pr...
Title: Queue at the School Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling a...
```python # -*- coding: utf-8 -*- """ Created on Mon Sep 25 17:15:12 2023 @author: 25419 """ list1=input().split() line=input() l=int(list1[0]) t=int(list1[1]) pr=0 while pr<t: pr=pr+1 for i in range(l-1): if line[i]=='B' and line[i+1]=='G': line[i]='G' line[i+...
-1
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,435,165,445
2,045
Python 3
OK
TESTS
33
62
0
assd=input() print(((len(assd)+1)*26-len(assd)))
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 assd=input() print(((len(assd)+1)*26-len(assd))) ```
3
611
B
New Year and Old Property
PROGRAMMING
1,300
[ "bitmasks", "brute force", "implementation" ]
null
null
The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Lim...
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively.
Print one integer – the number of years Limak will count in his chosen interval.
[ "5 10\n", "2015 2015\n", "100 105\n", "72057594000000000 72057595000000000\n" ]
[ "2\n", "1\n", "0\n", "26\n" ]
In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<su...
750
[ { "input": "5 10", "output": "2" }, { "input": "2015 2015", "output": "1" }, { "input": "100 105", "output": "0" }, { "input": "72057594000000000 72057595000000000", "output": "26" }, { "input": "1 100", "output": "16" }, { "input": "100000000000000000...
1,545,516,841
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
2,000
0
def cont0(x): string = str(bin(x)) number = string.count("0") return number years = list(map(int,input().split())) a = 0 for i in range(years[0],years[1]+1): if cont0(i) == 2: a += 1 print(a)
Title: New Year and Old Property Time Limit: None seconds Memory Limit: None megabytes Problem Description: The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 2...
```python def cont0(x): string = str(bin(x)) number = string.count("0") return number years = list(map(int,input().split())) a = 0 for i in range(years[0],years[1]+1): if cont0(i) == 2: a += 1 print(a) ```
0
938
D
Buy a Ticket
PROGRAMMING
2,000
[ "data structures", "graphs", "shortest paths" ]
null
null
Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well. There are *n* cities in Berland. People can travel between cities using two-directional train routes; there are exactly *m* routes, *i*-th route can be used to go ...
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=2·105, 1<=≤<=*m*<=≤<=2·105). Then *m* lines follow, *i*-th contains three integers *v**i*, *u**i* and *w**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*,<=*v**i*<=≠<=*u**i*, 1<=≤<=*w**i*<=≤<=1012) denoting *i*-th train route. There are no multiple train routes connect...
Print *n* integers. *i*-th of them must be equal to the minimum number of coins a person from city *i* has to spend to travel to some city *j* (or possibly stay in city *i*), attend a concert there, and return to city *i* (if *j*<=≠<=*i*).
[ "4 2\n1 2 4\n2 3 7\n6 20 1 25\n", "3 3\n1 2 1\n2 3 1\n1 3 1\n30 10 20\n" ]
[ "6 14 1 25 \n", "12 10 12 \n" ]
none
0
[ { "input": "4 2\n1 2 4\n2 3 7\n6 20 1 25", "output": "6 14 1 25 " }, { "input": "3 3\n1 2 1\n2 3 1\n1 3 1\n30 10 20", "output": "12 10 12 " }, { "input": "7 7\n1 6 745325\n2 3 3581176\n2 4 19\n3 6 71263060078\n5 4 141198\n7 4 163953\n5 6 15994\n1 297404206755 82096176217 14663411 1873897...
1,604,800,627
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
109
0
from sys import stdin, stdout n, m = map(int, stdin.readline().split()) ady = [[] for i in range(n)] for i in range(m): u,v,w = map(int,stdin.readline().split()) ady[u-1].append((v-1,2*w)) ady[v-1].append((u-1,2*w)) d_xcity = list(map(int,stdin.readline().split())) pq = [[i,d_xcity[i]] for i...
Title: Buy a Ticket Time Limit: None seconds Memory Limit: None megabytes Problem Description: Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well. There are *n* cities in Berland. People can travel between cities...
```python from sys import stdin, stdout n, m = map(int, stdin.readline().split()) ady = [[] for i in range(n)] for i in range(m): u,v,w = map(int,stdin.readline().split()) ady[u-1].append((v-1,2*w)) ady[v-1].append((u-1,2*w)) d_xcity = list(map(int,stdin.readline().split())) pq = [[i,d_xcity...
0
432
D
Prefixes and Suffixes
PROGRAMMING
2,000
[ "dp", "string suffix structures", "strings", "two pointers" ]
null
null
You have a string *s*<==<=*s*1*s*2...*s*|*s*|, where |*s*| is the length of string *s*, and *s**i* its *i*-th character. Let's introduce several definitions: - A substring *s*[*i*..*j*] (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|) of string *s* is string *s**i**s**i*<=+<=1...*s**j*. - The prefix of string *s* of length *l* (1<=≤...
The single line contains a sequence of characters *s*1*s*2...*s*|*s*| (1<=≤<=|*s*|<=≤<=105) — string *s*. The string only consists of uppercase English letters.
In the first line, print integer *k* (0<=≤<=*k*<=≤<=|*s*|) — the number of prefixes that match a suffix of string *s*. Next print *k* lines, in each line print two integers *l**i* *c**i*. Numbers *l**i* *c**i* mean that the prefix of the length *l**i* matches the suffix of length *l**i* and occurs in string *s* as a su...
[ "ABACABA\n", "AAA\n" ]
[ "3\n1 4\n3 2\n7 1\n", "3\n1 3\n2 2\n3 1\n" ]
none
2,000
[ { "input": "ABACABA", "output": "3\n1 4\n3 2\n7 1" }, { "input": "AAA", "output": "3\n1 3\n2 2\n3 1" }, { "input": "A", "output": "1\n1 1" }, { "input": "AAAAAAAAAAAAAAAAXAAAAAAAAAAAAAAAAAAAAAAA", "output": "17\n1 39\n2 37\n3 35\n4 33\n5 31\n6 29\n7 27\n8 25\n9 23\n10 21\...
1,666,873,899
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
def answer(string): pattern1 = zalgo(string) print(len(pattern1) + 1) for i in pattern1: pattern2 = lps(i) temp = kmp(string, i, pattern2) print(len(i), temp+1) print(len(string), 1) def lps(s): lps = [0 for _ in range(len(s))] i, j = 0, 1 while j < len...
Title: Prefixes and Suffixes Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a string *s*<==<=*s*1*s*2...*s*|*s*|, where |*s*| is the length of string *s*, and *s**i* its *i*-th character. Let's introduce several definitions: - A substring *s*[*i*..*j*] (1<=≤<=*i*<=≤<=*j*<=≤<=...
```python def answer(string): pattern1 = zalgo(string) print(len(pattern1) + 1) for i in pattern1: pattern2 = lps(i) temp = kmp(string, i, pattern2) print(len(i), temp+1) print(len(string), 1) def lps(s): lps = [0 for _ in range(len(s))] i, j = 0, 1 whi...
0
702
A
Maximum Increase
PROGRAMMING
800
[ "dp", "greedy", "implementation" ]
null
null
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print the maximum length of an increasing subarray of the given array.
[ "5\n1 7 2 11 15\n", "6\n100 100 100 100 100 100\n", "3\n1 2 3\n" ]
[ "3\n", "1\n", "3\n" ]
none
0
[ { "input": "5\n1 7 2 11 15", "output": "3" }, { "input": "6\n100 100 100 100 100 100", "output": "1" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "1\n1000000000", "output": "1" }, { "input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7...
1,696,531,277
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
n=int(input()) string=input().split() arr=[] ans=[] for x in string: arr.append(int(x)) mx=1 lastposition=0 violet=False for i in range(1,len(arr),1): if arr[i-1]>=arr[i]: violet=True else: violet=False if violet==True: if mx<(i-lastposi...
Title: Maximum Increase Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called...
```python n=int(input()) string=input().split() arr=[] ans=[] for x in string: arr.append(int(x)) mx=1 lastposition=0 violet=False for i in range(1,len(arr),1): if arr[i-1]>=arr[i]: violet=True else: violet=False if violet==True: if mx<(...
0
10
D
LCIS
PROGRAMMING
2,800
[ "dp" ]
D. LCIS
1
256
This problem differs from one which was on the online contest. The sequence *a*1,<=*a*2,<=...,<=*a**n* is called increasing, if *a**i*<=&lt;<=*a**i*<=+<=1 for *i*<=&lt;<=*n*. The sequence *s*1,<=*s*2,<=...,<=*s**k* is called the subsequence of the sequence *a*1,<=*a*2,<=...,<=*a**n*, if there exist such a set of inde...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=500) — the length of the first sequence. The second line contains *n* space-separated integers from the range [0,<=109] — elements of the first sequence. The third line contains an integer *m* (1<=≤<=*m*<=≤<=500) — the length of the second sequence. The fourth line ...
In the first line output *k* — the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any.
[ "7\n2 3 1 6 5 4 6\n4\n1 3 5 6\n", "5\n1 2 0 2 1\n3\n1 0 1\n" ]
[ "3\n3 5 6 \n", "2\n0 1 \n" ]
none
0
[ { "input": "7\n2 3 1 6 5 4 6\n4\n1 3 5 6", "output": "3\n3 5 6 " }, { "input": "5\n1 2 0 2 1\n3\n1 0 1", "output": "2\n0 1 " }, { "input": "2\n6 10\n3\n6 3 3", "output": "1\n6 " }, { "input": "1\n7\n2\n7 9", "output": "1\n7 " }, { "input": "3\n37 49 24\n3\n33 5 70...
1,637,086,540
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
#Слава Великой Змее! n = int(input()) arr = [0] + list(map(int, input().split())) m = int(input()) brr = [0] + list(map(int, input().split())) d = [[0 for j in range(m + 1)] for i in range(n + 1)] prev = [0] * (n + 1) for i in range(1, n + 1): for j in range(1, m + 1): if arr[i] == brr[j]: d[i][...
Title: LCIS Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: This problem differs from one which was on the online contest. The sequence *a*1,<=*a*2,<=...,<=*a**n* is called increasing, if *a**i*<=&lt;<=*a**i*<=+<=1 for *i*<=&lt;<=*n*. The sequence *s*1,<=*s*2,<=...,<=*s**k* is called the sub...
```python #Слава Великой Змее! n = int(input()) arr = [0] + list(map(int, input().split())) m = int(input()) brr = [0] + list(map(int, input().split())) d = [[0 for j in range(m + 1)] for i in range(n + 1)] prev = [0] * (n + 1) for i in range(1, n + 1): for j in range(1, m + 1): if arr[i] == brr[j]: ...
-1
580
E
Kefa and Watch
PROGRAMMING
2,500
[ "data structures", "hashing", "strings" ]
null
null
One day Kefa the parrot was walking down the street as he was on the way home from the restaurant when he saw something glittering by the road. As he came nearer he understood that it was a watch. He decided to take it to the pawnbroker to earn some money. The pawnbroker said that each watch contains a serial number ...
The first line of the input contains three positive integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=+<=*k*<=≤<=105) — the length of the serial number, the number of change made by Kefa and the number of quality checks. The second line contains a serial number consisting of *n* digits. Then *m*<=+<=*k* lines ...
For each check on a single line print "YES" if the watch passed it, otherwise print "NO".
[ "3 1 2\n112\n2 2 3 1\n1 1 3 8\n2 1 2 1\n", "6 2 3\n334934\n2 2 5 2\n1 4 4 3\n2 1 6 3\n1 2 3 8\n2 3 6 1\n" ]
[ "NO\nYES\n", "NO\nYES\nNO\n" ]
In the first sample test two checks will be made. In the first one substring "12" is checked on whether or not it has period 1, so the answer is "NO". In the second one substring "88", is checked on whether or not it has period 1, and it has this period, so the answer is "YES". In the second statement test three check...
2,500
[ { "input": "3 1 2\n112\n2 2 3 1\n1 1 3 8\n2 1 2 1", "output": "NO\nYES" }, { "input": "6 2 3\n334934\n2 2 5 2\n1 4 4 3\n2 1 6 3\n1 2 3 8\n2 3 6 1", "output": "NO\nYES\nNO" }, { "input": "1 0 1\n5\n2 1 1 1", "output": "YES" }, { "input": "20 1 2\n34075930750342906718\n2 1 20 2...
1,697,628,262
2,147,483,647
PyPy 3-64
OK
TESTS
80
763
23,449,600
if True: from io import BytesIO, IOBase import math import random import sys import os import bisect import typing from collections import Counter, defaultdict, deque from copy import deepcopy from functools import cmp_to_key, lru_cache, reduce from heapq impor...
Title: Kefa and Watch Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Kefa the parrot was walking down the street as he was on the way home from the restaurant when he saw something glittering by the road. As he came nearer he understood that it was a watch. He decided to take it t...
```python if True: from io import BytesIO, IOBase import math import random import sys import os import bisect import typing from collections import Counter, defaultdict, deque from copy import deepcopy from functools import cmp_to_key, lru_cache, reduce from h...
3
151
A
Soft Drinking
PROGRAMMING
800
[ "implementation", "math" ]
null
null
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt. To make a toast, each frie...
The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.
Print a single integer — the number of toasts each friend can make.
[ "3 4 5 10 8 100 3 1\n", "5 100 10 1 19 90 4 3\n", "10 1000 1000 25 23 1 50 1\n" ]
[ "2\n", "3\n", "0\n" ]
A comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
500
[ { "input": "3 4 5 10 8 100 3 1", "output": "2" }, { "input": "5 100 10 1 19 90 4 3", "output": "3" }, { "input": "10 1000 1000 25 23 1 50 1", "output": "0" }, { "input": "1 7 4 5 5 8 3 2", "output": "4" }, { "input": "2 3 3 5 5 10 1 3", "output": "1" }, { ...
1,672,746,866
2,147,483,647
Python 3
OK
TESTS
27
92
0
n, k, l, c, d, p, nl, np = [int(i) for i in input().split(" ")] print(min(k*l//nl, c*d, p//np)//n)
Title: Soft Drinking Time Limit: None seconds Memory Limit: None megabytes Problem Description: This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut...
```python n, k, l, c, d, p, nl, np = [int(i) for i in input().split(" ")] print(min(k*l//nl, c*d, p//np)//n) ```
3
252
A
Little Xor
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that. ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230.
Print a single integer — the required maximal *xor* of a segment of consecutive elements.
[ "5\n1 2 1 1 2\n", "3\n1 2 7\n", "4\n4 2 4 8\n" ]
[ "3\n", "7\n", "14\n" ]
In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one. The second sample contains only one optimal segment, which contains exactly one array element (element with index three).
500
[ { "input": "5\n1 2 1 1 2", "output": "3" }, { "input": "3\n1 2 7", "output": "7" }, { "input": "4\n4 2 4 8", "output": "14" }, { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "output": "15" }, { "inpu...
1,564,900,313
2,147,483,647
Python 3
OK
TESTS
56
248
0
n=int(input()) a=list(map(int,input().split())) m=0 for i in range(0,n-1): x=a[i] m=max(m,x) for j in range(i+1,n): x=x^a[j] m=max(m,x) print(max(m,a[n-1]))
Title: Little Xor Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, ...
```python n=int(input()) a=list(map(int,input().split())) m=0 for i in range(0,n-1): x=a[i] m=max(m,x) for j in range(i+1,n): x=x^a[j] m=max(m,x) print(max(m,a[n-1])) ```
3
218
B
Airport
PROGRAMMING
1,100
[ "implementation" ]
null
null
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=&gt;<=0) empty seats at the given moment, then the ticket for such a plane ...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th...
Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly.
[ "4 3\n2 1 1\n", "4 3\n2 2 2\n" ]
[ "5 5\n", "7 6\n" ]
In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum. In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd pl...
500
[ { "input": "4 3\n2 1 1", "output": "5 5" }, { "input": "4 3\n2 2 2", "output": "7 6" }, { "input": "10 5\n10 3 3 1 2", "output": "58 26" }, { "input": "10 1\n10", "output": "55 55" }, { "input": "10 1\n100", "output": "955 955" }, { "input": "10 2\n4 7...
1,622,116,067
2,147,483,647
Python 3
OK
TESTS
33
186
0
def maximum(lst,n): amount = 0 for _ in range(n): maxempty = max(lst) amount += maxempty lst[lst.index(maxempty)] -= 1 return amount def minimum(anotherlst,n): amount = 0 count = n while count: minempty = min(anotherlst) if minempty<=0: ...
Title: Airport Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen pl...
```python def maximum(lst,n): amount = 0 for _ in range(n): maxempty = max(lst) amount += maxempty lst[lst.index(maxempty)] -= 1 return amount def minimum(anotherlst,n): amount = 0 count = n while count: minempty = min(anotherlst) if minempty...
3
965
C
Greedy Arkady
PROGRAMMING
2,000
[ "math" ]
null
null
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away. The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies ...
The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can ...
Print a single integer — the maximum possible number of candies Arkady can give to himself. Note that it is always possible to choose some valid $x$.
[ "20 4 5 2\n", "30 9 4 1\n" ]
[ "8\n", "4\n" ]
In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total...
1,500
[ { "input": "20 4 5 2", "output": "8" }, { "input": "30 9 4 1", "output": "4" }, { "input": "2 2 1 1", "output": "1" }, { "input": "42 20 5 29", "output": "5" }, { "input": "1000000000000000000 135 1000000000000000 1000", "output": "8325624421831635" }, { ...
1,524,682,108
4,408
Python 3
WRONG_ANSWER
TESTS
8
77
7,065,600
import math n, k, m, d = map(int, input().split()) s = max(n // k, m) for i in range(2, d+1): x = n // (k * (i-1) + 1) if x <= m: s = max(s, x * i) print(s)
Title: Greedy Arkady Time Limit: None seconds Memory Limit: None megabytes Problem Description: $k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away. The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arka...
```python import math n, k, m, d = map(int, input().split()) s = max(n // k, m) for i in range(2, d+1): x = n // (k * (i-1) + 1) if x <= m: s = max(s, x * i) print(s) ```
0
835
A
Key races
PROGRAMMING
800
[ "math" ]
null
null
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *...
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th...
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
[ "5 1 2 1 2\n", "3 3 1 1 1\n", "4 5 3 1 5\n" ]
[ "First\n", "Second\n", "Friendship\n" ]
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ...
500
[ { "input": "5 1 2 1 2", "output": "First" }, { "input": "3 3 1 1 1", "output": "Second" }, { "input": "4 5 3 1 5", "output": "Friendship" }, { "input": "1000 1000 1000 1000 1000", "output": "Friendship" }, { "input": "1 1 1 1 1", "output": "Friendship" }, ...
1,592,837,884
2,147,483,647
Python 3
OK
TESTS
32
109
0
s,v1,v2,t1,t2 = list(map(int,input().split())) a = 2*t1+s*v1 b = 2*t2+s*v2 if a < b: print("First") elif a > b: print("Second") elif a == b: print("Friendship")
Title: Key races Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t...
```python s,v1,v2,t1,t2 = list(map(int,input().split())) a = 2*t1+s*v1 b = 2*t2+s*v2 if a < b: print("First") elif a > b: print("Second") elif a == b: print("Friendship") ```
3
680
B
Bear and Finding Criminals
PROGRAMMING
1,000
[ "constructive algorithms", "implementation" ]
null
null
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he...
The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city.
Print the number of criminals Limak will catch.
[ "6 3\n1 1 1 0 1 0\n", "5 2\n0 0 0 1 0\n" ]
[ "3\n", "1\n" ]
In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red. Using the BCD gives Limak the following information: - There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There i...
1,000
[ { "input": "6 3\n1 1 1 0 1 0", "output": "3" }, { "input": "5 2\n0 0 0 1 0", "output": "1" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 1\n0", "output": "0" }, { "input": "9 3\n1 1 1 1 1 1 1 1 0", "output": "8" }, { "input": "9 5\n1 0 1 0 1 0...
1,619,101,316
2,147,483,647
Python 3
OK
TESTS
24
62
204,800
n,k=map(int,input().split()) k-=1 x=list(map(int,input().split())) y=[0]*n z=[0]*n for i in range(n): if x[i]==1: y[abs(i-k)]+=1 z[abs(i-k)]+=1 c=0 for i in range(n): if z[i]==y[i]: c+=z[i] print(c)
Title: Bear and Finding Criminals Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city...
```python n,k=map(int,input().split()) k-=1 x=list(map(int,input().split())) y=[0]*n z=[0]*n for i in range(n): if x[i]==1: y[abs(i-k)]+=1 z[abs(i-k)]+=1 c=0 for i in range(n): if z[i]==y[i]: c+=z[i] print(c) ```
3
2
A
Winner
PROGRAMMING
1,500
[ "hashing", "implementation" ]
A. Winner
1
64
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ...
Print the name of the winner.
[ "3\nmike 3\nandrew 5\nmike 2\n", "3\nandrew 3\nandrew 2\nmike 5\n" ]
[ "andrew\n", "andrew\n" ]
none
0
[ { "input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew" }, { "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew" }, { "input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "output": "kaxqybeultn" },...
1,689,949,113
2,147,483,647
PyPy 3-64
OK
TESTS
20
124
0
from sys import stdin input = lambda: stdin.readline().rstrip('\r\n') n=int(input()) p,q=[],{} for _ in range(n): a,b = input().split() q[a] = q.get(a,0)+int(b) p.append([a,q[a]]) maxi = max(q.values()) for i,j in p: if q[i]==maxi and j>=maxi: print(i) break
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes...
```python from sys import stdin input = lambda: stdin.readline().rstrip('\r\n') n=int(input()) p,q=[],{} for _ in range(n): a,b = input().split() q[a] = q.get(a,0)+int(b) p.append([a,q[a]]) maxi = max(q.values()) for i,j in p: if q[i]==maxi and j>=maxi: print(i) br...
3.938
787
A
The Monster
PROGRAMMING
1,200
[ "brute force", "math", "number theory" ]
null
null
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams at times *d*,<=*d*<=+<=*c*,<=*d*<=+<=2*c*,<=*d*<=+<=3*c*,<=.... The Monster will catch them if a...
The first line of input contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100). The second line contains two integers *c* and *d* (1<=≤<=*c*,<=*d*<=≤<=100).
Print the first time Rick and Morty will scream at the same time, or <=-<=1 if they will never scream at the same time.
[ "20 2\n9 19\n", "2 1\n16 12\n" ]
[ "82\n", "-1\n" ]
In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82. In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
500
[ { "input": "20 2\n9 19", "output": "82" }, { "input": "2 1\n16 12", "output": "-1" }, { "input": "39 52\n88 78", "output": "1222" }, { "input": "59 96\n34 48", "output": "1748" }, { "input": "87 37\n91 29", "output": "211" }, { "input": "11 81\n49 7", ...
1,490,282,672
1,172
Python 3
WRONG_ANSWER
TESTS
35
46
4,608,000
#/usr/bin/env python3 import sys import math a, b = map(int, sys.stdin.readline().split()) c, d = map(int, sys.stdin.readline().split()) if (b - d) % math.gcd(a, c) != 0: print(-1) else: for i in range(a): if (c * i - b + d) % a == 0: print(c * i + d) break
Title: The Monster Time Limit: None seconds Memory Limit: None megabytes Problem Description: A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams a...
```python #/usr/bin/env python3 import sys import math a, b = map(int, sys.stdin.readline().split()) c, d = map(int, sys.stdin.readline().split()) if (b - d) % math.gcd(a, c) != 0: print(-1) else: for i in range(a): if (c * i - b + d) % a == 0: print(c * i + d) b...
0
424
C
Magic Formulas
PROGRAMMING
1,600
[ "math" ]
null
null
People in the Tomskaya region like magic formulas very much. You can see some of them below. Imagine you are given a sequence of positive integer numbers *p*1, *p*2, ..., *p**n*. Lets write down some magic formulas: Here, "mod" means the operation of taking the residue after dividing. The expression means applying ...
The first line of the input contains the only integer *n* (1<=≤<=*n*<=≤<=106). The next line contains *n* integers: *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=2·109).
The only line of output should contain a single integer — the value of *Q*.
[ "3\n1 2 3\n" ]
[ "3\n" ]
none
1,500
[ { "input": "3\n1 2 3", "output": "3" }, { "input": "1\n0", "output": "0" }, { "input": "2\n65535 0", "output": "65534" }, { "input": "10\n1356106972 165139648 978829595 410669403 873711167 287346624 117863440 228957745 835903650 1575323015", "output": "948506286" }, {...
1,609,569,397
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
124
0
def magic(arr): q=[] for i in range(len(arr)): temp=arr[i] for j in range(1,len(arr)+1): temp=temp^((i+1)%j) print(temp) q.append(temp) ans=q[0] for i in range(1,len(q)): ans=ans^q[i] return ans a=input() lst=list(map(int,input().strip...
Title: Magic Formulas Time Limit: None seconds Memory Limit: None megabytes Problem Description: People in the Tomskaya region like magic formulas very much. You can see some of them below. Imagine you are given a sequence of positive integer numbers *p*1, *p*2, ..., *p**n*. Lets write down some magic formulas: He...
```python def magic(arr): q=[] for i in range(len(arr)): temp=arr[i] for j in range(1,len(arr)+1): temp=temp^((i+1)%j) print(temp) q.append(temp) ans=q[0] for i in range(1,len(q)): ans=ans^q[i] return ans a=input() lst=list(map(int,inp...
0
266
A
Stones on the Table
PROGRAMMING
800
[ "implementation" ]
null
null
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red...
Print a single integer — the answer to the problem.
[ "3\nRRG\n", "5\nRRRRR\n", "4\nBRBG\n" ]
[ "1\n", "4\n", "0\n" ]
none
500
[ { "input": "3\nRRG", "output": "1" }, { "input": "5\nRRRRR", "output": "4" }, { "input": "4\nBRBG", "output": "0" }, { "input": "1\nB", "output": "0" }, { "input": "2\nBG", "output": "0" }, { "input": "3\nBGB", "output": "0" }, { "input": "...
1,694,529,094
2,147,483,647
Python 3
OK
TESTS
34
92
0
a=b=0 input() for x in input(): a+=b==x b=x print(a)
Title: Stones on the Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ...
```python a=b=0 input() for x in input(): a+=b==x b=x print(a) ```
3
80
A
Panoramix's Prediction
PROGRAMMING
800
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t...
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
500
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", ...
1,580,143,500
2,147,483,647
Python 3
OK
TESTS
45
218
307,200
a,b=map(int,input().split());c=[];t=2 for i in list(range(b,a,-1)): t=2 while((t**2)<=i): if i%t==0:c.append(i);break else:t+=1 print("NO" if b-a-len(c)>1 or b in c else "YES")
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater t...
```python a,b=map(int,input().split());c=[];t=2 for i in list(range(b,a,-1)): t=2 while((t**2)<=i): if i%t==0:c.append(i);break else:t+=1 print("NO" if b-a-len(c)>1 or b in c else "YES") ```
3.944928
932
F
Escape Through Leaf
PROGRAMMING
2,700
[ "data structures", "dp", "geometry" ]
null
null
You are given a tree with *n* nodes (numbered from 1 to *n*) rooted at node 1. Also, each node has two values associated with it. The values for *i*-th node are *a**i* and *b**i*. You can jump from a node to any node in its subtree. The cost of one jump from node *x* to node *y* is the product of *a**x* and *b**y*. Th...
The first line of input contains an integer *n* (2<=≤<=*n*<=≤<=105) — the number of nodes in the tree. The second line contains *n* space-separated integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n*(<=-<=105<=<=≤<=<=*a**i*<=<=≤<=<=105). The third line contains *n* space-separated integers *b*1,<=<=*b*2,<=<=...,<=<=*b**n*(<=-<...
Output *n* space-separated integers, *i*-th of which denotes the minimum cost of a path from node *i* to reach any leaf.
[ "3\n2 10 -1\n7 -7 5\n2 3\n2 1\n", "4\n5 -10 5 7\n-8 -80 -3 -10\n2 1\n2 4\n1 3\n" ]
[ "10 50 0 ", "-300 100 0 0 " ]
In the first example, node 3 is already a leaf, so the cost is 0. For node 2, jump to node 3 with cost *a*<sub class="lower-index">2</sub> × *b*<sub class="lower-index">3</sub> = 50. For node 1, jump directly to node 3 with cost *a*<sub class="lower-index">1</sub> × *b*<sub class="lower-index">3</sub> = 10. In the sec...
2,500
[ { "input": "3\n2 10 -1\n7 -7 5\n2 3\n2 1", "output": "10 50 0 " }, { "input": "4\n5 -10 5 7\n-8 -80 -3 -10\n2 1\n2 4\n1 3", "output": "-300 100 0 0 " }, { "input": "5\n7 -8 -8 -3 -10\n6 1 -6 7 5\n3 1\n2 5\n1 4\n4 5", "output": "-42 0 0 -25 -10 " }, { "input": "6\n4 -8 9 -1 -2...
1,631,002,335
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> using namespace std; #define ll long long struct edge{ int ne,to; }a[200010]; struct node{ int ls,rs,v; }t[100010]; struct emm{ ll k,b; }qwq[100010]; int n,num,head[100010],rt[100010],A[100010],B[100010]; ll f[100010]; inline void add(int u,int v){ a[++num].ne=head[u]; a[num...
Title: Escape Through Leaf Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a tree with *n* nodes (numbered from 1 to *n*) rooted at node 1. Also, each node has two values associated with it. The values for *i*-th node are *a**i* and *b**i*. You can jump from a node to any no...
```python #include<bits/stdc++.h> using namespace std; #define ll long long struct edge{ int ne,to; }a[200010]; struct node{ int ls,rs,v; }t[100010]; struct emm{ ll k,b; }qwq[100010]; int n,num,head[100010],rt[100010],A[100010],B[100010]; ll f[100010]; inline void add(int u,int v){ a[++num].ne=head[u...
-1
414
B
Mashmokh and ACM
PROGRAMMING
1,400
[ "combinatorics", "dp", "number theory" ]
null
null
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced prog...
The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000).
Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7).
[ "3 2\n", "6 4\n", "2 1\n" ]
[ "5\n", "39\n", "2\n" ]
In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].
1,000
[ { "input": "3 2", "output": "5" }, { "input": "6 4", "output": "39" }, { "input": "2 1", "output": "2" }, { "input": "1478 194", "output": "312087753" }, { "input": "1415 562", "output": "953558593" }, { "input": "1266 844", "output": "735042656" ...
1,698,474,543
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
1,000
0
n, t = map(int, input().split()) arr = [] mod = 10**9+7 if t == 1: print(n) else: for i in range(1, n + 1): arr.append(n // i) for i in range(t-2): for j in range(1, n+1): i = j while (i<=n): i += j if i <= n: ...
Title: Mashmokh and ACM Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join h...
```python n, t = map(int, input().split()) arr = [] mod = 10**9+7 if t == 1: print(n) else: for i in range(1, n + 1): arr.append(n // i) for i in range(t-2): for j in range(1, n+1): i = j while (i<=n): i += j if i <= n: ...
0
733
B
Parade
PROGRAMMING
1,100
[ "math" ]
null
null
Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits beg...
The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of columns. The next *n* lines contain the pairs of integers *l**i* and *r**i* (1<=≤<=*l**i*,<=*r**i*<=≤<=500) — the number of soldiers in the *i*-th column which start to march from the left or the right leg respectively.
Print single integer *k* — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached. Consider that columns are numbered from 1 to *n* in the order they are given in the input data. If there are several answers, print any of them.
[ "3\n5 6\n8 9\n10 3\n", "2\n6 5\n5 6\n", "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32\n" ]
[ "3\n", "1\n", "0\n" ]
In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5. If you give the order to change the leg to the third co...
1,000
[ { "input": "3\n5 6\n8 9\n10 3", "output": "3" }, { "input": "2\n6 5\n5 6", "output": "1" }, { "input": "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32", "output": "0" }, { "input": "2\n500 499\n500 500", "output": "0" }, { "input": "1\n139 252", "output": "0" }, { ...
1,640,454,008
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
a=int(input()) x=0 y=0 o=0 p=0 for i in range(a): d,c=map(int,input().split()) o+=d p+=c if x>d-c: x=d-c elif y<d-c: y=d-c print(max(abs(x),abs(y),abs(o-p))
Title: Parade Time Limit: None seconds Memory Limit: None megabytes Problem Description: Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should...
```python a=int(input()) x=0 y=0 o=0 p=0 for i in range(a): d,c=map(int,input().split()) o+=d p+=c if x>d-c: x=d-c elif y<d-c: y=d-c print(max(abs(x),abs(y),abs(o-p)) ```
-1
489
C
Given Length and Sum of Digits...
PROGRAMMING
1,400
[ "dp", "greedy", "implementation" ]
null
null
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers.
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
[ "2 15\n", "3 0\n" ]
[ "69 96\n", "-1 -1\n" ]
none
1,500
[ { "input": "2 15", "output": "69 96" }, { "input": "3 0", "output": "-1 -1" }, { "input": "2 1", "output": "10 10" }, { "input": "3 10", "output": "109 910" }, { "input": "100 100", "output": "1000000000000000000000000000000000000000000000000000000000000000000...
1,676,428,831
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
entered_list = input().split() m = int(entered_list[0]) s = int(float(entered_list[1])) sum = 0 min = 0 c = True num = pow(10, m) for i in range(num): f = i l = i while f>1: k = f % 10 f = f / 10 sum+= k if c == True and sum == s and l!= 0 and s...
Title: Given Length and Sum of Digits... Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should ...
```python entered_list = input().split() m = int(entered_list[0]) s = int(float(entered_list[1])) sum = 0 min = 0 c = True num = pow(10, m) for i in range(num): f = i l = i while f>1: k = f % 10 f = f / 10 sum+= k if c == True and sum == s and l...
0
698
A
Vacations
PROGRAMMING
1,400
[ "dp" ]
null
null
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is close...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co...
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days.
[ "4\n1 3 2 0\n", "7\n1 3 3 2 1 2 3\n", "2\n2 2\n" ]
[ "2\n", "0\n", "1\n" ]
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya ca...
500
[ { "input": "4\n1 3 2 0", "output": "2" }, { "input": "7\n1 3 3 2 1 2 3", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "1\n0", "output": "1" }, { "input": "10\n0 0 1 1 0 0 0 0 1 0", "output": "8" }, { "input": "100\n3 2 3 3 3 2 3 1 ...
1,530,859,199
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
108
0
days = int(input()) lst = list(map(int,input().split())) rest = [0] if lst[0] == 1: gym, cont = [0], [1] elif lst[0] == 2: gym, cont = [1], [0] else: gym, cont = [1], [1] for i in range(1,days): rest.append(max(rest[-1],gym[-1],cont[-1])) if lst[i] == 3: cont.append(max(rest[-2],...
Title: Vacations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int...
```python days = int(input()) lst = list(map(int,input().split())) rest = [0] if lst[0] == 1: gym, cont = [0], [1] elif lst[0] == 2: gym, cont = [1], [0] else: gym, cont = [1], [1] for i in range(1,days): rest.append(max(rest[-1],gym[-1],cont[-1])) if lst[i] == 3: cont.append(max...
0
158
A
Next Round
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate...
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence...
Output the number of participants who advance to the next round.
[ "8 5\n10 9 8 7 7 7 5 5\n", "4 2\n0 0 0 0\n" ]
[ "6\n", "0\n" ]
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
500
[ { "input": "8 5\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "4 2\n0 0 0 0", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "5" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "1 1\n10", "output": "1" }, { "input": "17 14\n16 15...
1,699,542,908
2,147,483,647
Python 3
OK
TESTS
50
92
0
n, k = map(int, input().split()) scores = list(map(int, input().split())) mark = scores[k - 1] count = sum(1 for m in scores if m >= mark and m > 0) print(count)
Title: Next Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* p...
```python n, k = map(int, input().split()) scores = list(map(int, input().split())) mark = scores[k - 1] count = sum(1 for m in scores if m >= mark and m > 0) print(count) ```
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,693,225,128
2,147,483,647
Python 3
OK
TESTS
35
92
0
def max_dominoes(M, N): if M % 2 == 1 or N % 2 == 1: return (M * N) // 2 else: return (M * N) // 2 # Read input M, N = map(int, input().split()) # Calculate and print the maximum number of dominoes print(max_dominoes(M, N))
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python def max_dominoes(M, N): if M % 2 == 1 or N % 2 == 1: return (M * N) // 2 else: return (M * N) // 2 # Read input M, N = map(int, input().split()) # Calculate and print the maximum number of dominoes print(max_dominoes(M, N)) ```
3.977
780
A
Andryusha and Socks
PROGRAMMING
800
[ "implementation" ]
null
null
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ...
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs. The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ...
Print single integer — the maximum number of socks that were on the table at the same time.
[ "1\n1 1\n", "3\n2 1 1 3 2 3\n" ]
[ "1\n", "2\n" ]
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - ...
500
[ { "input": "1\n1 1", "output": "1" }, { "input": "3\n2 1 1 3 2 3", "output": "2" }, { "input": "5\n5 1 3 2 4 3 1 2 4 5", "output": "5" }, { "input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7", "output": "6" }, { "input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ...
1,592,891,510
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
3
2,000
34,099,200
input();li = list(map(int , input().split())) li2 = [] x = len(li2) for i in li: if i in li2: li2.remove(i) else: li2.append(i) x = max(x, len(li2)) print(x)
Title: Andryusha and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere...
```python input();li = list(map(int , input().split())) li2 = [] x = len(li2) for i in li: if i in li2: li2.remove(i) else: li2.append(i) x = max(x, len(li2)) print(x) ```
0
935
A
Fafa and his Company
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em...
The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company.
Print a single integer representing the answer to the problem.
[ "2\n", "10\n" ]
[ "1\n", "3\n" ]
In the second sample Fafa has 3 ways: - choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
500
[ { "input": "2", "output": "1" }, { "input": "10", "output": "3" }, { "input": "3", "output": "1" }, { "input": "4", "output": "2" }, { "input": "6", "output": "3" }, { "input": "13", "output": "1" }, { "input": "100000", "output": "35" ...
1,637,335,792
2,147,483,647
Python 3
OK
TESTS
33
61
0
n=int(input()) c=0 if n<=2: print(1) else: for i in range(1,(n//2)+1): if n%i==0: c+=1 print(c)
Title: Fafa and his Company Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp...
```python n=int(input()) c=0 if n<=2: print(1) else: for i in range(1,(n//2)+1): if n%i==0: c+=1 print(c) ```
3
989
A
A Blend of Springtime
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone." "But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic. The landscape can be expressed as a row of consecutive cells, each of which either contains a flower o...
The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise. You can print each letter in any case (upper or lower).
[ ".BAC.\n", "AA..CB\n" ]
[ "Yes\n", "No\n" ]
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it. In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
500
[ { "input": ".BAC.", "output": "Yes" }, { "input": "AA..CB", "output": "No" }, { "input": ".", "output": "No" }, { "input": "ACB.AAAAAA", "output": "Yes" }, { "input": "B.BC.BBBCA", "output": "Yes" }, { "input": "BA..CAB..B", "output": "Yes" }, ...
1,623,921,789
2,147,483,647
Python 3
OK
TESTS
37
62
0
def f(l,s): for i in l: if i in s: return "Yes" return "No" s=input() l=["ABC","BAC","BCA","ACB","CBA","CAB"] print(f(l,s))
Title: A Blend of Springtime Time Limit: None seconds Memory Limit: None megabytes Problem Description: "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone." "But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimisti...
```python def f(l,s): for i in l: if i in s: return "Yes" return "No" s=input() l=["ABC","BAC","BCA","ACB","CBA","CAB"] print(f(l,s)) ```
3
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "1000022...
1,683,557,556
2,147,483,647
Python 3
OK
TESTS
30
92
0
s = input() sol = "" i = 0 while i < len(s): if s[i] == ".": sol += '0' else: i += 1 if s[i] == ".": sol += '1' else: sol += '2' i += 1 print(sol)
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ...
```python s = input() sol = "" i = 0 while i < len(s): if s[i] == ".": sol += '0' else: i += 1 if s[i] == ".": sol += '1' else: sol += '2' i += 1 print(sol) ```
3.977
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If...
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "outp...
1,689,669,729
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
try: n = input() demo = 0 flag = 0 print(len(n)) for i in range(len(n)): if i<=(len(n)-2): if int(n[i]) == int(n[i+1]): demo+=1 if demo>=6: flag = 1 else: demo = 0 if flag==1: ...
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A...
```python try: n = input() demo = 0 flag = 0 print(len(n)) for i in range(len(n)): if i<=(len(n)-2): if int(n[i]) == int(n[i+1]): demo+=1 if demo>=6: flag = 1 else: demo = 0 if flag==...
0
612
A
The Text Splitting
PROGRAMMING
1,300
[ "brute force", "implementation", "strings" ]
null
null
You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*. For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". Note it is allowed to split the string *s* to the st...
The first line contains three positive integers *n*,<=*p*,<=*q* (1<=≤<=*p*,<=*q*<=≤<=*n*<=≤<=100). The second line contains the string *s* consists of lowercase and uppercase latin letters and digits.
If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1". Otherwise in the first line print integer *k* — the number of strings in partition of *s*. Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The...
[ "5 2 3\nHello\n", "10 9 5\nCodeforces\n", "6 4 5\nPrivet\n", "8 1 1\nabacabac\n" ]
[ "2\nHe\nllo\n", "2\nCodef\norces\n", "-1\n", "8\na\nb\na\nc\na\nb\na\nc\n" ]
none
0
[ { "input": "5 2 3\nHello", "output": "2\nHe\nllo" }, { "input": "10 9 5\nCodeforces", "output": "2\nCodef\norces" }, { "input": "6 4 5\nPrivet", "output": "-1" }, { "input": "8 1 1\nabacabac", "output": "8\na\nb\na\nc\na\nb\na\nc" }, { "input": "1 1 1\n1", "ou...
1,536,716,081
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
0
n=int(input()) p=int(input()) q=int(input()) s=input() x=s.split() for p in x: print(x)
Title: The Text Splitting Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*. For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "H...
```python n=int(input()) p=int(input()) q=int(input()) s=input() x=s.split() for p in x: print(x) ```
-1
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,662,972,934
2,147,483,647
Python 3
OK
TESTS
3
62
0
n = int(input()) ans = n * [0] for i in range(n): m = int(input()) if (360 % (180 - m) == 0): ans[i] = 1 else: continue for i in range(n): if ans[i] == 1: print('YES') else: 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 n = int(input()) ans = n * [0] for i in range(n): m = int(input()) if (360 % (180 - m) == 0): ans[i] = 1 else: continue for i in range(n): if ans[i] == 1: print('YES') else: print('NO') ```
3
912
B
New Year's Eve
PROGRAMMING
1,300
[ "bitmasks", "constructive algorithms", "number theory" ]
null
null
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness. The choice of candies has a d...
The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018).
Output one number — the largest possible xor-sum.
[ "4 3\n", "6 6\n" ]
[ "7\n", "7\n" ]
In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7. In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.
1,000
[ { "input": "4 3", "output": "7" }, { "input": "6 6", "output": "7" }, { "input": "2 2", "output": "3" }, { "input": "1022 10", "output": "1023" }, { "input": "415853337373441 52", "output": "562949953421311" }, { "input": "75 12", "output": "127" ...
1,669,621,261
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
46
0
n, k = map(int, input().split()) sum = 0 for i in range(k): x = pow(2, i) if x <= n: sum += x else: break print(sum)
Title: New Year's Eve Time Limit: None seconds Memory Limit: None megabytes Problem Description: Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* co...
```python n, k = map(int, input().split()) sum = 0 for i in range(k): x = pow(2, i) if x <= n: sum += x else: break print(sum) ```
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,655,463,776
2,147,483,647
PyPy 3-64
OK
TESTS
102
62
0
from io import BytesIO from os import fstat, read from sys import stdout def fast_input(file_no = 0): byte_stream = BytesIO(read(file_no, fstat(file_no).st_size)) return byte_stream #fi = open(PATH_INPUT, "r") #io_byte_input = fast_input(fi.fileno()) io_byte_input = fast_input() #fi.close() f_in...
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 from io import BytesIO from os import fstat, read from sys import stdout def fast_input(file_no = 0): byte_stream = BytesIO(read(file_no, fstat(file_no).st_size)) return byte_stream #fi = open(PATH_INPUT, "r") #io_byte_input = fast_input(fi.fileno()) io_byte_input = fast_input() #fi.clo...
3.9845
271
A
Beautiful Year
PROGRAMMING
800
[ "brute force" ]
null
null
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on...
The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number.
Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists.
[ "1987\n", "2013\n" ]
[ "2013\n", "2014\n" ]
none
500
[ { "input": "1987", "output": "2013" }, { "input": "2013", "output": "2014" }, { "input": "1000", "output": "1023" }, { "input": "1001", "output": "1023" }, { "input": "1234", "output": "1235" }, { "input": "5555", "output": "5601" }, { "inp...
1,692,419,153
2,147,483,647
PyPy 3
OK
TESTS
27
154
0
input_year = int( input() ) year = input_year + 1 searching = True while searching: searching = False str_year = str(year) for digit in str_year: if str_year.count(digit) > 1: searching = True break if not searching: break year += 1 ...
Title: Beautiful Year Time Limit: None seconds Memory Limit: None megabytes Problem Description: It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: give...
```python input_year = int( input() ) year = input_year + 1 searching = True while searching: searching = False str_year = str(year) for digit in str_year: if str_year.count(digit) > 1: searching = True break if not searching: break ye...
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,661,101,088
2,147,483,647
Python 3
OK
TESTS
84
46
0
input() T = set(map(int, input().split())) print('YES' if any(t-1 in T and t+1 in T for t in T) else 'NO')
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 input() T = set(map(int, input().split())) print('YES' if any(t-1 in T and t+1 in T for t in T) else 'NO') ```
3
493
A
Vasya and Football
PROGRAMMING
1,300
[ "implementation" ]
null
null
Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card. Vasya is watching a recorded football match now and makes notes of all the fouls tha...
The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number *n* (1<=≤<=*n*<=≤<=9...
For each event when a player received his first red card in a chronological order print a string containing the following information: - The name of the team to which the player belongs; - the player's number in his team; - the minute when he received the card. If no player received a card, then you do not need to...
[ "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r\n" ]
[ "MC 25 70\nMC 42 82\nCSKA 13 90\n" ]
none
500
[ { "input": "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r", "output": "MC 25 70\nMC 42 82\nCSKA 13 90" }, { "input": "REAL\nBARCA\n3\n27 h 7 y\n44 a 10 y\n87 h 3 r", "output": "REAL 3 87" }, { "input": "MASFF\nSAFBDSRG\n5\n1 ...
1,607,338,983
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
139
0
home = input() away= input() n = int(input()) arr = [] for _ in range(n): arr.append(list(input().split(' '))) foul = [] visited = [] rep = [] for i in range(n): if arr[i][3]=='r': foul.append(arr[i]) elif arr[i][2] in visited and arr[i][2]not in rep: foul.append(arr[i]) rep.append(...
Title: Vasya and Football Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically re...
```python home = input() away= input() n = int(input()) arr = [] for _ in range(n): arr.append(list(input().split(' '))) foul = [] visited = [] rep = [] for i in range(n): if arr[i][3]=='r': foul.append(arr[i]) elif arr[i][2] in visited and arr[i][2]not in rep: foul.append(arr[i]) r...
0
975
B
Mancala
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next ...
The only line contains 14 integers $a_1, a_2, \ldots, a_{14}$ ($0 \leq a_i \leq 10^9$) — the number of stones in each hole. It is guaranteed that for any $i$ ($1\leq i \leq 14$) $a_i$ is either zero or odd, and there is at least one stone in the board.
Output one integer, the maximum possible score after one move.
[ "0 1 1 0 0 0 0 0 0 7 0 0 0 0\n", "5 1 1 1 1 0 0 0 0 0 0 0 0 0\n" ]
[ "4\n", "8\n" ]
In the first test case the board after the move from the hole with $7$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $4$.
1,000
[ { "input": "0 1 1 0 0 0 0 0 0 7 0 0 0 0", "output": "4" }, { "input": "5 1 1 1 1 0 0 0 0 0 0 0 0 0", "output": "8" }, { "input": "10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 1", "output": "54294" }, { "input": "0 0 0 0 0 0 0 0 0 0 0 0 0 15", ...
1,630,887,151
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
6,963,200
def main(): board = [int(i) for i in input().split()] xa,ya,cxa,cya=0,0,0,0 for i in board: if(i%2==0): xa+=i cxa+=1 else: ya+=i cya+=1 indx=0 maxi=0 for i in board: if(i%2!=0): print(i) ...
Title: Mancala Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. ...
```python def main(): board = [int(i) for i in input().split()] xa,ya,cxa,cya=0,0,0,0 for i in board: if(i%2==0): xa+=i cxa+=1 else: ya+=i cya+=1 indx=0 maxi=0 for i in board: if(i%2!=0): print(i)...
0
975
A
Aramic script
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
In Aramic language words can only represent objects. Words in Aramic have special properties: - A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$...
The first line contains one integer $n$ ($1 \leq n \leq 10^3$) — the number of words in the script. The second line contains $n$ words $s_1, s_2, \ldots, s_n$ — the script itself. The length of each string does not exceed $10^3$. It is guaranteed that all characters of the strings are small latin letters.
Output one integer — the number of different objects mentioned in the given ancient Aramic script.
[ "5\na aa aaa ab abb\n", "3\namer arem mrea\n" ]
[ "2", "1" ]
In the first test, there are two objects mentioned. The roots that represent them are "a","ab". In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer".
500
[ { "input": "5\na aa aaa ab abb", "output": "2" }, { "input": "3\namer arem mrea", "output": "1" }, { "input": "10\nbda bbb cda dca dda dcb bcd dcb ada ddd", "output": "6" }, { "input": "2\nfhjlqs aceginpr", "output": "2" }, { "input": "2\nbcdfghimn efghijlmo", ...
1,546,108,833
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
108
0
t=int(input()) l=list(input().split()) a=set() for j in range(t): x=''.join(list(set(list(l[j])))) a.add(x) print(len(a))
Title: Aramic script Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Aramic language words can only represent objects. Words in Aramic have special properties: - A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the ...
```python t=int(input()) l=list(input().split()) a=set() for j in range(t): x=''.join(list(set(list(l[j])))) a.add(x) print(len(a)) ```
0
351
B
Jeff and Furik
PROGRAMMING
1,900
[ "combinatorics", "dp", "probabilities" ]
null
null
Jeff has become friends with Furik. Now these two are going to play one quite amusing game. At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of *n* numbers: *p*1, *p*2, ..., *p**n*. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=3000). The next line contains *n* distinct integers *p*1, *p*2, ..., *p**n* (1<=≤<=*p**i*<=≤<=*n*) — the permutation *p*. The numbers are separated by spaces.
In a single line print a single real value — the answer to the problem. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6.
[ "2\n1 2\n", "5\n3 5 2 4 1\n" ]
[ "0.000000\n", "13.000000\n" ]
In the first test the sequence is already sorted, so the answer is 0.
1,000
[ { "input": "2\n1 2", "output": "0.000000" }, { "input": "5\n3 5 2 4 1", "output": "13.000000" }, { "input": "16\n6 15 3 8 7 11 9 10 2 13 4 14 1 16 5 12", "output": "108.000000" }, { "input": "9\n1 7 8 5 3 4 6 9 2", "output": "33.000000" }, { "input": "5\n2 3 4 5 1...
1,692,331,690
2,147,483,647
PyPy 3-64
OK
TESTS
25
156
2,048,000
import sys input = sys.stdin.readline MOD=10**9+7 if __name__ == '__main__': n=int(input()) arr=list(map(int, input().split())) cnt=0 for i in range(n-1): for j in range(i+1,n): if arr[j]<arr[i]: cnt +=1 print((cnt*2-(cnt%2))*1.0)
Title: Jeff and Furik Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jeff has become friends with Furik. Now these two are going to play one quite amusing game. At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of *n* numbers: *p*1, *p*2, ....
```python import sys input = sys.stdin.readline MOD=10**9+7 if __name__ == '__main__': n=int(input()) arr=list(map(int, input().split())) cnt=0 for i in range(n-1): for j in range(i+1,n): if arr[j]<arr[i]: cnt +=1 print((cnt*2-(cnt%2))*1.0) ```
3
776
A
A Serial Killer
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected ...
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days. Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and t...
Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
[ "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n", "icm codeforces\n1\ncodeforces technex\n" ]
[ "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n", "icm codeforces\nicm technex\n" ]
In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
500
[ { "input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler" }, { "input": "icm codeforces\n1\ncodeforces technex", "output": "icm codeforces\nicm technex" }, { "input": "a b\n3\na c\n...
1,617,532,497
2,147,483,647
PyPy 3
OK
TESTS
57
155
3,276,800
str1,str2 = map(str,input().split()) n = int(input()) print(str1,str2) for each in range(n): murdered,replace = map(str,input().split()) if(str1==murdered): str1 = replace print(str1,str2) else: str2 = replace print(str1,str2)
Title: A Serial Killer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The...
```python str1,str2 = map(str,input().split()) n = int(input()) print(str1,str2) for each in range(n): murdered,replace = map(str,input().split()) if(str1==murdered): str1 = replace print(str1,str2) else: str2 = replace print(str1,str2) ```
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,662,430,670
2,147,483,647
Python 3
OK
TESTS
35
92
0
k,n=map(int,input().split()) f=k*n print(f//2)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python k,n=map(int,input().split()) f=k*n print(f//2) ```
3.977
298
B
Sail
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation" ]
null
null
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*). - If the wind blows to the east, the boat will ...
The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different. The second line contains *t* characters, the *i*-th character is the wind blowing direction at the...
If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).
[ "5 0 0 1 1\nSESNW\n", "10 5 3 3 6\nNENSWESNEE\n" ]
[ "4\n", "-1\n" ]
In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4. In the second sample, they cannot sail to the destination.
500
[ { "input": "5 0 0 1 1\nSESNW", "output": "4" }, { "input": "10 5 3 3 6\nNENSWESNEE", "output": "-1" }, { "input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS", "output": "13" }, { "input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSS...
1,561,819,951
2,147,483,647
PyPy 3
OK
TESTS
43
312
2,764,800
t, sx, sy, fx, fy = map(int, input().split()) m = input() ans = 0 for i in m: if sx < fx and i == 'E': sx += 1 if sx > fx and i == 'W': sx -= 1 if sy < fy and i == 'N': sy += 1 if sy > fy and i == 'S': sy -= 1 ans += 1 if sx == fx and sy == fy: ...
Title: Sail Time Limit: None seconds Memory Limit: None megabytes Problem Description: The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assu...
```python t, sx, sy, fx, fy = map(int, input().split()) m = input() ans = 0 for i in m: if sx < fx and i == 'E': sx += 1 if sx > fx and i == 'W': sx -= 1 if sy < fy and i == 'N': sy += 1 if sy > fy and i == 'S': sy -= 1 ans += 1 if sx == fx and sy == ...
3
701
C
They Are Everywhere
PROGRAMMING
1,500
[ "binary search", "strings", "two pointers" ]
null
null
Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is ...
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of flats in the house. The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*.
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
[ "3\nAaA\n", "7\nbcAAcbc\n", "6\naaBCCe\n" ]
[ "2\n", "3\n", "5\n" ]
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2. In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6. In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
1,000
[ { "input": "3\nAaA", "output": "2" }, { "input": "7\nbcAAcbc", "output": "3" }, { "input": "6\naaBCCe", "output": "5" }, { "input": "1\nA", "output": "1" }, { "input": "1\ng", "output": "1" }, { "input": "52\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ...
1,670,951,549
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> using namespace std; #define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define ll long long int #define F first #define S second const int maxn = 1e5 + 100; int a[maxn], cnt[60]; int main(){ fast_io; int n; cin >> n; string s; cin >> s; for(int i = 0;...
Title: They Are Everywhere Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each ...
```python #include <bits/stdc++.h> using namespace std; #define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define ll long long int #define F first #define S second const int maxn = 1e5 + 100; int a[maxn], cnt[60]; int main(){ fast_io; int n; cin >> n; string s; cin >> s; for(...
-1
777
A
Shell Game
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "math" ]
null
null
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator. The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements.
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
[ "4\n2\n", "1\n1\n" ]
[ "1\n", "0\n" ]
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements. 1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. Th...
500
[ { "input": "4\n2", "output": "1" }, { "input": "1\n1", "output": "0" }, { "input": "2\n2", "output": "0" }, { "input": "3\n1", "output": "1" }, { "input": "3\n2", "output": "0" }, { "input": "3\n0", "output": "2" }, { "input": "2000000000\n...
1,638,342,726
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
31
0
a, n, x = [], int(input()), int(input()) if x == 2: a = [2, 1, 0, 0, 1, 2] elif x == 1: a = [1, 2, 2, 1, 0, 0] else: a = [0, 0, 1, 2, 2, 1] print(a[(n - 1) % 6])
Title: Shell Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball ben...
```python a, n, x = [], int(input()), int(input()) if x == 2: a = [2, 1, 0, 0, 1, 2] elif x == 1: a = [1, 2, 2, 1, 0, 0] else: a = [0, 0, 1, 2, 2, 1] print(a[(n - 1) % 6]) ```
0
363
B
Fence
PROGRAMMING
1,100
[ "brute force", "dp" ]
null
null
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights. Polycarpus has bought a posh piano and is thinking about how to get it into the h...
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th...
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
[ "7 3\n1 2 6 1 1 7 1\n" ]
[ "3\n" ]
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
1,000
[ { "input": "7 3\n1 2 6 1 1 7 1", "output": "3" }, { "input": "1 1\n100", "output": "1" }, { "input": "2 1\n10 20", "output": "1" }, { "input": "10 5\n1 2 3 1 2 2 3 1 4 5", "output": "1" }, { "input": "10 2\n3 1 4 1 4 6 2 1 4 6", "output": "7" }, { "inp...
1,676,460,442
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
n, k = map(int, input().split()) arr = [int(a) for a in input().split()] tmp_arr = [] for i in range(k): tmp_arr.append(arr[i]) min_sum = sum(tmp_arr) res = 0 cur_ind = k tmp_sum = min_sum count = 0 for i in range(1, n - k): tmp_sum -= arr[count] tmp_sum += arr[cur_ind] coun...
Title: Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ...
```python n, k = map(int, input().split()) arr = [int(a) for a in input().split()] tmp_arr = [] for i in range(k): tmp_arr.append(arr[i]) min_sum = sum(tmp_arr) res = 0 cur_ind = k tmp_sum = min_sum count = 0 for i in range(1, n - k): tmp_sum -= arr[count] tmp_sum += arr[cur_ind]...
0
820
A
Mister B and Book Reading
PROGRAMMING
900
[ "implementation" ]
null
null
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages. At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at ...
First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≤<=*c*<=≤<=1000, 0<=≤<=*l*<=&lt;<=*v*0<=≤<=*v*1<=≤<=1000, 0<=≤<=*a*<=≤<=1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages fo...
Print one integer — the number of days Mister B needed to finish the book.
[ "5 5 10 5 4\n", "12 4 12 4 1\n", "15 1 100 0 0\n" ]
[ "1\n", "3\n", "15\n" ]
In the first sample test the book contains 5 pages, so Mister B read it right at the first day. In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book. In third sample test every day Mister B read 1 page of the book, so he finished...
500
[ { "input": "5 5 10 5 4", "output": "1" }, { "input": "12 4 12 4 1", "output": "3" }, { "input": "15 1 100 0 0", "output": "15" }, { "input": "1 1 1 0 0", "output": "1" }, { "input": "1000 999 1000 1000 998", "output": "2" }, { "input": "1000 2 2 5 1", ...
1,498,574,536
436
Python 3
OK
TESTS
110
77
5,529,600
c, v, v1, a, l = map(int, input().split()) for i in range(1, 1000000): c -= v if i > 1: c += l if c <= 0: print(i) break v += a v = min(v, v1)
Title: Mister B and Book Reading Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages. At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, ...
```python c, v, v1, a, l = map(int, input().split()) for i in range(1, 1000000): c -= v if i > 1: c += l if c <= 0: print(i) break v += a v = min(v, v1) ```
3
540
A
Combination Lock
PROGRAMMING
800
[ "implementation" ]
null
null
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock. The second line contains a string of *n* digits — the original state of the disks. The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
[ "5\n82195\n64723\n" ]
[ "13\n" ]
In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32...
500
[ { "input": "5\n82195\n64723", "output": "13" }, { "input": "12\n102021090898\n010212908089", "output": "16" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "10\n0728592530\n1362615763", "output": "27" }, { ...
1,596,387,325
2,147,483,647
Python 3
OK
TESTS
43
109
6,656,000
n=int(input()) s=input() o=input() f="01234567890123456789" ans=0 for i in range(n): si=int(s[i]) oi=int(o[i]) ans=ans+min(abs(si-oi),abs(si-(10+oi)),abs(si+10-oi)) print(ans)
Title: Combination Lock Time Limit: None seconds Memory Limit: None megabytes Problem Description: Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is ...
```python n=int(input()) s=input() o=input() f="01234567890123456789" ans=0 for i in range(n): si=int(s[i]) oi=int(o[i]) ans=ans+min(abs(si-oi),abs(si-(10+oi)),abs(si+10-oi)) print(ans) ```
3
29
C
Mail Stamps
PROGRAMMING
1,700
[ "data structures", "dfs and similar", "graphs", "implementation" ]
C. Mail Stamps
2
256
One day Bob got a letter in an envelope. Bob knows that when Berland's post officers send a letter directly from city «A» to city «B», they stamp it with «A B», or «B A». Unfortunately, often it is impossible to send a letter directly from the city of the sender to the city of the receiver, that's why the letter is sen...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of mail stamps on the envelope. Then there follow *n* lines with two integers each — description of the stamps. Each stamp is described with indexes of the cities between which a letter is sent. The indexes of cities are integers from 1 to 109. Indexes of...
Output *n*<=+<=1 numbers — indexes of cities in one of the two possible routes of the letter.
[ "2\n1 100\n100 2\n", "3\n3 1\n100 2\n3 2\n" ]
[ "2 100 1 ", "100 2 3 1 " ]
none
1,500
[ { "input": "2\n1 100\n100 2", "output": "2 100 1 " }, { "input": "3\n3 1\n100 2\n3 2", "output": "100 2 3 1 " }, { "input": "3\n458744979 589655889\n248228386 824699605\n458744979 824699605", "output": "589655889 458744979 824699605 248228386 " }, { "input": "4\n90104473 2210...
1,630,674,913
2,147,483,647
Python 3
OK
TESTS
20
1,310
28,672,000
from _collections import deque n=int(input())-1 x,y=map(int,input().split()) q=deque([x,y]) w={x:{y},y:{x}} l={x,y} for i in range(n): x,y=map(int,input().split()) if x in w:w[x].add(y) else:w[x]={y} if y in w:w[y].add(x) else:w[y]={x} while len(w[q[-1]])>1: for i in w[q[-1]]: ...
Title: Mail Stamps Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Bob got a letter in an envelope. Bob knows that when Berland's post officers send a letter directly from city «A» to city «B», they stamp it with «A B», or «B A». Unfortunately, often it is impossible to send a letter d...
```python from _collections import deque n=int(input())-1 x,y=map(int,input().split()) q=deque([x,y]) w={x:{y},y:{x}} l={x,y} for i in range(n): x,y=map(int,input().split()) if x in w:w[x].add(y) else:w[x]={y} if y in w:w[y].add(x) else:w[y]={x} while len(w[q[-1]])>1: for i in w[q[-...
3.619094
119
A
Epic Game
PROGRAMMING
800
[ "implementation" ]
null
null
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take...
The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
[ "3 5 9\n", "1 1 100\n" ]
[ "0", "1" ]
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b...
500
[ { "input": "3 5 9", "output": "0" }, { "input": "1 1 100", "output": "1" }, { "input": "23 12 16", "output": "1" }, { "input": "95 26 29", "output": "1" }, { "input": "73 32 99", "output": "1" }, { "input": "1 1 1", "output": "0" }, { "inpu...
1,584,694,031
2,147,483,647
PyPy 3
OK
TESTS
45
310
0
import sys import math #to read string get_string = lambda: sys.stdin.readline().strip() #to read list of integers get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) ) #to read integers get_int = lambda: int(sys.stdin.readline()) #to print fast pt = lambda x: sys.stdout.write(str(x)+'...
Title: Epic Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto...
```python import sys import math #to read string get_string = lambda: sys.stdin.readline().strip() #to read list of integers get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) ) #to read integers get_int = lambda: int(sys.stdin.readline()) #to print fast pt = lambda x: sys.stdout.writ...
3
867
A
Between the Offices
PROGRAMMING
800
[ "implementation" ]
null
null
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane. You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem...
The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days. The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given...
Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise. You can print each letter in any case (upper or lower).
[ "4\nFSSF\n", "2\nSF\n", "10\nFFFFFFFFFF\n", "10\nSSFFSFFSFF\n" ]
[ "NO\n", "YES\n", "NO\n", "YES\n" ]
In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO". In the second example you just flew from Seattle to San Francisco, so the answer is "YES". In the third example you staye...
500
[ { "input": "4\nFSSF", "output": "NO" }, { "input": "2\nSF", "output": "YES" }, { "input": "10\nFFFFFFFFFF", "output": "NO" }, { "input": "10\nSSFFSFFSFF", "output": "YES" }, { "input": "20\nSFSFFFFSSFFFFSSSSFSS", "output": "NO" }, { "input": "20\nSSFFF...
1,577,618,533
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
93
0
n = int(input()) t = input() f = 0 s = 0 for i in range(n): if t[i] == 'S': s += 1 else: f += 1 if s > f: print('YES') else: print('NO')
Title: Between the Offices Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane. You prefer flying from Seattle to San Franci...
```python n = int(input()) t = input() f = 0 s = 0 for i in range(n): if t[i] == 'S': s += 1 else: f += 1 if s > f: print('YES') else: print('NO') ```
0
637
B
Chat Order
PROGRAMMING
1,200
[ "*special", "binary search", "constructive algorithms", "data structures", "sortings" ]
null
null
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then...
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
[ "4\nalex\nivan\nroman\nivan\n", "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n" ]
[ "ivan\nroman\nalex\n", "alina\nmaria\nekaterina\ndarya\n" ]
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows: 1. alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows: 1. ivan 1. alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows: 1. roman 1...
1,000
[ { "input": "4\nalex\nivan\nroman\nivan", "output": "ivan\nroman\nalex" }, { "input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina", "output": "alina\nmaria\nekaterina\ndarya" }, { "input": "1\nwdi", "output": "wdi" }, { "input": "2\nypg\nypg", "outpu...
1,463,413,977
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
171
4,608,000
n=int(input()) chat={} for i in range(n): name=input() chat[name]=i chat={v:k for k,v in chat.items()} x=list(chat.keys()) x.reverse() for m in x: print(chat[m])
Title: Chat Order Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The rela...
```python n=int(input()) chat={} for i in range(n): name=input() chat[name]=i chat={v:k for k,v in chat.items()} x=list(chat.keys()) x.reverse() for m in x: print(chat[m]) ```
0
266
B
Queue at the School
PROGRAMMING
800
[ "constructive algorithms", "graph matchings", "implementation", "shortest paths" ]
null
null
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea...
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find. The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *...
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
[ "5 1\nBGGBG\n", "5 2\nBGGBG\n", "4 1\nGGGB\n" ]
[ "GBGGB\n", "GGBGB\n", "GGGB\n" ]
none
500
[ { "input": "5 1\nBGGBG", "output": "GBGGB" }, { "input": "5 2\nBGGBG", "output": "GGBGB" }, { "input": "4 1\nGGGB", "output": "GGGB" }, { "input": "2 1\nBB", "output": "BB" }, { "input": "2 1\nBG", "output": "GB" }, { "input": "6 2\nBBGBBG", "outpu...
1,695,573,564
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
6
122
0
n, t = [int(i) for i in input().split()] s = list(input()) k = s.copy() c = 0 if "G" in s: for j in range(n): if s[j] == "B": d = j + t if d < n: k[j], k[d] = k[d], k[j] else: k[j], k[n-1-c] = k[n-1-c], k[j] c +=...
Title: Queue at the School Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling a...
```python n, t = [int(i) for i in input().split()] s = list(input()) k = s.copy() c = 0 if "G" in s: for j in range(n): if s[j] == "B": d = j + t if d < n: k[j], k[d] = k[d], k[j] else: k[j], k[n-1-c] = k[n-1-c], k[j] ...
0
928
B
Chat
PROGRAMMING
1,400
[ "*special", "dp" ]
null
null
There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago. More formal, your message history is a sequence of messages ordered by time sent numbered from 1 to...
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=*n*) — the total amount of messages and the number of previous and next messages visible. The second line features a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=&lt;<=*i*), where *a**i* denotes the *i*-th message link...
Print *n* integers with *i*-th denoting the number of distinct messages you can read starting from message *i* and traversing the links while possible.
[ "6 0\n0 1 1 2 3 2\n", "10 1\n0 1 0 3 4 5 2 3 7 0\n", "2 2\n0 1\n" ]
[ "1 2 2 3 3 3 \n", "2 3 3 4 5 6 6 6 8 2 \n", "2 2 \n" ]
Consider *i* = 6 in sample case one. You will read message 6, then 2, then 1 and then there will be no link to go. In the second sample case *i* = 6 gives you messages 5, 6, 7 since *k* = 1, then 4, 5, 6, then 2, 3, 4 and then the link sequence breaks. The number of distinct messages here is equal to 6.
1,250
[ { "input": "6 0\n0 1 1 2 3 2", "output": "1 2 2 3 3 3 " }, { "input": "10 1\n0 1 0 3 4 5 2 3 7 0", "output": "2 3 3 4 5 6 6 6 8 2 " }, { "input": "2 2\n0 1", "output": "2 2 " }, { "input": "1 1\n0", "output": "1 " }, { "input": "5 2\n0 1 2 3 1", "output": "3 4...
1,673,329,625
2,147,483,647
PyPy 3-64
OK
TESTS
118
109
18,636,800
n, k = map(int, input().split()) a = list(map(int, input().split())) dp = [0] * n for i in range(n): if a[i] == 0: s = min(k, i) + 1 else: s = dp[a[i] - 1] + min(2 * k, i - a[i]) + 1 dp[i] = s an = [] for i in range(n): an.append(str(dp[i] + min(k, n - i - 1))) print(" ".join...
Title: Chat Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago. More form...
```python n, k = map(int, input().split()) a = list(map(int, input().split())) dp = [0] * n for i in range(n): if a[i] == 0: s = min(k, i) + 1 else: s = dp[a[i] - 1] + min(2 * k, i - a[i]) + 1 dp[i] = s an = [] for i in range(n): an.append(str(dp[i] + min(k, n - i - 1))) prin...
3
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,548,389,828
2,147,483,647
Python 3
OK
TESTS
33
109
0
book=input() print((len(book)*26)+(26-len(book)))
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 book=input() print((len(book)*26)+(26-len(book))) ```
3
448
B
Suffix Structures
PROGRAMMING
1,400
[ "implementation", "strings" ]
null
null
Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team. At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*. You need to transform word *s* into word *t*". The task looked simple to the guys because they know th...
The first line contains a non-empty word *s*. The second line contains a non-empty word *t*. Words *s* and *t* are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.
In the single line print the answer to the problem. Print "need tree" (without the quotes) if word *s* cannot be transformed into word *t* even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without th...
[ "automaton\ntomat\n", "array\narary\n", "both\nhot\n", "need\ntree\n" ]
[ "automaton\n", "array\n", "both\n", "need tree\n" ]
In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot".
1,000
[ { "input": "automaton\ntomat", "output": "automaton" }, { "input": "array\narary", "output": "array" }, { "input": "both\nhot", "output": "both" }, { "input": "need\ntree", "output": "need tree" }, { "input": "abacaba\naaaa", "output": "automaton" }, { ...
1,624,758,382
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
77
0
def fun(s,t): if (s in t) or (t in s): return True else: return False s=input() t=input() ss=sorted(s) st=sorted(t) if fun(s,t): print("automaton") elif ss==st: print("array") elif fun(ss,st): print("both") else: print("need tree")
Title: Suffix Structures Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team. At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*....
```python def fun(s,t): if (s in t) or (t in s): return True else: return False s=input() t=input() ss=sorted(s) st=sorted(t) if fun(s,t): print("automaton") elif ss==st: print("array") elif fun(ss,st): print("both") else: print("need tree") ```
0
555
A
Case of Matryoshkas
PROGRAMMING
1,500
[ "implementation" ]
null
null
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of *n* matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to *n*. A matryoshka with a smaller number can...
The first line contains integers *n* (1<=≤<=*n*<=≤<=105) and *k* (1<=≤<=*k*<=≤<=105) — the number of matryoshkas and matryoshka chains in the initial configuration. The next *k* lines contain the descriptions of the chains: the *i*-th line first contains number *m**i* (1<=≤<=*m**i*<=≤<=*n*), and then *m**i* numbers *a...
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
[ "3 2\n2 1 2\n1 3\n", "7 3\n3 1 3 7\n2 2 5\n2 4 6\n" ]
[ "1\n", "10\n" ]
In the first sample test there are two chains: 1 → 2 and 3. In one second you can nest the first chain into the second one and get 1 → 2 → 3. In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
250
[ { "input": "3 2\n2 1 2\n1 3", "output": "1" }, { "input": "7 3\n3 1 3 7\n2 2 5\n2 4 6", "output": "10" }, { "input": "1 1\n1 1", "output": "0" }, { "input": "3 2\n1 2\n2 1 3", "output": "3" }, { "input": "5 3\n1 4\n3 1 2 3\n1 5", "output": "2" }, { "in...
1,539,739,640
2,147,483,647
Python 3
OK
TESTS
47
374
7,270,400
n, k = list(map(int,input().split(" "))) cost = 0 for i in range(k): inp = list(map(int,input().split(" "))) m = inp[0] a = inp[1:] if a[0] != 1: cost += m * 2 - 1 else: for j in range(m): if a[j] == j+1: continue j -= 1 break cost += (m - j) * 2 - 1 print(cost - 1)
Title: Case of Matryoshkas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of *n* matryoshka dolls that can be nested ...
```python n, k = list(map(int,input().split(" "))) cost = 0 for i in range(k): inp = list(map(int,input().split(" "))) m = inp[0] a = inp[1:] if a[0] != 1: cost += m * 2 - 1 else: for j in range(m): if a[j] == j+1: continue j -= 1 break cost += (m - j) * 2 - 1 print(cost - 1) ```
3
994
A
Fingerprints
PROGRAMMING
800
[ "implementation" ]
null
null
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse...
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen...
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
[ "7 3\n3 5 7 1 6 2 8\n1 2 7\n", "4 4\n3 4 1 0\n0 1 7 9\n" ]
[ "7 1 2\n", "1 0\n" ]
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence. In the second example digits $...
500
[ { "input": "7 3\n3 5 7 1 6 2 8\n1 2 7", "output": "7 1 2" }, { "input": "4 4\n3 4 1 0\n0 1 7 9", "output": "1 0" }, { "input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8", "output": "8 6 4 2" }, { "input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9", "output": "3 7 4 9 0" }, { "...
1,619,779,168
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
n,m = map(int, input().split()) List_n = list(map(int, input().split())) del List_n[n:] List_m = list(map(int, input().split())) del List_m[m:] # List1 = [] for i in List_m: if i in List_n: print(i,end=" ")
Title: Fingerprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keyp...
```python n,m = map(int, input().split()) List_n = list(map(int, input().split())) del List_n[n:] List_m = list(map(int, input().split())) del List_m[m:] # List1 = [] for i in List_m: if i in List_n: print(i,end=" ") ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,661,361,677
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
x=str(input()) l=u=0 for i in list(x): if(ord(i)>=65 and ord(i)<=90): l+=1 elif(ord(i)>=97 and ord(i)<=122): u+=1 if(l>u): print(x.lowercase()) elif(l<u): print(x.uppercase()) else: print(x.lowercase())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python x=str(input()) l=u=0 for i in list(x): if(ord(i)>=65 and ord(i)<=90): l+=1 elif(ord(i)>=97 and ord(i)<=122): u+=1 if(l>u): print(x.lowercase()) elif(l<u): print(x.uppercase()) else: print(x.lowercase()) ```
-1
629
A
Far Relative’s Birthday Cake
PROGRAMMING
800
[ "brute force", "combinatorics", "constructive algorithms", "implementation" ]
null
null
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta...
In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake. Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
[ "3\n.CC\nC..\nC.C\n", "4\nCC..\nC..C\n.CC.\n.CC.\n" ]
[ "4\n", "9\n" ]
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3)
500
[ { "input": "3\n.CC\nC..\nC.C", "output": "4" }, { "input": "4\nCC..\nC..C\n.CC.\n.CC.", "output": "9" }, { "input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C", "output": "46" }, { "input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.", "output": "84" },...
1,597,667,661
2,147,483,647
Python 3
OK
TESTS
48
109
307,200
fact = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000, 20922789888000, 355687428096000, 6402373705728000, 121645100408832000, 2432902008176640000, 51090942171709440000, 1124000727777607680000, 25852016738884976640000, 620448401733239439360000, 155112...
Title: Far Relative’s Birthday Cake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a *n*<=×<=*n* square consisting of equal squares with s...
```python fact = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000, 20922789888000, 355687428096000, 6402373705728000, 121645100408832000, 2432902008176640000, 51090942171709440000, 1124000727777607680000, 25852016738884976640000, 6204484017332394393600...
3
651
A
Joysticks
PROGRAMMING
1,100
[ "dp", "greedy", "implementation", "math" ]
null
null
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if n...
The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively.
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
[ "3 5\n", "4 4\n" ]
[ "6\n", "5\n" ]
In the first sample game lasts for 6 minute by using the following algorithm: - at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joyst...
500
[ { "input": "3 5", "output": "6" }, { "input": "4 4", "output": "5" }, { "input": "100 100", "output": "197" }, { "input": "1 100", "output": "98" }, { "input": "100 1", "output": "98" }, { "input": "1 4", "output": "2" }, { "input": "1 1", ...
1,592,325,730
2,147,483,647
Python 3
OK
TESTS
39
109
0
a1,a2=[int(x) for x in input().split()] k=0 flag=0 if a1==a2==1: flag=1 else: while a1>0 and a2>0: if a1>=a2: a2+=1 a1-=2 else: a2-=2 a1+=1 k+=1 if flag==1: print(0) else: print(k)
Title: Joysticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick on...
```python a1,a2=[int(x) for x in input().split()] k=0 flag=0 if a1==a2==1: flag=1 else: while a1>0 and a2>0: if a1>=a2: a2+=1 a1-=2 else: a2-=2 a1+=1 k+=1 if flag==1: print(0) else: print(k) ```
3