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
471
A
MUH and Sticks
PROGRAMMING
1,100
[ "implementation" ]
null
null
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: -...
The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
[ "4 2 5 4 4 4\n", "4 4 5 4 4 5\n", "1 2 3 4 5 6\n" ]
[ "Bear", "Elephant", "Alien" ]
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.
500
[ { "input": "4 2 5 4 4 4", "output": "Bear" }, { "input": "4 4 5 4 4 5", "output": "Elephant" }, { "input": "1 2 3 4 5 6", "output": "Alien" }, { "input": "5 5 5 5 5 5", "output": "Elephant" }, { "input": "1 1 1 2 3 5", "output": "Alien" }, { "input": "...
1,563,376,523
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
109
0
# -*- coding: utf-8 -*- """ Created on Wed Jul 17 20:40:54 2019 @author: avina """ l = list(map(int, input().split())) l.sort() n = len(set(l)) if n <=3: if l[1] == l[0]: print('Elephant') else: print('Bear') else: print('Alien')
Title: MUH and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an...
```python # -*- coding: utf-8 -*- """ Created on Wed Jul 17 20:40:54 2019 @author: avina """ l = list(map(int, input().split())) l.sort() n = len(set(l)) if n <=3: if l[1] == l[0]: print('Elephant') else: print('Bear') else: print('Alien') ```
0
747
B
Mammoth's Genome Decoding
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s...
The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome. The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.
If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).
[ "8\nAG?C??CT\n", "4\nAGCT\n", "6\n????G?\n", "4\nAA??\n" ]
[ "AGACGTCT\n", "AGCT\n", "===\n", "===\n" ]
In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is ...
1,000
[ { "input": "8\nAG?C??CT", "output": "AGACGTCT" }, { "input": "4\nAGCT", "output": "AGCT" }, { "input": "6\n????G?", "output": "===" }, { "input": "4\nAA??", "output": "===" }, { "input": "4\n????", "output": "ACGT" }, { "input": "252\n???????GCG??T??TT...
1,482,146,341
2,147,483,647
Python 3
OK
TESTS
95
62
4,608,000
from sys import exit validChars = ['A', 'G', 'C', 'T'] freq = {} length = int(input()) genome = list(input()) if length % 4 != 0: print('===') exit() for c in validChars: freq[c] = 0 for c in genome: if c in validChars: freq[c] = freq[c] + 1 for c in validChars: if ...
Title: Mammoth's Genome Decoding Time Limit: None seconds Memory Limit: None megabytes Problem Description: The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter...
```python from sys import exit validChars = ['A', 'G', 'C', 'T'] freq = {} length = int(input()) genome = list(input()) if length % 4 != 0: print('===') exit() for c in validChars: freq[c] = 0 for c in genome: if c in validChars: freq[c] = freq[c] + 1 for c in validChars...
3
897
A
Scarborough Fair
PROGRAMMING
800
[ "implementation" ]
null
null
Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Althou...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains a string *s* of length *n*, consisting of lowercase English letters. Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), ...
Output string *s* after performing *m* operations described above.
[ "3 1\nioi\n1 1 i n\n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n" ]
[ "noi", "gaaak" ]
For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak.
500
[ { "input": "3 1\nioi\n1 1 i n", "output": "noi" }, { "input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g", "output": "gaaak" }, { "input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n...
1,665,739,775
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
A=(input("").split()) n=int(A[0]) m=int(A[1]) str=(input("")) for i in range(m): B=(input("").split()) l=int(B[0]) r= int(B[1]) c1=B[2] c2=B[3] for j in range(0,r): if str[j]==c1: str=str.replace(c1,c2,l) print(str)
Title: Scarborough Fair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get ...
```python A=(input("").split()) n=int(A[0]) m=int(A[1]) str=(input("")) for i in range(m): B=(input("").split()) l=int(B[0]) r= int(B[1]) c1=B[2] c2=B[3] for j in range(0,r): if str[j]==c1: str=str.replace(c1,c2,l) print(str) ``...
0
486
A
Calculating Function
PROGRAMMING
800
[ "implementation", "math" ]
null
null
For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*.
The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015).
Print *f*(*n*) in a single line.
[ "4\n", "5\n" ]
[ "2\n", "-3\n" ]
*f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
500
[ { "input": "4", "output": "2" }, { "input": "5", "output": "-3" }, { "input": "1000000000", "output": "500000000" }, { "input": "1000000001", "output": "-500000001" }, { "input": "1000000000000000", "output": "500000000000000" }, { "input": "100", ...
1,695,506,166
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
def foncution(n): x = int(n / 2) return (x * (x+1)) - (x ** 2) n = int(input()) print(foncution(n))
Title: Calculating Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*. Input Specification: The single line...
```python def foncution(n): x = int(n / 2) return (x * (x+1)) - (x ** 2) n = int(input()) print(foncution(n)) ```
0
691
A
Fashion in Berland
PROGRAMMING
1,000
[ "implementation" ]
null
null
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open. You are given a jacket with *n* buttons. Determine if it is fast...
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1.
In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".
[ "3\n1 0 1\n", "3\n1 0 0\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "3\n1 0 1", "output": "YES" }, { "input": "3\n1 0 0", "output": "NO" }, { "input": "3\n1 1 0", "output": "YES" }, { "input": "3\n1 1 1", "output": "NO" }, { "input": "3\n0 0 1", "output": "NO" }, { "input": "3\n0 0 0", "output": "NO" }...
1,537,280,210
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
124
0
n=int(input()) arr=list(map(int,input().split())) arr.sort() if n==1: if arr[0]==0: print('YES') else: print('NO') else: t=0 for i in range(2): if arr[i]==0: t+=1 if t==2 or t==0: print('NO') else: print('YES')
Title: Fashion in Berland Time Limit: None seconds Memory Limit: None megabytes Problem Description: According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened,...
```python n=int(input()) arr=list(map(int,input().split())) arr.sort() if n==1: if arr[0]==0: print('YES') else: print('NO') else: t=0 for i in range(2): if arr[i]==0: t+=1 if t==2 or t==0: print('NO') else: prin...
0
616
B
Dinner with Emma
PROGRAMMING
1,000
[ "games", "greedy" ]
null
null
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The stree...
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan. Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue.
Print the only integer *a* — the cost of the dinner for Jack and Emma.
[ "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n", "3 3\n1 2 3\n2 3 1\n3 1 2\n" ]
[ "2\n", "1\n" ]
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the din...
0
[ { "input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1", "output": "2" }, { "input": "3 3\n1 2 3\n2 3 1\n3 1 2", "output": "1" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 10\n74 35 82 39 1 84 29 41 70 12", "output": "1" }, { "input": "10 1\n44\n23\n65\n17\n48\n29\n...
1,679,320,329
6,729
PyPy 3-64
WRONG_ANSWER
TESTS
3
46
0
a,b = map(int, input().split()) ans = [10**10 for i in range(b)] for i in range(a): num = list(map(int, input().split())) for i in range(b): ans[i] = min(num[i],ans[i]) print(max(ans))
Title: Dinner with Emma Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of *n* streets and...
```python a,b = map(int, input().split()) ans = [10**10 for i in range(b)] for i in range(a): num = list(map(int, input().split())) for i in range(b): ans[i] = min(num[i],ans[i]) print(max(ans)) ```
0
43
B
Letter
PROGRAMMING
1,100
[ "implementation", "strings" ]
B. Letter
2
256
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help ...
The first line contains a newspaper heading *s*1. The second line contains the letter text *s*2. *s*1 и *s*2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces o...
If Vasya can write the given anonymous letter, print YES, otherwise print NO
[ "Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog\n", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears\n", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears\n", "...
[ "NO\n", "YES\n", "NO\n", "YES\n" ]
none
1,000
[ { "input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "output": "NO" }, { "input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "output": "YES" }, { "input": "Instead of doggi...
1,632,152,341
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
154
20,172,800
s=input() d=input() s=s.replace(" ","") d=d.replace(" ","") for i in d: if (i not in s) or (s.count(i)>d.count(i)): print("NO") break else: print("YES")
Title: Letter Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to...
```python s=input() d=input() s=s.replace(" ","") d=d.replace(" ","") for i in d: if (i not in s) or (s.count(i)>d.count(i)): print("NO") break else: print("YES") ```
0
282
A
Bit++
PROGRAMMING
800
[ "implementation" ]
null
null
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th...
Print a single integer — the final value of *x*.
[ "1\n++X\n", "2\nX++\n--X\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "1\n++X", "output": "1" }, { "input": "2\nX++\n--X", "output": "0" }, { "input": "3\n++X\n++X\n++X", "output": "3" }, { "input": "2\n--X\n--X", "output": "-2" }, { "input": "5\n++X\n--X\n++X\n--X\n--X", "output": "-1" }, { "input": "28\nX--\...
1,698,120,325
2,147,483,647
Python 3
OK
TESTS
36
46
0
a = int(input()) def cal(): global a x = 0 for i in range(a): req = input() if "++" in req: x += 1 else: x -= 1 return x if 1 <= a <= 150: print(cal())
Title: Bit++ Time Limit: None seconds Memory Limit: None megabytes Problem Description: The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ incre...
```python a = int(input()) def cal(): global a x = 0 for i in range(a): req = input() if "++" in req: x += 1 else: x -= 1 return x if 1 <= a <= 150: print(cal()) ```
3
611
A
New Year and Days
PROGRAMMING
900
[ "implementation" ]
null
null
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015. Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016. Limak wants to prove how responsible a bear he is. He is going to regularly save candies for ...
The only line of the input is in one of the following two formats: - "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month.
Print one integer — the number of candies Limak will save in the year 2016.
[ "4 of week\n", "30 of month\n" ]
[ "52\n", "11\n" ]
Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday. In the first sample Limak wants to sav...
500
[ { "input": "4 of week", "output": "52" }, { "input": "30 of month", "output": "11" }, { "input": "17 of month", "output": "12" }, { "input": "31 of month", "output": "7" }, { "input": "6 of week", "output": "53" }, { "input": "1 of week", "output":...
1,451,488,360
460
PyPy 3
OK
TESTS
38
93
0
a = list(input().split()) if a[2] == 'month': if a[0] == '31': print(7) elif a[0] == '30': print(11) else: print(12) else: if a[0] == '5' or a[0] == '6': print(53) else: print(52)
Title: New Year and Days Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015. Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming ye...
```python a = list(input().split()) if a[2] == 'month': if a[0] == '31': print(7) elif a[0] == '30': print(11) else: print(12) else: if a[0] == '5' or a[0] == '6': print(53) else: print(52) ```
3
27
A
Next Test
PROGRAMMING
1,200
[ "implementation", "sortings" ]
A. Next Test
2
256
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests.
Output the required default value for the next test index.
[ "3\n1 7 2\n" ]
[ "3\n" ]
none
500
[ { "input": "1\n1", "output": "2" }, { "input": "2\n2 1", "output": "3" }, { "input": "3\n3 4 1", "output": "2" }, { "input": "4\n6 4 3 5", "output": "1" }, { "input": "5\n3 2 1 7 4", "output": "5" }, { "input": "6\n4 1 2 5 3 7", "output": "6" }, ...
1,620,029,540
2,147,483,647
Python 3
OK
TESTS
30
124
102,400
n=int(input()) x=list(map(int,input().split())) x=list(set(x)) x.sort() c=1 for i in range(n): if x[i]!=c: break c+=1 print(c)
Title: Next Test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the...
```python n=int(input()) x=list(map(int,input().split())) x=list(set(x)) x.sort() c=1 for i in range(n): if x[i]!=c: break c+=1 print(c) ```
3.968809
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,624,625,535
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
8
218
0
l,l2=set(),set() l3={} cc={} c=0 for i in range(int(input())): a,b=map(int,input().split()) if l3.get(b,0): l3[b]=0 cc[a]=cc.get(a,0)+1 if a!=b: l.add(a) l2.add(b) elif cc[a]>1: l.add(a) l2.add(b) else: l3[a]=l3.get(a,0)+1 ...
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 l,l2=set(),set() l3={} cc={} c=0 for i in range(int(input())): a,b=map(int,input().split()) if l3.get(b,0): l3[b]=0 cc[a]=cc.get(a,0)+1 if a!=b: l.add(a) l2.add(b) elif cc[a]>1: l.add(a) l2.add(b) else: l3[a]=l3.get(a,0)+1...
0
275
A
Lights Out
PROGRAMMING
900
[ "implementation" ]
null
null
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw...
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
[ "1 0 0\n0 0 0\n0 0 1\n", "1 0 1\n8 8 8\n2 0 3\n" ]
[ "001\n010\n100\n", "010\n011\n100\n" ]
none
500
[ { "input": "1 0 0\n0 0 0\n0 0 1", "output": "001\n010\n100" }, { "input": "1 0 1\n8 8 8\n2 0 3", "output": "010\n011\n100" }, { "input": "13 85 77\n25 50 45\n65 79 9", "output": "000\n010\n000" }, { "input": "96 95 5\n8 84 74\n67 31 61", "output": "011\n011\n101" }, {...
1,686,064,343
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
# Read the input grid = [] for _ in range(3): row = list(map(int, input().split())) grid.append(row) # Initialize the result grid result = [[1] * 3 for _ in range(3)] # All lights are initially on # Iterate over each light in the grid for i in range(3): for j in range(3): # Toggle the...
Title: Lights Out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ...
```python # Read the input grid = [] for _ in range(3): row = list(map(int, input().split())) grid.append(row) # Initialize the result grid result = [[1] * 3 for _ in range(3)] # All lights are initially on # Iterate over each light in the grid for i in range(3): for j in range(3): # ...
0
246
A
Buggy Sorting
PROGRAMMING
900
[ "constructive algorithms", "greedy", "sortings" ]
null
null
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a**n* in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. ...
You've got a single integer *n* (1<=≤<=*n*<=≤<=50) — the size of the sorted array.
Print *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the counter-example, for which Valera's algorithm won't work correctly. If the counter-example that meets the described conditions is impossible to give, print -1. If there are several counter-examples, consisting of *n* numbers, yo...
[ "1\n" ]
[ "-1\n" ]
none
500
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "-1" }, { "input": "3", "output": "3 2 1 " }, { "input": "4", "output": "4 3 2 1 " }, { "input": "5", "output": "5 4 3 2 1 " }, { "input": "6", "output": "6 5 4 3 2 1 " }, { "input...
1,683,692,237
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); if (n == 1) { System.out.println("-1"); } else if (n == 2) { System.out.println("1 2"); } else { System.out.print("2 1"); ...
Title: Buggy Sorting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a*...
```python import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); if (n == 1) { System.out.println("-1"); } else if (n == 2) { System.out.println("1 2"); } else { System.out.prin...
-1
633
A
Ebony and Ivory
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of ...
The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.
Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise.
[ "4 6 15\n", "3 2 7\n", "6 11 6\n" ]
[ "No\n", "Yes\n", "Yes\n" ]
In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage.
250
[ { "input": "4 6 15", "output": "No" }, { "input": "3 2 7", "output": "Yes" }, { "input": "6 11 6", "output": "Yes" }, { "input": "3 12 15", "output": "Yes" }, { "input": "5 5 10", "output": "Yes" }, { "input": "6 6 7", "output": "No" }, { "...
1,456,508,707
1,807
Python 3
TIME_LIMIT_EXCEEDED
TESTS
13
2,000
0
def lol(a,b,c): nodelist = [] nodelist.append([a,b]) while nodelist != []: u = nodelist.pop() if u[0] == c: return "Yes" if u[1] == c: return "Yes" x = u[0] + u[1] if x == c: return "Yes" elif x < c: ...
Title: Ebony and Ivory Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. F...
```python def lol(a,b,c): nodelist = [] nodelist.append([a,b]) while nodelist != []: u = nodelist.pop() if u[0] == c: return "Yes" if u[1] == c: return "Yes" x = u[0] + u[1] if x == c: return "Yes" elif x < c: ...
0
581
A
Vasya the Hipster
PROGRAMMING
800
[ "implementation", "math" ]
null
null
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning ...
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he'...
[ "3 1\n", "2 3\n", "7 3\n" ]
[ "1 1\n", "2 0\n", "3 2\n" ]
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
500
[ { "input": "3 1", "output": "1 1" }, { "input": "2 3", "output": "2 0" }, { "input": "7 3", "output": "3 2" }, { "input": "100 100", "output": "100 0" }, { "input": "4 10", "output": "4 3" }, { "input": "6 10", "output": "6 2" }, { "input":...
1,673,118,889
2,147,483,647
PyPy 3-64
OK
TESTS
30
46
0
a, b = map(int, input().split()) results = [0, 0] results[0] = min(a, b) a -= results[0] b -= results[0] results[1] = a // 2 + b // 2 print(*results)
Title: Vasya the Hipster Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red...
```python a, b = map(int, input().split()) results = [0, 0] results[0] = min(a, b) a -= results[0] b -= results[0] results[1] = a // 2 + b // 2 print(*results) ```
3
747
B
Mammoth's Genome Decoding
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s...
The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome. The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.
If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).
[ "8\nAG?C??CT\n", "4\nAGCT\n", "6\n????G?\n", "4\nAA??\n" ]
[ "AGACGTCT\n", "AGCT\n", "===\n", "===\n" ]
In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is ...
1,000
[ { "input": "8\nAG?C??CT", "output": "AGACGTCT" }, { "input": "4\nAGCT", "output": "AGCT" }, { "input": "6\n????G?", "output": "===" }, { "input": "4\nAA??", "output": "===" }, { "input": "4\n????", "output": "ACGT" }, { "input": "252\n???????GCG??T??TT...
1,516,530,109
2,147,483,647
Python 3
OK
TESTS
95
62
5,632,000
def main(): n = int(input().strip()) st = input().strip() if n%4: print('===') return li = [0] * 5 t = n//4 for i in st: if i=='?': li[0] += 1 elif i=='A': li[1] += 1 elif i=='C': li[2] += 1 elif i...
Title: Mammoth's Genome Decoding Time Limit: None seconds Memory Limit: None megabytes Problem Description: The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter...
```python def main(): n = int(input().strip()) st = input().strip() if n%4: print('===') return li = [0] * 5 t = n//4 for i in st: if i=='?': li[0] += 1 elif i=='A': li[1] += 1 elif i=='C': li[2] += 1 ...
3
262
B
Roma and Changing Signs
PROGRAMMING
1,200
[ "greedy" ]
null
null
Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of s...
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104). The numbers in the lines are separated by single spaces...
In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes.
[ "3 2\n-1 -1 1\n", "3 1\n-1 -1 1\n" ]
[ "3\n", "1\n" ]
In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
1,000
[ { "input": "3 2\n-1 -1 1", "output": "3" }, { "input": "3 1\n-1 -1 1", "output": "1" }, { "input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343", "output": "81852" }, { "input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -89...
1,580,985,807
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
4
186
0
n,k=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() i=0 while k>0: if arr[i]<0: arr[i]=arr[i]*-1 i+=1 k-=1 else: if k%2==0: break else: arr[i]=arr[i]*-1 break sum=0 for i in arr: sum+=i print(sum)
Title: Roma and Changing Signs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of ...
```python n,k=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() i=0 while k>0: if arr[i]<0: arr[i]=arr[i]*-1 i+=1 k-=1 else: if k%2==0: break else: arr[i]=arr[i]*-1 break sum=0 for i in arr: sum+=i print(sum) `...
-1
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,649,436,846
2,147,483,647
PyPy 3-64
OK
TESTS
102
62
0
#------- karthik2712 -------# s = input() t = input() for i in range(len(s)): print(int(s[i]) ^ int(t[i]), end = "")
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python #------- karthik2712 -------# s = input() t = input() for i in range(len(s)): print(int(s[i]) ^ int(t[i]), end = "") ```
3.9845
221
B
Little Elephant and Numbers
PROGRAMMING
1,300
[ "implementation" ]
null
null
The Little Elephant loves numbers. He has a positive integer *x*. The Little Elephant wants to find the number of positive integers *d*, such that *d* is the divisor of *x*, and *x* and *d* have at least one common (the same) digit in their decimal representations. Help the Little Elephant to find the described num...
A single line contains a single integer *x* (1<=≤<=*x*<=≤<=109).
In a single line print an integer — the answer to the problem.
[ "1\n", "10\n" ]
[ "1\n", "2\n" ]
none
1,000
[ { "input": "1", "output": "1" }, { "input": "10", "output": "2" }, { "input": "47", "output": "1" }, { "input": "100", "output": "5" }, { "input": "128", "output": "6" }, { "input": "2", "output": "1" }, { "input": "17", "output": "2" ...
1,625,290,346
2,147,483,647
Python 3
OK
TESTS
39
154
0
x = int(input()) hash = [] for i in range(10): hash.append(0) t = x while t > 0: hash[t % 10] = 1 t //= 10 ans = 0 i = 1 while i * i <= x: if x % i == 0: t = i while t > 0 and hash[t % 10] == 0: t //= 10 if t > 0: ans += 1 if x // ...
Title: Little Elephant and Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant loves numbers. He has a positive integer *x*. The Little Elephant wants to find the number of positive integers *d*, such that *d* is the divisor of *x*, and *x* and *d* have at least o...
```python x = int(input()) hash = [] for i in range(10): hash.append(0) t = x while t > 0: hash[t % 10] = 1 t //= 10 ans = 0 i = 1 while i * i <= x: if x % i == 0: t = i while t > 0 and hash[t % 10] == 0: t //= 10 if t > 0: ans += 1 ...
3
552
C
Vanya and Scales
PROGRAMMING
1,900
[ "brute force", "dp", "greedy", "math", "meet-in-the-middle", "number theory" ]
null
null
Vanya has a scales for weighing loads and weights of masses *w*0,<=*w*1,<=*w*2,<=...,<=*w*100 grams where *w* is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass *m* using the given weights, if the weights can be put on both pans of the scale...
The first line contains two integers *w*,<=*m* (2<=≤<=*w*<=≤<=109, 1<=≤<=*m*<=≤<=109) — the number defining the masses of the weights and the mass of the item.
Print word 'YES' if the item can be weighted and 'NO' if it cannot.
[ "3 7\n", "100 99\n", "100 50\n" ]
[ "YES\n", "YES\n", "NO\n" ]
Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can ha...
1,500
[ { "input": "3 7", "output": "YES" }, { "input": "100 99", "output": "YES" }, { "input": "100 50", "output": "NO" }, { "input": "1000000000 1", "output": "YES" }, { "input": "100 10002", "output": "NO" }, { "input": "4 7", "output": "NO" }, { ...
1,542,198,860
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
93
0
import sys w,m = input().split() w = int(w) m = int(m) a = [] if w<= 3: print('YES') sys.exit() while m!= 0: if (m % w != (w - 1)) and (m % w != 0) and (m % w != 1): m = (m+1)//w print('NO') sys.exit() else: print('YES') sys.exit()
Title: Vanya and Scales Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya has a scales for weighing loads and weights of masses *w*0,<=*w*1,<=*w*2,<=...,<=*w*100 grams where *w* is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can wei...
```python import sys w,m = input().split() w = int(w) m = int(m) a = [] if w<= 3: print('YES') sys.exit() while m!= 0: if (m % w != (w - 1)) and (m % w != 0) and (m % w != 1): m = (m+1)//w print('NO') sys.exit() else: print('YES') sys.exit() ```
0
0
none
none
none
0
[ "none" ]
null
null
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. ...
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "1 3 2 1 2 1\n", "1 1 1 1 1 99\n" ]
[ "YES\n", "NO\n" ]
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
0
[ { "input": "1 3 2 1 2 1", "output": "YES" }, { "input": "1 1 1 1 1 99", "output": "NO" }, { "input": "1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "0 0 0 0 0 0", "output": "YES" }, { "input": "633 609 369 704 573 416", "output": "NO" }, { ...
1,512,476,070
2,147,483,647
Python 3
OK
TESTS
53
62
5,529,600
a=[] sumx = 0 sum1 = 0 for i in input().split() : a.append(int(i)) sumx += int(i) for i in range(6): for r in range(i,6): if r == i : continue for z in range(r,6): if(z == r): continue sum1 = a[i]+a[r]+a[z] if(sum1 == sumx-sum1...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exac...
```python a=[] sumx = 0 sum1 = 0 for i in input().split() : a.append(int(i)) sumx += int(i) for i in range(6): for r in range(i,6): if r == i : continue for z in range(r,6): if(z == r): continue sum1 = a[i]+a[r]+a[z] if(sum1 ==...
3
359
C
Prime Number
PROGRAMMING
1,900
[ "math", "number theory" ]
null
null
Simon has a prime number *x* and an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: , where number *t* equals *x**a*1<=+<=*a*2<=+<=......
The first line contains two positive integers *n* and *x* (1<=≤<=*n*<=≤<=105, 2<=≤<=*x*<=≤<=109) — the size of the array and the prime number. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*<=≤<=109).
Print a single number — the answer to the problem modulo 1000000007 (109<=+<=7).
[ "2 2\n2 2\n", "3 3\n1 2 3\n", "2 2\n29 29\n", "4 5\n0 0 0 0\n" ]
[ "8\n", "27\n", "73741817\n", "1\n" ]
In the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7745f7cc87c6c5f753e3414fad9baa3b1e3fea48.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, the answer to the problem is 8. In the second sample, <img align="middle" class="tex-formula" src="https://espresso.codef...
1,500
[ { "input": "2 2\n2 2", "output": "8" }, { "input": "3 3\n1 2 3", "output": "27" }, { "input": "2 2\n29 29", "output": "73741817" }, { "input": "4 5\n0 0 0 0", "output": "1" }, { "input": "1 2\n1000000000", "output": "1" }, { "input": "26 2\n0 0 0 0 0 0...
1,594,208,375
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
4
1,000
32,256,000
def gcd(a,b): if(a==0): return b return gcd(b%a,a) def binp(a,b): res = 1 while (b > 0): if (b & 1): res = res * a a = a * a b >>= 1 return res mod = 1000000007 n,x = map(int,input().split()) A = list(map(int,input().split())) sum = 0 f...
Title: Prime Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon has a prime number *x* and an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common den...
```python def gcd(a,b): if(a==0): return b return gcd(b%a,a) def binp(a,b): res = 1 while (b > 0): if (b & 1): res = res * a a = a * a b >>= 1 return res mod = 1000000007 n,x = map(int,input().split()) A = list(map(int,input().split())) ...
0
597
B
Restaurant
PROGRAMMING
1,600
[ "dp", "greedy", "sortings" ]
null
null
A restaurant received *n* orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the *i*-th order is characterized by two time values — the start time *l**i* and the finish time *r**i* (*l**i*<=≤<=*r**i*). Restaurant management can accept and reject orders. What is the maximal...
The first line contains integer number *n* (1<=≤<=*n*<=≤<=5·105) — number of orders. The following *n* lines contain integer values *l**i* and *r**i* each (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109).
Print the maximal number of orders that can be accepted.
[ "2\n7 11\n4 7\n", "5\n1 2\n2 3\n3 4\n4 5\n5 6\n", "6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8\n" ]
[ "1\n", "3\n", "2\n" ]
none
1,000
[ { "input": "2\n7 11\n4 7", "output": "1" }, { "input": "5\n1 2\n2 3\n3 4\n4 5\n5 6", "output": "3" }, { "input": "6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8", "output": "2" }, { "input": "1\n1 1", "output": "1" }, { "input": "2\n4 6\n4 8", "output": "1" }, { "inp...
1,613,887,481
2,147,483,647
Python 3
OK
TESTS
70
1,309
39,833,600
import sys n = int(sys.stdin.readline()) orders = [tuple(map(int, sys.stdin.readline().split())) for _ in range(n)] orders.sort(key=lambda x: x[1]) prev_r = None count = 0 for l, r in orders: if not prev_r or prev_r < l: count += 1 prev_r = r print(count)
Title: Restaurant Time Limit: None seconds Memory Limit: None megabytes Problem Description: A restaurant received *n* orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the *i*-th order is characterized by two time values — the start time *l**i* and the finish time *r**...
```python import sys n = int(sys.stdin.readline()) orders = [tuple(map(int, sys.stdin.readline().split())) for _ in range(n)] orders.sort(key=lambda x: x[1]) prev_r = None count = 0 for l, r in orders: if not prev_r or prev_r < l: count += 1 prev_r = r print(count) ```
3
220
A
Little Elephant and Problem
PROGRAMMING
1,300
[ "implementation", "sortings" ]
null
null
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he co...
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*. Note that the elements of the array are not necessarily distinct numbers.
In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise.
[ "2\n1 2\n", "3\n3 2 1\n", "4\n4 3 2 1\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES". In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES". In the third sample we ...
500
[ { "input": "2\n1 2", "output": "YES" }, { "input": "3\n3 2 1", "output": "YES" }, { "input": "4\n4 3 2 1", "output": "NO" }, { "input": "3\n1 3 2", "output": "YES" }, { "input": "2\n2 1", "output": "YES" }, { "input": "9\n7 7 8 8 10 10 10 10 1000000000...
1,645,907,542
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
22
46
2,764,800
def main(): n = int(input()) arr = list(map(int, input().split())) sorted_arr = sorted(arr) for i in range(n): element, sorted_element = arr[i], sorted_arr[i] if element != sorted_element: index = arr.index(sorted_element) arr[i], arr[index] = sorted_ele...
Title: Little Elephant and Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array. The Little Elephant doesn't want to c...
```python def main(): n = int(input()) arr = list(map(int, input().split())) sorted_arr = sorted(arr) for i in range(n): element, sorted_element = arr[i], sorted_arr[i] if element != sorted_element: index = arr.index(sorted_element) arr[i], arr[index] = ...
0
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,444,104
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
5,632,000
n = int(input()) k = int(input()) A = int(input()) B = int(input()) zen = 0 while n != 1: if n % k == 0: if (n - 1) * A > B: n //= k zen += B else: zen += (n - 1) * A n = 1 else: l = n % k n -= l zen += A * l...
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()) zen = 0 while n != 1: if n % k == 0: if (n - 1) * A > B: n //= k zen += B else: zen += (n - 1) * A n = 1 else: l = n % k n -= l ze...
0
1,008
A
Romaji
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant...
The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters.
Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower).
[ "sumimasen\n", "ninja\n", "codeforces\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese. In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.
500
[ { "input": "sumimasen", "output": "YES" }, { "input": "ninja", "output": "YES" }, { "input": "codeforces", "output": "NO" }, { "input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen", "output": "YES" }, { "in...
1,681,036,665
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
31
0
import sys s=sys.stdin.readline().strip() glas=[*'aouie'];soglas=[*"qwrtypsdfghjklzxcvbm"] x=''.join(list(map(lambda x: "0" if x in soglas else "1", s))) print("NO" if "00" in x else "YES")
Title: Romaji Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after eve...
```python import sys s=sys.stdin.readline().strip() glas=[*'aouie'];soglas=[*"qwrtypsdfghjklzxcvbm"] x=''.join(list(map(lambda x: "0" if x in soglas else "1", s))) print("NO" if "00" in x else "YES") ```
0
66
B
Petya and Countryside
PROGRAMMING
1,100
[ "brute force", "implementation" ]
B. Petya and Countryside
2
256
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
[ "1\n2\n", "5\n1 2 1 2 1\n", "8\n1 2 1 1 1 3 3 4\n" ]
[ "1\n", "3\n", "6\n" ]
none
1,000
[ { "input": "1\n2", "output": "1" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "8\n1 2 1 1 1 3 3 4", "output": "6" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "10" }, { "input...
1,562,998,918
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n = int(input.readline()) lis = list(map(int, input.readline().split())) results = [] for i, x in enumerate(lis): count = 1 for j in range(i, -1, -1): if j == i: continue if j+1 >= len(lis) or lis[j] > lis[j+1]: break ...
Title: Petya and Countryside Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *...
```python n = int(input.readline()) lis = list(map(int, input.readline().split())) results = [] for i, x in enumerate(lis): count = 1 for j in range(i, -1, -1): if j == i: continue if j+1 >= len(lis) or lis[j] > lis[j+1]: br...
-1
807
A
Is it rated?
PROGRAMMING
900
[ "implementation", "sortings" ]
null
null
Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ...
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants. Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order...
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
[ "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n", "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n", "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n" ]
[ "rated\n", "unrated\n", "maybe\n" ]
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som...
500
[ { "input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884", "output": "rated" }, { "input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699", "output": "maybe" }, { ...
1,665,934,207
2,147,483,647
Python 3
OK
TESTS
150
46
4,505,600
a=int(input()) arr=[] for i in range(a): sub=list(map(int,input().split())) arr.append(sub) d=0 j=0 for i in range(a-1): if arr[i][0]>arr[i][1] or arr[i][0]<arr[i][1]: d=d+1 if arr[i][0]<arr[i+1][0]: j=j+1 if arr[a-1][0]>arr[a-1][1] or arr[a-1][0]<arr[a-1][1]: d=d+1 if d>0:...
Title: Is it rated? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number ...
```python a=int(input()) arr=[] for i in range(a): sub=list(map(int,input().split())) arr.append(sub) d=0 j=0 for i in range(a-1): if arr[i][0]>arr[i][1] or arr[i][0]<arr[i][1]: d=d+1 if arr[i][0]<arr[i+1][0]: j=j+1 if arr[a-1][0]>arr[a-1][1] or arr[a-1][0]<arr[a-1][1]: d=d+1 ...
3
269
A
Magical Boxes
PROGRAMMING
1,600
[ "greedy", "math" ]
null
null
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes. From the top view each magical box looks like a square with side length equal to 2*k* (*k* is an integer, *k*<=≥<=0) units. A magical box *v* can be pu...
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=105), the number of different sizes of boxes Emuskald has. Each of following *n* lines contains two integers *k**i* and *a**i* (0<=≤<=*k**i*<=≤<=109, 1<=≤<=*a**i*<=≤<=109), which means that Emuskald has *a**i* boxes with side length 2*k**i*. It is guarantee...
Output a single integer *p*, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2*p*.
[ "2\n0 3\n1 5\n", "1\n0 4\n", "2\n1 10\n2 2\n" ]
[ "3\n", "1\n", "3\n" ]
Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture. In the second test case, we can put all four small boxes into a box with side length 2.
500
[ { "input": "2\n0 3\n1 5", "output": "3" }, { "input": "1\n0 4", "output": "1" }, { "input": "2\n1 10\n2 2", "output": "3" }, { "input": "1\n0 1", "output": "1" }, { "input": "1\n1000000000 1000000000", "output": "1000000015" }, { "input": "1\n0 16", ...
1,639,483,218
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
from collections import Counter l = list(map(int, input().split())) dict = Counter(l) if len(dict) == 3: print("Bear") elif len(dict) == 2: print("Elephant") else: print("Alien")
Title: Magical Boxes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes. From the top view each magical box looks like a squa...
```python from collections import Counter l = list(map(int, input().split())) dict = Counter(l) if len(dict) == 3: print("Bear") elif len(dict) == 2: print("Elephant") else: print("Alien") ```
0
984
A
Game
PROGRAMMING
800
[ "sortings" ]
null
null
Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ...
The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$).
Print one number that will be left on the board.
[ "3\n2 1 3\n", "3\n2 2 2\n" ]
[ "2", "2" ]
In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board. In the second sample, $2$ is left on the board regardless of the actions of the players.
500
[ { "input": "3\n2 1 3", "output": "2" }, { "input": "3\n2 2 2", "output": "2" }, { "input": "9\n44 53 51 80 5 27 74 79 94", "output": "53" }, { "input": "10\n38 82 23 37 96 4 81 60 67 86", "output": "60" }, { "input": "10\n58 26 77 15 53 81 68 48 22 65", "outpu...
1,591,557,331
2,147,483,647
Python 3
OK
TESTS
35
139
307,200
n=int(input()) arr=[int(x) for x in input().split()] arr.sort() i=0 while len(arr)!=1: if i%2==0: arr.remove(max(arr)) else: arr.remove(min(arr)) i+=1 print(arr[0])
Title: Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the...
```python n=int(input()) arr=[int(x) for x in input().split()] arr.sort() i=0 while len(arr)!=1: if i%2==0: arr.remove(max(arr)) else: arr.remove(min(arr)) i+=1 print(arr[0]) ```
3
926
A
2-3-numbers
PROGRAMMING
1,300
[ "implementation", "math" ]
null
null
A positive integer is called a 2-3-integer, if it is equal to 2*x*·3*y* for some non-negative integers *x* and *y*. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not. Print th...
The only line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=2·109).
Print a single integer the number of 2-3-integers on the segment [*l*,<=*r*].
[ "1 10\n", "100 200\n", "1 2000000000\n" ]
[ "7\n", "5\n", "326\n" ]
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9. In the second example the 2-3-integers are 108, 128, 144, 162 and 192.
0
[ { "input": "1 10", "output": "7" }, { "input": "100 200", "output": "5" }, { "input": "1 2000000000", "output": "326" }, { "input": "1088391168 1934917632", "output": "17" }, { "input": "1088391167 1934917632", "output": "17" }, { "input": "1088391169 ...
1,521,301,983
1,083
Python 3
OK
TESTS
53
109
7,372,800
l,r = list(map(int, input().split())) ans = 0 for i in range(40): for j in range(40): v= int(2**i * 3**j); if(v >= l and v <= r): ans = ans + 1 print(ans)
Title: 2-3-numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: A positive integer is called a 2-3-integer, if it is equal to 2*x*·3*y* for some non-negative integers *x* and *y*. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For exa...
```python l,r = list(map(int, input().split())) ans = 0 for i in range(40): for j in range(40): v= int(2**i * 3**j); if(v >= l and v <= r): ans = ans + 1 print(ans) ```
3
429
B
Working out
PROGRAMMING
1,600
[ "dp" ]
null
null
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix *a* with *n* lines and *m* columns. Let number *a*[*i*][*j*] represents the calories burned by performing workout at the cell of gym in the *i*-th line and the *j*-th column. Ia...
The first line of the input contains two integers *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=1000). Each of the next *n* lines contains *m* integers: *j*-th number from *i*-th line denotes element *a*[*i*][*j*] (0<=≤<=*a*[*i*][*j*]<=≤<=105).
The output contains a single number — the maximum total gain possible.
[ "3 3\n100 100 100\n100 1 100\n100 100 100\n" ]
[ "800" ]
Iahub will choose exercises *a*[1][1] → *a*[1][2] → *a*[2][2] → *a*[3][2] → *a*[3][3]. Iahubina will choose exercises *a*[3][1] → *a*[2][1] → *a*[2][2] → *a*[2][3] → *a*[1][3].
1,000
[ { "input": "3 3\n100 100 100\n100 1 100\n100 100 100", "output": "800" }, { "input": "4 5\n87882 40786 3691 85313 46694\n28884 16067 3242 97367 78518\n4250 35501 9780 14435 19004\n64673 65438 56977 64495 27280", "output": "747898" }, { "input": "3 3\n3 1 2\n3 2 0\n2 3 2", "output": "...
1,592,634,114
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
124
0
if __name__ == '__main__': n, m = map(int, input().split()) mtrx = [] for _ in range(n): mtrx.append(list(map(int, input().split()))) dpm = [[None for _ in range(m)] for _ in range(n)] for i in range(n): for j in range(m): dpm[i][j] = (mtrx[i][j], mtrx[i][j]) ...
Title: Working out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix *a* with *n* lines and *m* columns. Let number *a*[*i*][*j*] represents the calor...
```python if __name__ == '__main__': n, m = map(int, input().split()) mtrx = [] for _ in range(n): mtrx.append(list(map(int, input().split()))) dpm = [[None for _ in range(m)] for _ in range(n)] for i in range(n): for j in range(m): dpm[i][j] = (mtrx[i][j], mtrx[i][j]...
0
222
A
Shooshuns and Sequence
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current ...
The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found.
Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1.
[ "3 2\n3 1 1\n", "3 1\n3 1 1\n" ]
[ "1\n", "-1\n" ]
In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one. In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1....
500
[ { "input": "3 2\n3 1 1", "output": "1" }, { "input": "3 1\n3 1 1", "output": "-1" }, { "input": "1 1\n1", "output": "0" }, { "input": "2 1\n1 1", "output": "0" }, { "input": "2 1\n2 1", "output": "-1" }, { "input": "4 4\n1 2 3 4", "output": "3" }...
1,622,991,241
2,147,483,647
Python 3
OK
TESTS
47
312
7,475,200
n, k = map(int, input().split()) a = list(map(int, input().split())) while n and a[n - 1] == a[-1]: n -= 1 print(n if k > n else -1)
Title: Shooshuns and Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the cur...
```python n, k = map(int, input().split()) a = list(map(int, input().split())) while n and a[n - 1] == a[-1]: n -= 1 print(n if k > n else -1) ```
3
166
E
Tetrahedron
PROGRAMMING
1,500
[ "dp", "math", "matrices" ]
null
null
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. ...
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
[ "2\n", "4\n" ]
[ "3\n", "21\n" ]
The required paths in the first sample are: - *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D*
1,000
[ { "input": "2", "output": "3" }, { "input": "4", "output": "21" }, { "input": "1", "output": "0" }, { "input": "3", "output": "6" }, { "input": "5", "output": "60" }, { "input": "6", "output": "183" }, { "input": "7", "output": "546" ...
1,633,009,248
2,147,483,647
Python 3
OK
TESTS
36
124
6,963,200
# _166e ##################################################################################################################### from math import ceil, log def main(): n = int(input()) if n%2: return ((finalRemainderOf(3, n-1) - 1)*750000006)%1000000007 return ((finalRemainderOf(3, n) - ...
Title: Tetrahedron Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each m...
```python # _166e ##################################################################################################################### from math import ceil, log def main(): n = int(input()) if n%2: return ((finalRemainderOf(3, n-1) - 1)*750000006)%1000000007 return ((finalRemainderO...
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,594,664,929
2,147,483,647
PyPy 3
OK
TESTS
27
310
20,172,800
a,b,c=map(int,input().strip().split()) volumes = (a*b*c)**0.5 le = volumes / a br = volumes / b he = volumes/c print( int(4 * (le + br + he)))
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 a,b,c=map(int,input().strip().split()) volumes = (a*b*c)**0.5 le = volumes / a br = volumes / b he = volumes/c print( int(4 * (le + br + he))) ```
3
282
A
Bit++
PROGRAMMING
800
[ "implementation" ]
null
null
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th...
Print a single integer — the final value of *x*.
[ "1\n++X\n", "2\nX++\n--X\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "1\n++X", "output": "1" }, { "input": "2\nX++\n--X", "output": "0" }, { "input": "3\n++X\n++X\n++X", "output": "3" }, { "input": "2\n--X\n--X", "output": "-2" }, { "input": "5\n++X\n--X\n++X\n--X\n--X", "output": "-1" }, { "input": "28\nX--\...
1,699,946,040
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n=int(input()) for i in range(n) s=str(input()) cnt=0 if s[0]=='+' or s[len(s)-1]=='+': cnt+=1 elif s[0]=='-' or s[len(s)-1]=='-': cnt-=1 print(cnt)
Title: Bit++ Time Limit: None seconds Memory Limit: None megabytes Problem Description: The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ incre...
```python n=int(input()) for i in range(n) s=str(input()) cnt=0 if s[0]=='+' or s[len(s)-1]=='+': cnt+=1 elif s[0]=='-' or s[len(s)-1]=='-': cnt-=1 print(cnt) ```
-1
991
A
If at first you don't succeed...
PROGRAMMING
1,000
[ "implementation" ]
null
null
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam. Some of them celebrated in the BugDonalds restaurant, some of them...
The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$).
If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam. ...
[ "10 10 5 20\n", "2 2 0 4\n", "2 2 2 1\n" ]
[ "5", "-1", "-1" ]
The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam. In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students...
500
[ { "input": "10 10 5 20", "output": "5" }, { "input": "2 2 0 4", "output": "-1" }, { "input": "2 2 2 1", "output": "-1" }, { "input": "98 98 97 100", "output": "1" }, { "input": "1 5 2 10", "output": "-1" }, { "input": "5 1 2 10", "output": "-1" }...
1,593,971,673
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
77
6,656,000
""" Written By Shagoto """ a = int(input()) b = int(input()) c = int(input()) n = int(input()) if (a > n or b > n or c > n or a < c or b < c): print(-1) elif(n - (a - c) - (b - c) - c > 0): print(n - (a - c) - (b - c) - c) else: print(-1)
Title: If at first you don't succeed... Time Limit: None seconds Memory Limit: None megabytes Problem Description: Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group w...
```python """ Written By Shagoto """ a = int(input()) b = int(input()) c = int(input()) n = int(input()) if (a > n or b > n or c > n or a < c or b < c): print(-1) elif(n - (a - c) - (b - c) - c > 0): print(n - (a - c) - (b - c) - c) else: print(-1) ```
-1
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,615,806,466
2,147,483,647
Python 3
OK
TESTS
102
77
0
a=input() b=input() c="" for x in range(len(a)): if a[x]==b[x]: c+="0" else: c+="1" print(c)
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 a=input() b=input() c="" for x in range(len(a)): if a[x]==b[x]: c+="0" else: c+="1" print(c) ```
3.98075
551
A
GukiZ and Contest
PROGRAMMING
800
[ "brute force", "implementation", "sortings" ]
null
null
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote...
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*).
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
[ "3\n1 3 3\n", "1\n1\n", "5\n3 5 3 4 5\n" ]
[ "3 1 1\n", "1\n", "4 1 4 3 1\n" ]
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first positi...
500
[ { "input": "3\n1 3 3", "output": "3 1 1" }, { "input": "1\n1", "output": "1" }, { "input": "5\n3 5 3 4 5", "output": "4 1 4 3 1" }, { "input": "7\n1 3 5 4 2 2 1", "output": "6 3 1 2 4 4 6" }, { "input": "11\n5 6 4 2 9 7 6 6 6 6 7", "output": "9 4 10 11 1 2 4 4...
1,434,204,162
2,147,483,647
Python 3
OK
TESTS
36
62
614,400
__author__ = 'Sandi' import sys from collections import defaultdict lines = sys.stdin.read().strip().split("\n") n = int(lines[0]) students = lines[1].split(" ") students = list(map(int, students)) sortStudents = list(map(int, students[::])) sortStudents.sort(reverse=True) prev = sortStudents[0] grade = 1 ...
Title: GukiZ and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the star...
```python __author__ = 'Sandi' import sys from collections import defaultdict lines = sys.stdin.read().strip().split("\n") n = int(lines[0]) students = lines[1].split(" ") students = list(map(int, students)) sortStudents = list(map(int, students[::])) sortStudents.sort(reverse=True) prev = sortStudents[0] g...
3
262
A
Roma and Lucky Numbers
PROGRAMMING
800
[ "implementation" ]
null
null
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integer...
The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has. The numbers in the lines are separated by single spaces.
In a single line print a single integer — the answer to the problem.
[ "3 4\n1 2 4\n", "3 2\n447 44 77\n" ]
[ "3\n", "2\n" ]
In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
500
[ { "input": "3 4\n1 2 4", "output": "3" }, { "input": "3 2\n447 44 77", "output": "2" }, { "input": "2 2\n507978501 180480073", "output": "2" }, { "input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089", "output": "9" }, { ...
1,621,079,153
2,147,483,647
Python 3
OK
TESTS
34
124
0
n, k = map(int, input().split()) a = list(map(str, input().split())) ans = 0 for i in range(n): cnt = 0 for j in range(len(a[i])): if a[i][j] == '4' or a[i][j] == '7': cnt += 1 if cnt <= k: ans += 1 print(ans)
Title: Roma and Lucky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits...
```python n, k = map(int, input().split()) a = list(map(str, input().split())) ans = 0 for i in range(n): cnt = 0 for j in range(len(a[i])): if a[i][j] == '4' or a[i][j] == '7': cnt += 1 if cnt <= k: ans += 1 print(ans) ```
3
449
A
Jzzhu and Chocolate
PROGRAMMING
1,700
[ "greedy", "math" ]
null
null
Jzzhu has a big rectangular chocolate bar that consists of *n*<=×<=*m* unit squares. He wants to cut this bar exactly *k* times. Each cut must meet the following requirements: - each cut should be straight (horizontal or vertical); - each cut should go along edges of unit squares (it is prohibited to divide any unit...
A single line contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=109; 1<=≤<=*k*<=≤<=2·109).
Output a single integer representing the answer. If it is impossible to cut the big chocolate *k* times, print -1.
[ "3 4 1\n", "6 4 2\n", "2 3 4\n" ]
[ "6\n", "8\n", "-1\n" ]
In the first sample, Jzzhu can cut the chocolate following the picture below: In the second sample the optimal division looks like this: In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
500
[ { "input": "3 4 1", "output": "6" }, { "input": "6 4 2", "output": "8" }, { "input": "2 3 4", "output": "-1" }, { "input": "10 10 2", "output": "30" }, { "input": "1000000000 1000000000 2000000000", "output": "-1" }, { "input": "1000000000 1000000000 9...
1,599,935,623
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
78
0
n,m,k=map(int , input().split()) if 1<= n and m<=1000000000 and k>=1 and k<=2000000000: k=k+1 if (n*m)%k==0: print(int((n*m)/k)) else: print("-1")
Title: Jzzhu and Chocolate Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jzzhu has a big rectangular chocolate bar that consists of *n*<=×<=*m* unit squares. He wants to cut this bar exactly *k* times. Each cut must meet the following requirements: - each cut should be straight (horizo...
```python n,m,k=map(int , input().split()) if 1<= n and m<=1000000000 and k>=1 and k<=2000000000: k=k+1 if (n*m)%k==0: print(int((n*m)/k)) else: print("-1") ```
0
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i...
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" ...
1,671,114,164
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
77
3,174,400
for s in[*open(0)][1:]:print(1440-eval(s.replace(' ','*60+')))
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the...
```python for s in[*open(0)][1:]:print(1440-eval(s.replace(' ','*60+'))) ```
-1
433
B
Kuriyama Mirai's Stones
PROGRAMMING
1,200
[ "dp", "implementation", "sortings" ]
null
null
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones. The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t...
Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.
[ "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n", "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n" ]
[ "24\n9\n28\n", "10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n" ]
Please note that the answers to the questions may overflow 32-bit integer type.
1,500
[ { "input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6", "output": "24\n9\n28" }, { "input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2", "output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5" }, { "input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1...
1,637,648,930
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
n = int(input()) arr = list(map(int,input().split())) arr1 = sorted(arr) for i in range(1,n): arr[i] = arr[i] + arr[i-1] arr1[i] = arr1[i] + arr[i -1] arr.insert(0,0) arr1.insert(0,0) for _ in range(int(input())): t,l,r = map(int,input().split()) ans = 0 if t == 1: ans = arr[r] - arr[l-1] els...
Title: Kuriyama Mirai's Stones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s...
```python n = int(input()) arr = list(map(int,input().split())) arr1 = sorted(arr) for i in range(1,n): arr[i] = arr[i] + arr[i-1] arr1[i] = arr1[i] + arr[i -1] arr.insert(0,0) arr1.insert(0,0) for _ in range(int(input())): t,l,r = map(int,input().split()) ans = 0 if t == 1: ans = arr[r] - arr[...
-1
300
A
Array
PROGRAMMING
1,100
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The produ...
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second...
[ "3\n-1 2 0\n", "4\n-1 -2 -3 0\n" ]
[ "1 -1\n1 2\n1 0\n", "1 -1\n2 -3 -2\n1 0\n" ]
none
500
[ { "input": "3\n-1 2 0", "output": "1 -1\n1 2\n1 0" }, { "input": "4\n-1 -2 -3 0", "output": "1 -1\n2 -3 -2\n1 0" }, { "input": "5\n-1 -2 1 2 0", "output": "1 -1\n2 1 2\n2 0 -2" }, { "input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -1...
1,690,548,238
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
n=int(input()) a=list(map(int,input().split())) a.sort() c=a.count(0) C=[1,0] A=[1,a[0]] B=[n-2] for i in range(1,n): if a[i]!=0: B.append(a[i]) print(*A) print(*B) print(*C)
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. T...
```python n=int(input()) a=list(map(int,input().split())) a.sort() c=a.count(0) C=[1,0] A=[1,a[0]] B=[n-2] for i in range(1,n): if a[i]!=0: B.append(a[i]) print(*A) print(*B) print(*C) ```
0
666
A
Reberland Linguistics
PROGRAMMING
1,800
[ "dp", "implementation", "strings" ]
null
null
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
The only line contains a string *s* (5<=≤<=|*s*|<=≤<=104) consisting of lowercase English letters.
On the first line print integer *k* — a number of distinct possible suffixes. On the next *k* lines print suffixes. Print suffixes in lexicographical (alphabetical) order.
[ "abacabaca\n", "abaca\n" ]
[ "3\naca\nba\nca\n", "0\n" ]
The first test was analysed in the problem statement. In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix.
500
[ { "input": "abacabaca", "output": "3\naca\nba\nca" }, { "input": "abaca", "output": "0" }, { "input": "gzqgchv", "output": "1\nhv" }, { "input": "iosdwvzerqfi", "output": "9\ner\nerq\nfi\nqfi\nrq\nvz\nvze\nze\nzer" }, { "input": "oawtxikrpvfuzugjweki", "output...
1,461,998,865
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
4,812,800
__author__ = 'Utena' s=input() n=len(s) ans=set() if n<=6: print(0) exit(0) dp=[[False,False]for i in range(n+1)] dp[3][1]=True dp[2][0]=True ans.add(s[-2:]) ans.add(s[-3:]) for i in range(4,n-4): if s[(-i):(-i+2)]!=s[(-i+2):(-i+4)]and dp[i-2][0] or dp[i-2][1]: dp[i][0]=True a...
Title: Reberland Linguistics Time Limit: None seconds Memory Limit: None megabytes Problem Description: First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental kn...
```python __author__ = 'Utena' s=input() n=len(s) ans=set() if n<=6: print(0) exit(0) dp=[[False,False]for i in range(n+1)] dp[3][1]=True dp[2][0]=True ans.add(s[-2:]) ans.add(s[-3:]) for i in range(4,n-4): if s[(-i):(-i+2)]!=s[(-i+2):(-i+4)]and dp[i-2][0] or dp[i-2][1]: dp[i][0]=True ...
0
669
A
Little Artem and Presents
PROGRAMMING
800
[ "math" ]
null
null
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art...
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday.
Print the maximum possible number of times Artem can give presents to Masha.
[ "1\n", "2\n", "3\n", "4\n" ]
[ "1\n", "1\n", "2\n", "3\n" ]
In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ...
500
[ { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "3", "output": "2" }, { "input": "4", "output": "3" }, { "input": "100", "output": "67" }, { "input": "101", "output": "67" }, { "input": "102", "output": "68"...
1,462,115,813
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n = int(input()) if n%3 == 0 : y = n//3 elif n%3 == 1: y = n//3 + 1 else y = n // 3 print(y)
Title: Little Artem and Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan...
```python n = int(input()) if n%3 == 0 : y = n//3 elif n%3 == 1: y = n//3 + 1 else y = n // 3 print(y) ```
-1
599
A
Patrick and Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len...
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o...
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
[ "10 20 30\n", "1 1 5\n" ]
[ "60\n", "4\n" ]
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form...
500
[ { "input": "10 20 30", "output": "60" }, { "input": "1 1 5", "output": "4" }, { "input": "100 33 34", "output": "134" }, { "input": "777 777 777", "output": "2331" }, { "input": "2 2 8", "output": "8" }, { "input": "12 34 56", "output": "92" }, ...
1,632,340,168
2,147,483,647
Python 3
OK
TESTS
21
62
6,758,400
a, b, c = map(int, input().split()) a, b = min(a, b), max(a, b) s = a + min(c + c + a, c + b, a + b + b) print(s)
Title: Patrick and Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the...
```python a, b, c = map(int, input().split()) a, b = min(a, b), max(a, b) s = a + min(c + c + a, c + b, a + b + b) print(s) ```
3
451
A
Game With Sticks
PROGRAMMING
900
[ "implementation" ]
null
null
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid show...
The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game.
[ "2 2\n", "2 3\n", "3 3\n" ]
[ "Malvika\n", "Malvika\n", "Akshat\n" ]
Explanation of the first sample: The grid has four intersection points, numbered from 1 to 4. If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this. Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remov...
500
[ { "input": "2 2", "output": "Malvika" }, { "input": "2 3", "output": "Malvika" }, { "input": "3 3", "output": "Akshat" }, { "input": "20 68", "output": "Malvika" }, { "input": "1 1", "output": "Akshat" }, { "input": "1 2", "output": "Akshat" }, ...
1,692,802,900
2,147,483,647
Python 3
OK
TESTS
28
46
0
# 451A - Game With Sticks n,m = map(int, input().split()) tmp = min(n,m) if tmp % 2 == 0: print("Malvika") else: print("Akshat")
Title: Game With Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid...
```python # 451A - Game With Sticks n,m = map(int, input().split()) tmp = min(n,m) if tmp % 2 == 0: print("Malvika") else: print("Akshat") ```
3
317
A
Perfect Pair
PROGRAMMING
1,600
[ "brute force" ]
null
null
Let us call a pair of integer numbers *m*-perfect, if at least one number in the pair is greater than or equal to *m*. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not. Two integers *x*, *y* are written on the blackboard. It is allowed to erase one of them and replace it with the sum of th...
Single line of the input contains three integers *x*, *y* and *m* (<=-<=1018<=≤<=*x*, *y*, *m*<=≤<=1018). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preffered to use the cin, cout streams or the %I64d specifier.
Print the minimum number of operations or "-1" (without quotes), if it is impossible to transform the given pair to the *m*-perfect one.
[ "1 2 5\n", "-1 4 15\n", "0 -1 5\n" ]
[ "2\n", "4\n", "-1\n" ]
In the first sample the following sequence of operations is suitable: (1, 2) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (3, 2) <img align="middle" class="tex-formula" src="https://espresso.cod...
500
[ { "input": "1 2 5", "output": "2" }, { "input": "-1 4 15", "output": "4" }, { "input": "0 -1 5", "output": "-1" }, { "input": "0 1 8", "output": "5" }, { "input": "-134 -345 -134", "output": "0" }, { "input": "-134 -345 -133", "output": "-1" }, ...
1,672,585,285
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
92
0
x,y,m = [int(i) for i in input().split()] ans = 0 for j in range(1000): if x < y: x, y = y, x if max(x, y) >= m: break ans += 1 y = y + x if max(x, y) >= m: print(ans) else: print(-1)
Title: Perfect Pair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let us call a pair of integer numbers *m*-perfect, if at least one number in the pair is greater than or equal to *m*. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not. Two integers *x*, *y* a...
```python x,y,m = [int(i) for i in input().split()] ans = 0 for j in range(1000): if x < y: x, y = y, x if max(x, y) >= m: break ans += 1 y = y + x if max(x, y) >= m: print(ans) else: print(-1) ```
0
300
C
Beautiful Numbers
PROGRAMMING
1,800
[ "brute force", "combinatorics" ]
null
null
Vitaly is a very weird man. He's got two favorite digits *a* and *b*. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits *a* and *b*. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite dig...
The first line contains three integers: *a*, *b*, *n* (1<=≤<=*a*<=&lt;<=*b*<=≤<=9,<=1<=≤<=*n*<=≤<=106).
Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7).
[ "1 3 3\n", "2 3 10\n" ]
[ "1\n", "165\n" ]
none
2,000
[ { "input": "1 3 3", "output": "1" }, { "input": "2 3 10", "output": "165" }, { "input": "6 8 14215", "output": "651581472" }, { "input": "4 9 104671", "output": "329390901" }, { "input": "6 7 78755", "output": "0" }, { "input": "1 8 265", "output":...
1,670,496,361
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
2,000
1,536,000
mod = 10**9+7 import math as m def ss(s,a,b): while s>0: x = s%10 s = s//10 if x!= a and x!=b: return False return True def ss2(n,i): return m.factorial(n)//(m.factorial(n-i)*m.factorial(i)) %mod a, b, n = map(int,input().split()) if a>b: a,b = b,...
Title: Beautiful Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly is a very weird man. He's got two favorite digits *a* and *b*. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits *a* and *b*. Vitaly calls a good number ex...
```python mod = 10**9+7 import math as m def ss(s,a,b): while s>0: x = s%10 s = s//10 if x!= a and x!=b: return False return True def ss2(n,i): return m.factorial(n)//(m.factorial(n-i)*m.factorial(i)) %mod a, b, n = map(int,input().split()) if a>b: ...
0
114
A
Cifera
PROGRAMMING
1,000
[ "math" ]
null
null
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million...
The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1).
You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*.
[ "5\n25\n", "3\n8\n" ]
[ "YES\n1\n", "NO\n" ]
none
500
[ { "input": "5\n25", "output": "YES\n1" }, { "input": "3\n8", "output": "NO" }, { "input": "123\n123", "output": "YES\n0" }, { "input": "99\n970300", "output": "NO" }, { "input": "1000\n6666666", "output": "NO" }, { "input": "59\n3571", "output": "N...
1,643,884,625
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
import math a = int(input()) b = int(input()) x = 1 while True: x += 1 if math.pow(a, x) == b: print('Yes') if x == 2: print(1) break else: print(0) break else: print('No') break
Title: Cifera Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa...
```python import math a = int(input()) b = int(input()) x = 1 while True: x += 1 if math.pow(a, x) == b: print('Yes') if x == 2: print(1) break else: print(0) break else: print('No') break ```
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,635,667,988
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
4,198,400
val=[int(ele) for ele in input().split(' ')] mn=val[0]*val[1] n=mn//12 print(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 val=[int(ele) for ele in input().split(' ')] mn=val[0]*val[1] n=mn//12 print(n) ```
0
0
none
none
none
0
[ "none" ]
null
null
This is an interactive problem. In the output section below you will see the information about flushing the output. On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in Vičkopolis. Upon arrival, they left the car in a huge parking lot near the...
There are two numbers *n* and *k* (2<=≤<=*k*<=≤<=*n*<=≤<=105) in the single line of input denoting the number of dishes in the menu and the number of dishes Noora ordered.
If you want to provide an answer, output a string of the form 2 *x* *y* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*), if you think the dishes *x* and *y* was among dishes ordered by Noora. After that, flush the output and terminate your program.
[ "3 2\nNIE\nTAK\nNIE\nTAK\nTAK\nTAK\n" ]
[ "1 1 2\n1 2 1\n1 1 3\n1 3 1\n1 2 3\n1 3 2\n2 2 3\n" ]
There are three dishes in sample. Noora ordered dished numberes 2 and 3, which Leha should guess. If Noora receive requests for the first dish (*x* = 1), then she'll choose the second dish (*a* = 2) as the dish with the minimum value <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e5a4a1705...
0
[]
1,566,397,977
3,957
Python 3
WRONG_ANSWER
TESTS
0
109
0
import math def query(x,y): print(1, x+1, y+1) return input() == "TAK" n,k = map(int,input().split()) low = 0 high = n while high - low > 1: mid = (low+high)//2 left = query(mid, mid+1) if left: high = mid+1 else: low = mid+1 d1 = low goLeft = True if d1>n//2: # right small...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: This is an interactive problem. In the output section below you will see the information about flushing the output. On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious...
```python import math def query(x,y): print(1, x+1, y+1) return input() == "TAK" n,k = map(int,input().split()) low = 0 high = n while high - low > 1: mid = (low+high)//2 left = query(mid, mid+1) if left: high = mid+1 else: low = mid+1 d1 = low goLeft = True if d1>n//2: # r...
0
318
A
Even Odds
PROGRAMMING
900
[ "math" ]
null
null
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow...
The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Print the number that will stand at the position number *k* after Volodya's manipulations.
[ "10 3\n", "7 7\n" ]
[ "5", "6" ]
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
500
[ { "input": "10 3", "output": "5" }, { "input": "7 7", "output": "6" }, { "input": "7 1", "output": "1" }, { "input": "7 2", "output": "3" }, { "input": "8 5", "output": "2" }, { "input": "8 3", "output": "5" }, { "input": "8 4", "output...
1,697,096,193
2,147,483,647
Python 3
OK
TESTS
25
92
716,800
# Решение задач проекта CODEFORSES, Задача 318A # # (C) 2023 Артур Ще, Москва, Россия # Released under GNU Public License (GPL) # email [email protected] # ----------------------------------------------------------- ''' A. Чет и нечет ограничение по времени на тест1 секунда ограничение по памяти на тест256 м...
Title: Even Odds Time Limit: None seconds Memory Limit: None megabytes Problem Description: Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ...
```python # Решение задач проекта CODEFORSES, Задача 318A # # (C) 2023 Артур Ще, Москва, Россия # Released under GNU Public License (GPL) # email [email protected] # ----------------------------------------------------------- ''' A. Чет и нечет ограничение по времени на тест1 секунда ограничение по памяти на...
3
248
A
Cupboards
PROGRAMMING
800
[ "implementation" ]
null
null
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on *n* woode...
The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal...
In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
[ "5\n0 1\n1 0\n0 1\n1 1\n0 1\n" ]
[ "3\n" ]
none
500
[ { "input": "5\n0 1\n1 0\n0 1\n1 1\n0 1", "output": "3" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1\n1 1\n1 1", "output": "1" }, { "input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0", "output": "7" }, { "input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ...
1,624,511,935
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
56
2,000
819,200
n=int(input()) ll,rl=[],[] for i in range(n): l,r=input().split() l,r=int(l),int(r) ll.append(l) rl.append(r) sl=sum(ll) sr=sum(rl) def cupboard(ll,rl,sl,sr,n): st_l=list(map(str,ll)) st_r=list(map(str,rl)) if(sl>sr): s1=n-sl m1,m...
Title: Cupboards Time Limit: None seconds Memory Limit: None megabytes Problem Description: One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long...
```python n=int(input()) ll,rl=[],[] for i in range(n): l,r=input().split() l,r=int(l),int(r) ll.append(l) rl.append(r) sl=sum(ll) sr=sum(rl) def cupboard(ll,rl,sl,sr,n): st_l=list(map(str,ll)) st_r=list(map(str,rl)) if(sl>sr): s1=n-sl ...
0
65
D
Harry Potter and the Sorting Hat
PROGRAMMING
2,200
[ "brute force", "dfs and similar", "hashing" ]
D. Harry Potter and the Sorting Hat
2
256
As you know, Hogwarts has four houses: Gryffindor, Hufflepuff, Ravenclaw and Slytherin. The sorting of the first-years into houses is done by the Sorting Hat. The pupils are called one by one in the alphabetical order, each of them should put a hat on his head and, after some thought, the hat solemnly announces the nam...
The first input line contains an integer *n* (1<=≤<=*n*<=≤<=10000). It is the number of students who are in the list before Hermione. The next line contains *n* symbols. If all the relatives of a student used to study in the same house, then the *i*-th character in the string coincides with the first letter of the name...
Print all the possible houses where Hermione can be sent. The names of the houses should be printed in the alphabetical order, one per line.
[ "11\nG????SS???H\n", "2\nH?\n" ]
[ "Gryffindor\nRavenclaw\n", "Gryffindor\nRavenclaw\nSlytherin\n" ]
Consider the second example. There are only two students before Hermione. The first student is sent to Hufflepuff. The second disciple is given the choice between the houses where the least number of students has been sent, i.e. Gryffindor, Slytherin and Ravenclaw. If he chooses Gryffindor, Hermione is forced to choose...
2,000
[ { "input": "11\nG????SS???H", "output": "Gryffindor\nRavenclaw" }, { "input": "2\nH?", "output": "Gryffindor\nRavenclaw\nSlytherin" }, { "input": "1\n?", "output": "Gryffindor\nHufflepuff\nRavenclaw\nSlytherin" }, { "input": "1\nG", "output": "Hufflepuff\nRavenclaw\nSlyth...
1,664,090,490
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
61
3,276,800
houses = ['G', 'H', 'R', 'S'] full_houses = ['Gryffindor', 'Hufflepuff', 'Ravenclaw', 'Slytherin'] res = set() def get_Hermione_house(students_sent, inputs): print(students_sent, inputs) least = min(students_sent) if not inputs: res.update([idx for idx, num in enumerate( stud...
Title: Harry Potter and the Sorting Hat Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: As you know, Hogwarts has four houses: Gryffindor, Hufflepuff, Ravenclaw and Slytherin. The sorting of the first-years into houses is done by the Sorting Hat. The pupils are called one by one in the alphabe...
```python houses = ['G', 'H', 'R', 'S'] full_houses = ['Gryffindor', 'Hufflepuff', 'Ravenclaw', 'Slytherin'] res = set() def get_Hermione_house(students_sent, inputs): print(students_sent, inputs) least = min(students_sent) if not inputs: res.update([idx for idx, num in enumerate( ...
0
934
A
A Compatible Pair
PROGRAMMING
1,400
[ "brute force", "games" ]
null
null
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big B...
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109.
Print a single integer — the brightness of the chosen pair.
[ "2 2\n20 18\n2 14\n", "5 3\n-1 0 1 2 3\n-1 0 1\n" ]
[ "252\n", "2\n" ]
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
500
[ { "input": "2 2\n20 18\n2 14", "output": "252" }, { "input": "5 3\n-1 0 1 2 3\n-1 0 1", "output": "2" }, { "input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7", "output": "70" }, { "input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 ...
1,580,557,606
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
140
1,331,200
n, m = map(int, input().split()) lst1 = [int(i) for i in input().split()] lst2 = [int(i) for i in input().split()] _max = -1e10 _1 = 0 for i in range(n): for j in range(m): if lst1[i] * lst2[j] > _max: _max = lst1[i] * lst2[j] _1 = i _max = -1e10 for i in range(n): for j in range...
Title: A Compatible Pair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cr...
```python n, m = map(int, input().split()) lst1 = [int(i) for i in input().split()] lst2 = [int(i) for i in input().split()] _max = -1e10 _1 = 0 for i in range(n): for j in range(m): if lst1[i] * lst2[j] > _max: _max = lst1[i] * lst2[j] _1 = i _max = -1e10 for i in range(n): for ...
0
573
A
Bear and Poker
PROGRAMMING
1,300
[ "implementation", "math", "number theory" ]
null
null
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars. Each player can double his bid any number of times and triple his bid any nu...
First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players. The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players.
Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.
[ "4\n75 150 75 50\n", "3\n100 150 250\n" ]
[ "Yes\n", "No\n" ]
In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal.
500
[ { "input": "4\n75 150 75 50", "output": "Yes" }, { "input": "3\n100 150 250", "output": "No" }, { "input": "7\n34 34 68 34 34 68 34", "output": "Yes" }, { "input": "10\n72 96 12 18 81 20 6 2 54 1", "output": "No" }, { "input": "20\n958692492 954966768 77387000 724...
1,586,104,258
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
139
6,963,200
n=int(input()) l=[int(x) for x in input().split(" ")] l.sort(reverse=True) flag=0 for i in l: if i!=l[0]: a=l[0]/i if a%2==0 or a%3==0 or a%6==0: pass else: flag=1 print("NO") break if flag==0: print("YES")
Title: Bear and Poker Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid wit...
```python n=int(input()) l=[int(x) for x in input().split(" ")] l.sort(reverse=True) flag=0 for i in l: if i!=l[0]: a=l[0]/i if a%2==0 or a%3==0 or a%6==0: pass else: flag=1 print("NO") break if flag==0: print("YES") ```
0
26
B
Regular Bracket Sequence
PROGRAMMING
1,400
[ "greedy" ]
B. Regular Bracket Sequence
5
256
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. One day Johnny got bracket sequence. He decided to remove some...
Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106.
Output the maximum possible length of a regular bracket sequence.
[ "(()))(\n", "((()())\n" ]
[ "4\n", "6\n" ]
none
1,000
[ { "input": "(()))(", "output": "4" }, { "input": "((()())", "output": "6" }, { "input": "(", "output": "0" }, { "input": ")", "output": "0" }, { "input": ")(()(", "output": "2" }, { "input": "))))))(", "output": "0" }, { "input": "()()(()((...
1,699,367,702
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
0
kl=input() gb=list() wsx=0 for i in range(len(kl)): if kl[i]=='(': gb.append('(') else: if len(gb)==0: cnt+=1 else: wsx.pop() wsx+=len(gb) print(len(kl)-wsx)
Title: Regular Bracket Sequence Time Limit: 5 seconds Memory Limit: 256 megabytes Problem Description: A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regula...
```python kl=input() gb=list() wsx=0 for i in range(len(kl)): if kl[i]=='(': gb.append('(') else: if len(gb)==0: cnt+=1 else: wsx.pop() wsx+=len(gb) print(len(kl)-wsx) ```
-1
922
A
Cloning Toys
PROGRAMMING
1,300
[ "implementation" ]
null
null
Imp likes his plush toy a lot. Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one origina...
The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one).
Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "6 3\n", "4 2\n", "1000 1001\n" ]
[ "Yes\n", "No\n", "Yes\n" ]
In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
500
[ { "input": "6 3", "output": "Yes" }, { "input": "4 2", "output": "No" }, { "input": "1000 1001", "output": "Yes" }, { "input": "1000000000 999999999", "output": "Yes" }, { "input": "81452244 81452247", "output": "No" }, { "input": "188032448 86524683",...
1,570,567,590
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
from sys import stdin c, o = (int(x) for x in stdin.readline().split()) if o > 0 and c >= o-1 and (c-(o-1) % 2) == 0: print("Yes") else: print ("No")
Title: Cloning Toys Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imp likes his plush toy a lot. Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applie...
```python from sys import stdin c, o = (int(x) for x in stdin.readline().split()) if o > 0 and c >= o-1 and (c-(o-1) % 2) == 0: print("Yes") else: print ("No") ```
0
49
A
Sleuth
PROGRAMMING
800
[ "implementation" ]
A. Sleuth
2
256
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans...
The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter.
Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No". Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters.
[ "Is it a melon?\n", "Is it an apple?\n", "Is it a banana ?\n", "Is it an apple and a banana simultaneouSLY?\n" ]
[ "NO\n", "YES\n", "YES\n", "YES\n" ]
none
500
[ { "input": "Is it a melon?", "output": "NO" }, { "input": "Is it an apple?", "output": "YES" }, { "input": " Is it a banana ?", "output": "YES" }, { "input": "Is it an apple and a banana simultaneouSLY?", "output": "YES" }, { "input": "oHtSbDwzHb?", ...
1,695,532,911
2,147,483,647
PyPy 3-64
OK
TESTS
35
124
0
g=['A', 'E', 'I', 'O', 'U', 'Y'] sg=['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Z'] s=input().replace("?","").split() print("YES" if s[-1][-1].upper() in g else "NO")
Title: Sleuth Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ...
```python g=['A', 'E', 'I', 'O', 'U', 'Y'] sg=['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Z'] s=input().replace("?","").split() print("YES" if s[-1][-1].upper() in g else "NO") ```
3.969
496
A
Minimum Difficulty
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Mike is trying rock climbing but he is awful at it. There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=&lt;<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,...
The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds. The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strict...
Print a single number — the minimum difficulty of the track after removing a single hold.
[ "3\n1 4 6\n", "5\n1 2 3 4 5\n", "5\n1 2 3 7 8\n" ]
[ "5\n", "2\n", "4\n" ]
In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5. In the second test after removing every hold the difficulty equals 2. In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for whic...
500
[ { "input": "3\n1 4 6", "output": "5" }, { "input": "5\n1 2 3 4 5", "output": "2" }, { "input": "5\n1 2 3 7 8", "output": "4" }, { "input": "3\n1 500 1000", "output": "999" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "2" }, { "input": "10\n1 4 9...
1,599,171,116
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
93
307,200
if __name__ == '__main__': n = int(input()) holdList = [int(i) for i in input().split()] tmpList, minDif, maxDif = [], max(holdList), 0 for i in range(1, n - 1): tmpList = holdList[:] del(tmpList[i]) for j in range(0, n - 2): maxDif = max(maxDif, tmpList[j + 1] - tmpList[j]) minDif = min(minDif,...
Title: Minimum Difficulty Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mike is trying rock climbing but he is awful at it. There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=&lt;<=*a**i*<=+<=1 fo...
```python if __name__ == '__main__': n = int(input()) holdList = [int(i) for i in input().split()] tmpList, minDif, maxDif = [], max(holdList), 0 for i in range(1, n - 1): tmpList = holdList[:] del(tmpList[i]) for j in range(0, n - 2): maxDif = max(maxDif, tmpList[j + 1] - tmpList[j]) minDif = m...
0
978
B
File Name
PROGRAMMING
800
[ "greedy", "strings" ]
null
null
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia...
The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name. The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name.
Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0.
[ "6\nxxxiii\n", "5\nxxoxx\n", "10\nxxxxxxxxxx\n" ]
[ "1\n", "0\n", "8\n" ]
In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
0
[ { "input": "6\nxxxiii", "output": "1" }, { "input": "5\nxxoxx", "output": "0" }, { "input": "10\nxxxxxxxxxx", "output": "8" }, { "input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "98" }, { ...
1,655,226,496
2,147,483,647
Python 3
OK
TESTS
13
31
0
n = int(input()) s = input() tot = 0 for i in range(2, n): if s[i] == s[i - 1] and s[i - 1] == s[i - 2] and s[i] == 'x': tot+= 1 print(tot)
Title: File Name Time Limit: None seconds Memory Limit: None megabytes Problem Description: You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin let...
```python n = int(input()) s = input() tot = 0 for i in range(2, n): if s[i] == s[i - 1] and s[i - 1] == s[i - 2] and s[i] == 'x': tot+= 1 print(tot) ```
3
386
A
Second-Price Auction
PROGRAMMING
800
[ "implementation" ]
null
null
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the au...
The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder.
The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.
[ "2\n5 7\n", "3\n10 2 8\n", "6\n3 8 2 9 4 14\n" ]
[ "2 5\n", "1 8\n", "6 9\n" ]
none
500
[ { "input": "2\n5 7", "output": "2 5" }, { "input": "3\n10 2 8", "output": "1 8" }, { "input": "6\n3 8 2 9 4 14", "output": "6 9" }, { "input": "4\n4707 7586 4221 5842", "output": "2 5842" }, { "input": "5\n3304 4227 4869 6937 6002", "output": "4 6002" }, {...
1,686,648,167
2,147,483,647
PyPy 3-64
OK
TESTS
42
77
0
n = int(input()) b = list(map(int,input().split(' '))) max = b[0] max2 = -1 index = 0 for i in range (0,n): if max < b[i] : max = b[i] index = i for i in range (0,n): if max2 < b[i] < max: max2 = b[i] print(index+1, max2)
Title: Second-Price Auction Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is...
```python n = int(input()) b = list(map(int,input().split(' '))) max = b[0] max2 = -1 index = 0 for i in range (0,n): if max < b[i] : max = b[i] index = i for i in range (0,n): if max2 < b[i] < max: max2 = b[i] print(index+1, max2) ```
3
371
C
Hamburgers
PROGRAMMING
1,600
[ "binary search", "brute force" ]
null
null
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (...
The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C). The second line contains three integers *n...
Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.
[ "BBBSSC\n6 4 1\n1 2 3\n4\n", "BBC\n1 10 1\n1 10 1\n21\n", "BSC\n1 1 1\n1 1 3\n1000000000000\n" ]
[ "2\n", "7\n", "200000000001\n" ]
none
1,500
[ { "input": "BBBSSC\n6 4 1\n1 2 3\n4", "output": "2" }, { "input": "BBC\n1 10 1\n1 10 1\n21", "output": "7" }, { "input": "BSC\n1 1 1\n1 1 3\n1000000000000", "output": "200000000001" }, { "input": "B\n1 1 1\n1 1 1\n381", "output": "382" }, { "input": "BSC\n3 5 6\n7...
1,624,386,177
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
21
77
204,800
import sys,math from collections import deque,defaultdict import operator as op from functools import reduce from itertools import permutations import heapq #sys.setrecursionlimit(10**7) # OneDrive\Documents\codeforces I=sys.stdin.readline alpha="abcdefghijklmnopqrstuvwxyz" mod=10**9 + 7 """ x_mo...
Title: Hamburgers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He ...
```python import sys,math from collections import deque,defaultdict import operator as op from functools import reduce from itertools import permutations import heapq #sys.setrecursionlimit(10**7) # OneDrive\Documents\codeforces I=sys.stdin.readline alpha="abcdefghijklmnopqrstuvwxyz" mod=10**9 + 7 ...
0
817
C
Really Big Numbers
PROGRAMMING
1,600
[ "binary search", "brute force", "dp", "math" ]
null
null
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different...
The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018).
Print one integer — the quantity of really big numbers that are not greater than *n*.
[ "12 1\n", "25 20\n", "10 9\n" ]
[ "3\n", "0\n", "1\n" ]
In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20). In the third example 10 is the only really big number (10 - 1 ≥ 9).
0
[ { "input": "12 1", "output": "3" }, { "input": "25 20", "output": "0" }, { "input": "10 9", "output": "1" }, { "input": "300 1000", "output": "0" }, { "input": "500 1000", "output": "0" }, { "input": "1000 2000", "output": "0" }, { "input":...
1,588,308,127
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
108
0
import math n,s=map(int,input().split()) k=math.ceil(s/9.0) k=int(k) ans=n-9*k print(max(0,ans))
Title: Really Big Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its...
```python import math n,s=map(int,input().split()) k=math.ceil(s/9.0) k=int(k) ans=n-9*k print(max(0,ans)) ```
0
981
E
Addition on Segments
PROGRAMMING
2,200
[ "bitmasks", "data structures", "divide and conquer", "dp" ]
null
null
Grisha come to a contest and faced the following problem. You are given an array of size $n$, initially consisting of zeros. The elements of the array are enumerated from $1$ to $n$. You perform $q$ operations on the array. The $i$-th operation is described with three integers $l_i$, $r_i$ and $x_i$ ($1 \leq l_i \leq ...
The first line contains two integers $n$ and $q$ ($1 \leq n, q \leq 10^{4}$) — the length of the array and the number of queries in the initial problem. The following $q$ lines contain queries, one per line. The $i$-th of these lines contains three integers $l_i$, $r_i$ and $x_i$ ($1 \leq l_i \leq r_i \leq n$, $1 \leq...
In the first line print the only integer $k$, denoting the number of integers from $1$ to $n$, inclusive, that can be equal to the maximum in the array after applying some subset (possibly empty) of the given operations. In the next line print these $k$ integers from $1$ to $n$ — the possible values of the maximum. Pr...
[ "4 3\n1 3 1\n2 4 2\n3 4 4\n", "7 2\n1 5 1\n3 7 2\n", "10 3\n1 1 2\n1 1 3\n1 1 6\n" ]
[ "4\n1 2 3 4 \n", "3\n1 2 3 \n", "6\n2 3 5 6 8 9 \n" ]
Consider the first example. If you consider the subset only of the first query, the maximum is equal to $1$. If you take only the second query, the maximum equals to $2$. If you take the first two queries, the maximum becomes $3$. If you take only the fourth query, the maximum becomes $4$. If you take the fourth query ...
2,250
[ { "input": "4 3\n1 3 1\n2 4 2\n3 4 4", "output": "4\n1 2 3 4 " }, { "input": "7 2\n1 5 1\n3 7 2", "output": "3\n1 2 3 " }, { "input": "10 3\n1 1 2\n1 1 3\n1 1 6", "output": "6\n2 3 5 6 8 9 " }, { "input": "45 5\n37 38 16\n5 7 34\n1 42 31\n8 27 19\n15 28 39", "output": "5\...
1,527,452,124
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
1,638,400
from itertools import permutations n, q = list(map(int, input().split())) s = [int(0) for i in range(n)] sCopy = s.copy() maxC = 0 maxValues = [] qList = [] for i in range(q): l, r, x = list(map(lambda x: int(x) - 1, input().split())) x += 1 qList.append((l, r, x)) for posl in permutations(rang...
Title: Addition on Segments Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grisha come to a contest and faced the following problem. You are given an array of size $n$, initially consisting of zeros. The elements of the array are enumerated from $1$ to $n$. You perform $q$ operations on ...
```python from itertools import permutations n, q = list(map(int, input().split())) s = [int(0) for i in range(n)] sCopy = s.copy() maxC = 0 maxValues = [] qList = [] for i in range(q): l, r, x = list(map(lambda x: int(x) - 1, input().split())) x += 1 qList.append((l, r, x)) for posl in permuta...
0
431
A
Black Square
PROGRAMMING
800
[ "implementation" ]
null
null
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o...
The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104). The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a...
Print a single integer — the total number of calories that Jury wastes.
[ "1 2 3 4\n123214\n", "1 5 3 2\n11221\n" ]
[ "13\n", "13\n" ]
none
500
[ { "input": "1 2 3 4\n123214", "output": "13" }, { "input": "1 5 3 2\n11221", "output": "13" }, { "input": "5 5 5 1\n3422", "output": "16" }, { "input": "4 3 2 1\n2", "output": "3" }, { "input": "5651 6882 6954 4733\n2442313421", "output": "60055" }, { ...
1,699,883,045
2,147,483,647
PyPy 3-64
OK
TESTS
49
62
1,740,800
x = [int(a) for a in input().split()] s = input() cnt = 0 for i in s: cnt += x[int(i)-1] print(cnt)
Title: Black Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four ve...
```python x = [int(a) for a in input().split()] s = input() cnt = 0 for i in s: cnt += x[int(i)-1] print(cnt) ```
3
757
B
Bash's Big Day
PROGRAMMING
1,400
[ "greedy", "math", "number theory" ]
null
null
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases. But Zulu warns him that a group of *k*<=&gt;<=1 Pokemon with strengths {*...
The input consists of two lines. The first line contains an integer *n* (1<=≤<=*n*<=≤<=105), the number of Pokemon in the lab. The next line contains *n* space separated integers, where the *i*-th of them denotes *s**i* (1<=≤<=*s**i*<=≤<=105), the strength of the *i*-th Pokemon.
Print single integer — the maximum number of Pokemons Bash can take.
[ "3\n2 3 4\n", "5\n2 3 4 6 7\n" ]
[ "2\n", "3\n" ]
*gcd* (greatest common divisor) of positive integers set {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>} is the maximum positive integer that divides all the integers {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a...
1,000
[ { "input": "3\n2 3 4", "output": "2" }, { "input": "5\n2 3 4 6 7", "output": "3" }, { "input": "3\n5 6 4", "output": "2" }, { "input": "8\n41 74 4 27 85 39 100 36", "output": "4" }, { "input": "6\n89 20 86 81 62 23", "output": "3" }, { "input": "71\n23...
1,665,731,488
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
10
2,000
13,312,000
def spf(num): result = [] while num != 1: for i in range(2,num +1): if (num %i) == 0: num //= i result.append(i) break return list(set(result)) n = int(input()) row = list(map(int, input().split())) res = [0] * (max(row) + 1)...
Title: Bash's Big Day Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon fr...
```python def spf(num): result = [] while num != 1: for i in range(2,num +1): if (num %i) == 0: num //= i result.append(i) break return list(set(result)) n = int(input()) row = list(map(int, input().split())) res = [0] * (max...
0
593
A
2Char
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sendi...
The first line of the input contains number *n* (1<=≤<=*n*<=≤<=100) — the number of words in the article chosen by Andrew. Following are *n* lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct,...
Print a single integer — the maximum possible total length of words in Andrew's article.
[ "4\nabb\ncacc\naaa\nbbb\n", "5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa\n" ]
[ "9", "6" ]
In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}. In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}.
250
[ { "input": "4\nabb\ncacc\naaa\nbbb", "output": "9" }, { "input": "5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa", "output": "6" }, { "input": "1\na", "output": "1" }, { "input": "2\nz\nz", "output": "2" }, { "input": "5\nabcde\nfghij\nklmno\npqrst\nuvwxy", "output"...
1,446,761,732
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
words = [raw_input() for _ in range(int(raw_input()))] alphabet = 'abcdefghijklmnopqrstuvwxyz' Max = 0 for c in alphabet: for cc in alphabet: s = 0 for w in words: if set([ i for i in w]) <= {c, cc}: s += len(w) Max = max(Max, s) print(Max)
Title: 2Char Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written an...
```python words = [raw_input() for _ in range(int(raw_input()))] alphabet = 'abcdefghijklmnopqrstuvwxyz' Max = 0 for c in alphabet: for cc in alphabet: s = 0 for w in words: if set([ i for i in w]) <= {c, cc}: s += len(w) Max = max(Max, s) print(Max) ```
-1
225
A
Dice Tower
PROGRAMMING
1,100
[ "constructive algorithms", "greedy" ]
null
null
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left). Alice...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of dice in the tower. The second line contains an integer *x* (1<=≤<=*x*<=≤<=6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*,<=*b**i* (1<=≤<=...
Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes).
[ "3\n6\n3 2\n5 4\n2 4\n", "3\n3\n2 6\n4 1\n5 3\n" ]
[ "YES", "NO" ]
none
500
[ { "input": "3\n6\n3 2\n5 4\n2 4", "output": "YES" }, { "input": "3\n3\n2 6\n4 1\n5 3", "output": "NO" }, { "input": "1\n3\n2 1", "output": "YES" }, { "input": "2\n2\n3 1\n1 5", "output": "NO" }, { "input": "3\n2\n1 4\n5 3\n6 4", "output": "NO" }, { "in...
1,610,031,804
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
186
307,200
comp = {1:6,6:1,2:5,5:2,3:4,4:3} rem = {1:(5,2),2:(1,6),3:(1,6),4:(5,2),5:(1,6),6:(4,3)} n = int(input()) top = int(input()) prevcomp = comp[top] flag = True for i in range(n): x,y = [int(x) for x in input().split()] if prevcomp==rem[x][0]: prevcomp=rem[x][1] elif prevcomp==rem[x][1]: ...
Title: Dice Tower Time Limit: None seconds Memory Limit: None megabytes Problem Description: A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other...
```python comp = {1:6,6:1,2:5,5:2,3:4,4:3} rem = {1:(5,2),2:(1,6),3:(1,6),4:(5,2),5:(1,6),6:(4,3)} n = int(input()) top = int(input()) prevcomp = comp[top] flag = True for i in range(n): x,y = [int(x) for x in input().split()] if prevcomp==rem[x][0]: prevcomp=rem[x][1] elif prevcomp==rem[x...
0
818
E
Card Game Again
PROGRAMMING
1,900
[ "binary search", "data structures", "number theory", "two pointers" ]
null
null
Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of *n* cards and a magic number *k*. The order of the cards in the deck is fixed. Each card has a number written on it; number *a**i* is written on the *i*-th card in the deck. After re...
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=109). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) — the numbers written on the cards.
Print the number of ways to choose *x* and *y* so the resulting deck is valid.
[ "3 4\n6 2 8\n", "3 6\n9 1 14\n" ]
[ "4\n", "1\n" ]
In the first example the possible values of *x* and *y* are: 1. *x* = 0, *y* = 0; 1. *x* = 1, *y* = 0; 1. *x* = 2, *y* = 0; 1. *x* = 0, *y* = 1.
0
[ { "input": "3 4\n6 2 8", "output": "4" }, { "input": "3 6\n9 1 14", "output": "1" }, { "input": "5 1\n1 3 1 3 1", "output": "15" }, { "input": "5 1\n5 5 5 5 5", "output": "15" }, { "input": "5 1\n5 4 4 4 4", "output": "15" }, { "input": "100 1\n1 1 1 1...
1,690,714,768
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1690714768.3600838")# 1690714768.3601022
Title: Card Game Again Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of *n* cards and a magic number *k*. The order of the cards in the deck is fixed. Eac...
```python print("_RANDOM_GUESS_1690714768.3600838")# 1690714768.3601022 ```
0
445
A
DZY Loves Chessboard
PROGRAMMING
1,200
[ "dfs and similar", "implementation" ]
null
null
DZY loves chessboard, and he enjoys playing with it. He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th...
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ...
Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell. If multiple answers exist, print any of them. It ...
[ "1 1\n.\n", "2 2\n..\n..\n", "3 3\n.-.\n---\n--." ]
[ "B\n", "BW\nWB\n", "B-B\n---\n--B" ]
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK. In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output. In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
500
[ { "input": "1 1\n.", "output": "B" }, { "input": "2 2\n..\n..", "output": "BW\nWB" }, { "input": "3 3\n.-.\n---\n--.", "output": "B-B\n---\n--B" }, { "input": "3 1\n-\n.\n.", "output": "-\nW\nB" }, { "input": "11 11\n-----------\n-----------\n-----------\n--------...
1,622,708,383
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
139
0
n,m = map(int, input().split()) mat=[] for i in range(0,n): s=list(input()) mat.append(s) #print(mat) for i in range(0,n): for j in range(0,m): if(mat[i][j]=='.'): if((j+i)%2==0): mat[i][j]="B" else: mat[i][j]="W" for i in range(0,...
Title: DZY Loves Chessboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY loves chessboard, and he enjoys playing with it. He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ...
```python n,m = map(int, input().split()) mat=[] for i in range(0,n): s=list(input()) mat.append(s) #print(mat) for i in range(0,n): for j in range(0,m): if(mat[i][j]=='.'): if((j+i)%2==0): mat[i][j]="B" else: mat[i][j]="W" for i i...
0
999
B
Reversing Encryption
PROGRAMMING
900
[ "implementation" ]
null
null
A string $s$ of length $n$ can be encrypted by the following algorithm: - iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$). For example, the above algor...
The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters.
Print a string $s$ such that the above algorithm results in $t$.
[ "10\nrocesfedoc\n", "16\nplmaetwoxesisiht\n", "1\nz\n" ]
[ "codeforces\n", "thisisexampletwo\n", "z\n" ]
The first example is described in the problem statement.
0
[ { "input": "10\nrocesfedoc", "output": "codeforces" }, { "input": "16\nplmaetwoxesisiht", "output": "thisisexampletwo" }, { "input": "1\nz", "output": "z" }, { "input": "2\nir", "output": "ri" }, { "input": "3\nilj", "output": "jli" }, { "input": "4\nj...
1,608,874,337
2,147,483,647
PyPy 3
OK
TESTS
20
155
0
def div(n): out=[] for i in range(1,n+1): if n%i==0: out.append(i) return out n=int(input()) s=input() d=div(n) for i in d: t=s[:i] s=t[::-1]+s[i:] print(s)
Title: Reversing Encryption Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string $s$ of length $n$ can be encrypted by the following algorithm: - iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$...
```python def div(n): out=[] for i in range(1,n+1): if n%i==0: out.append(i) return out n=int(input()) s=input() d=div(n) for i in d: t=s[:i] s=t[::-1]+s[i:] print(s) ```
3
869
A
The Artful Expedient
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive integer *n* is decided first. Both Koyomi and Karen independently choose *n* distinct positive integers, deno...
The first line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=2<=000) — the length of both sequences. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=2·106) — the integers finally chosen by Koyomi. The third line contains *n* space-separated integers *y*1,<=...
Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.
[ "3\n1 2 3\n4 5 6\n", "5\n2 4 6 8 10\n9 7 5 3 1\n" ]
[ "Karen\n", "Karen\n" ]
In the first example, there are 6 pairs satisfying the constraint: (1, 1), (1, 2), (2, 1), (2, 3), (3, 2) and (3, 3). Thus, Karen wins since 6 is an even number. In the second example, there are 16 such pairs, and Karen wins again.
500
[ { "input": "3\n1 2 3\n4 5 6", "output": "Karen" }, { "input": "5\n2 4 6 8 10\n9 7 5 3 1", "output": "Karen" }, { "input": "1\n1\n2000000", "output": "Karen" }, { "input": "2\n97153 2000000\n1999998 254", "output": "Karen" }, { "input": "15\n31 30 29 28 27 26 25 24...
1,507,644,353
2,147,483,647
Python 3
OK
TESTS
49
62
614,400
n = int(input()) xs = list(map(int, input().split())) ys = list(map(int, input().split())) # cnt = 0 # for i in range(n): # for j in range(n): # xor = xs[i] ^ ys[j] # if xor in xs or xor in ys: # cnt += 1 # if cnt % 2 == 0: # print('Karen') # else: # print('Koyomi') # xi ^ yj ...
Title: The Artful Expedient Time Limit: None seconds Memory Limit: None megabytes Problem Description: Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive int...
```python n = int(input()) xs = list(map(int, input().split())) ys = list(map(int, input().split())) # cnt = 0 # for i in range(n): # for j in range(n): # xor = xs[i] ^ ys[j] # if xor in xs or xor in ys: # cnt += 1 # if cnt % 2 == 0: # print('Karen') # else: # print('Koyomi') ...
3
414
A
Mashmokh and Numbers
PROGRAMMING
1,500
[ "constructive algorithms", "number theory" ]
null
null
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh writes sequence of *n* distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he r...
The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*<=≤<=105; 0<=≤<=*k*<=≤<=108).
If such sequence doesn't exist output -1 otherwise output *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
[ "5 2\n", "5 3", "7 2\n" ]
[ "1 2 3 4 5\n", "2 4 3 7 1", "-1\n" ]
*gcd*(*x*, *y*) is greatest common divisor of *x* and *y*.
500
[ { "input": "5 2", "output": "1 2 3 4 5" }, { "input": "5 3", "output": "2 4 5 6 7" }, { "input": "7 2", "output": "-1" }, { "input": "1 1", "output": "-1" }, { "input": "2 0", "output": "-1" }, { "input": "1 10", "output": "-1" }, { "input"...
1,592,729,883
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
3
233
2,048,000
n,k=map(int,input().split()) ans=[i+1 for i in range(n)] if(k<len(ans)//2): print(-1) exit() if(k==len(ans)//2): print(*ans) exit() if(len(ans)%2==0): if(len(ans)==2): ans[0]=k ans[1]=2*k print(*ans) exit() else: score=(len(ans)-2)//2 ...
Title: Mashmokh and Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh writes sequence of *n* distinct integers on the board. Then Bimokh makes several (possibly zero) moves. ...
```python n,k=map(int,input().split()) ans=[i+1 for i in range(n)] if(k<len(ans)//2): print(-1) exit() if(k==len(ans)//2): print(*ans) exit() if(len(ans)%2==0): if(len(ans)==2): ans[0]=k ans[1]=2*k print(*ans) exit() else: score=(len(ans)-2)...
-1
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,594,172,128
2,147,483,647
PyPy 3
OK
TESTS
43
140
20,172,800
n = int(input()) p = list(input()) q = list(input()) count = 0 for i in range(n): y, m = int(p[i]), int(q[i]) t = abs(y - m) if t <= 5: count += t else: count += 10 - max(y, m) + min(y, m) print(count)
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()) p = list(input()) q = list(input()) count = 0 for i in range(n): y, m = int(p[i]), int(q[i]) t = abs(y - m) if t <= 5: count += t else: count += 10 - max(y, m) + min(y, m) print(count) ```
3
4
A
Watermelon
PROGRAMMING
800
[ "brute force", "math" ]
A. Watermelon
1
64
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and ...
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
[ "8\n" ]
[ "YES\n" ]
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
0
[ { "input": "8", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "7", "output": "NO"...
1,689,600,102
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n=int(input()) counter=0 for i in range(1,n): for j in range(i+1,n): if i+j==n and (i+j)%2==0: counter=1 break if counter==1: print("YES") else print("NO")
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin...
```python n=int(input()) counter=0 for i in range(1,n): for j in range(i+1,n): if i+j==n and (i+j)%2==0: counter=1 break if counter==1: print("YES") else print("NO") ```
-1
472
A
Design Tutorial: Learn from Math
PROGRAMMING
800
[ "math", "number theory" ]
null
null
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ...
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
[ "12\n", "15\n", "23\n", "1000000\n" ]
[ "4 8\n", "6 9\n", "8 15\n", "500000 500000\n" ]
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
500
[ { "input": "12", "output": "4 8" }, { "input": "15", "output": "6 9" }, { "input": "23", "output": "8 15" }, { "input": "1000000", "output": "500000 500000" }, { "input": "63874", "output": "4 63870" }, { "input": "14568", "output": "4 14564" }, ...
1,693,935,618
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n=int(input()) print(2,n-2,end=" ")
Title: Design Tutorial: Learn from Math Time Limit: None seconds Memory Limit: None megabytes Problem Description: One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statemen...
```python n=int(input()) print(2,n-2,end=" ") ```
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,696,851,031
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
77
2,764,800
n, l = map(int, input().split()) lst = list(map(int, input().split())) l1 = [] lst = sorted(lst) for i in range(n-1): l1.append(lst[i+1] - lst[i]) if lst[0] != 0 and lst[-1] != l: print(max(max(l1)/2, lst[0], l - lst[-1])) elif lst[-1] != l: print(max(max(l1)/2, l - lst[-1])) elif lst[0] != 0: ...
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 n, l = map(int, input().split()) lst = list(map(int, input().split())) l1 = [] lst = sorted(lst) for i in range(n-1): l1.append(lst[i+1] - lst[i]) if lst[0] != 0 and lst[-1] != l: print(max(max(l1)/2, lst[0], l - lst[-1])) elif lst[-1] != l: print(max(max(l1)/2, l - lst[-1])) elif lst[...
-1
918
A
Eleven
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the ...
The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Print Eleven's new name on the first and only line of output.
[ "8\n", "15\n" ]
[ "OOOoOooO\n", "OOOoOooOooooOoo\n" ]
none
500
[ { "input": "8", "output": "OOOoOooO" }, { "input": "15", "output": "OOOoOooOooooOoo" }, { "input": "85", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo" }, { "input": "381", "output": "OOOoOooOooooOoooooooOooooooooooooOooo...
1,584,859,341
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
6
109
307,200
def fib(num): res = [0 for i in range(num)] res[0], res[1] = 0, 1 for i in range(2, num): res[i] = res[i-1] + res[i-2] return res n = int(input()) a = fib(n) ans ='' for i in range(n-1): if i+1 in a: ans += 'O' else: ans += 'o' if n in a: ...
Title: Eleven Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should o...
```python def fib(num): res = [0 for i in range(num)] res[0], res[1] = 0, 1 for i in range(2, num): res[i] = res[i-1] + res[i-2] return res n = int(input()) a = fib(n) ans ='' for i in range(n-1): if i+1 in a: ans += 'O' else: ans += 'o' if n...
-1
349
B
Color the Fence
PROGRAMMING
1,700
[ "data structures", "dp", "greedy", "implementation" ]
null
null
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d...
The first line contains a positive integer *v* (0<=≤<=*v*<=≤<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=≤<=*a**i*<=≤<=105).
Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1.
[ "5\n5 4 3 2 1 2 3 4 5\n", "2\n9 11 1 12 5 8 9 10 6\n", "0\n1 1 1 1 1 1 1 1 1\n" ]
[ "55555\n", "33\n", "-1\n" ]
none
1,000
[ { "input": "5\n5 4 3 2 1 2 3 4 5", "output": "55555" }, { "input": "2\n9 11 1 12 5 8 9 10 6", "output": "33" }, { "input": "0\n1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "50\n5 3 10 2 2 4 3 6 5", "output": "5555555555555555555555555" }, { "input": "22\n405 3...
1,619,001,063
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
8
216
4,505,600
# import sys # sys.stdout = open('output.txt', 'w') # sys.stdin = open('input.txt', 'r') def solve(): v = int(input()) a = [int(x) for x in input().split()] idx = len(a)-1 for i in reversed(range(1, 9)): if a[i] < a[idx]: idx = i if a[idx] > v: print(-1) else: ...
Title: Color the Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. ...
```python # import sys # sys.stdout = open('output.txt', 'w') # sys.stdin = open('input.txt', 'r') def solve(): v = int(input()) a = [int(x) for x in input().split()] idx = len(a)-1 for i in reversed(range(1, 9)): if a[i] < a[idx]: idx = i if a[idx] > v: print(-1) ...
0
981
A
Antipalindrome
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}...
The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only.
If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique.
[ "mew\n", "wuffuw\n", "qqqqqqqq\n" ]
[ "3\n", "5\n", "0\n" ]
"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$. The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$. All sub...
500
[ { "input": "mew", "output": "3" }, { "input": "wuffuw", "output": "5" }, { "input": "qqqqqqqq", "output": "0" }, { "input": "ijvji", "output": "4" }, { "input": "iiiiiii", "output": "0" }, { "input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow"...
1,571,925,187
2,147,483,647
Python 3
OK
TESTS
133
124
0
x=input() x1=x[::-1] if x!=x1: print(len(x)) else: x1=x1.replace(x1[0],"",1) x2=x1[::-1] if x2!=x1: print(len(x1)) else: print("0")
Title: Antipalindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" ar...
```python x=input() x1=x[::-1] if x!=x1: print(len(x)) else: x1=x1.replace(x1[0],"",1) x2=x1[::-1] if x2!=x1: print(len(x1)) else: print("0") ```
3
267
A
Subtractions
PROGRAMMING
900
[ "math", "number theory" ]
null
null
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some num...
The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109).
Print the sought number of operations for each pair on a single line.
[ "2\n4 17\n7 987654321\n" ]
[ "8\n141093479\n" ]
none
500
[ { "input": "2\n4 17\n7 987654321", "output": "8\n141093479" }, { "input": "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321", "output": "141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479...
1,643,901,662
2,147,483,647
Python 3
OK
TESTS
35
77
0
import math for i in range(int(input())): a,b = map(int,input().split()) ways = 0 while True: if a==0 or b==0: break ways += ((max(a,b))//(min(a,b))) if max(a,b)==a: a -= (b*(a//b)) else: b -= (a*(b//a)) print(ways) ...
Title: Subtractions Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one o...
```python import math for i in range(int(input())): a,b = map(int,input().split()) ways = 0 while True: if a==0 or b==0: break ways += ((max(a,b))//(min(a,b))) if max(a,b)==a: a -= (b*(a//b)) else: b -= (a*(b//a)) pr...
3
755
B
PolandBall and Game
PROGRAMMING
1,100
[ "binary search", "data structures", "games", "greedy", "sortings", "strings" ]
null
null
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i...
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively. Then *n* strings follow, one per line — words familiar to PolandBall. Then *m* strings follow, one per line — words familiar to EnemyBall. Note that one Ball cannot know a w...
In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
[ "5 1\npolandball\nis\na\ncool\ncharacter\nnope\n", "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n", "1 2\na\na\nb\n" ]
[ "YES", "YES", "NO" ]
In the first example PolandBall knows much more words and wins effortlessly. In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
1,000
[ { "input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope", "output": "YES" }, { "input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "output": "YES" }, { "input": "1 2\na\na\nb", "output": "NO" }, { "input": "2 2\na\nb\nb\nc", "output": "YES" }, { "input": "...
1,629,187,796
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
n, m = map(int, input().split()) k = 0 l = [] for i in range(n): s = input() l.append(s) for j in range(m): s = input() if s in l: k++ n -= k m -= k k %= 2 n += k if (n > m): print("YES") else: print("NO")
Title: PolandBall and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You...
```python n, m = map(int, input().split()) k = 0 l = [] for i in range(n): s = input() l.append(s) for j in range(m): s = input() if s in l: k++ n -= k m -= k k %= 2 n += k if (n > m): print("YES") else: print("NO") ```
-1
600
B
Queries about less or equal elements
PROGRAMMING
1,300
[ "binary search", "data structures", "sortings", "two pointers" ]
null
null
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109). The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109).
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
[ "5 4\n1 3 5 7 9\n6 4 2 8\n", "5 5\n1 2 1 2 5\n3 1 4 1 5\n" ]
[ "3 2 1 4\n", "4 2 4 2 5\n" ]
none
0
[ { "input": "5 4\n1 3 5 7 9\n6 4 2 8", "output": "3 2 1 4" }, { "input": "5 5\n1 2 1 2 5\n3 1 4 1 5", "output": "4 2 4 2 5" }, { "input": "1 1\n-1\n-2", "output": "0" }, { "input": "1 1\n-80890826\n686519510", "output": "1" }, { "input": "11 11\n237468511 -77918754...
1,664,144,554
2,147,483,647
PyPy 3-64
OK
TESTS
60
311
34,406,400
def upper_bound(lista, x): l = 0 r = len(lista) - 1 m = 0 while l <= r: m = (l + r) // 2 if lista[m] > x: r = m - 1 else: l = m + 1 return l n, m = map(int, input().split(' ')) a = list(map(int, input().split(' '))) b = list(map(int, i...
Title: Queries about less or equal elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. In...
```python def upper_bound(lista, x): l = 0 r = len(lista) - 1 m = 0 while l <= r: m = (l + r) // 2 if lista[m] > x: r = m - 1 else: l = m + 1 return l n, m = map(int, input().split(' ')) a = list(map(int, input().split(' '))) b = list(...
3
443
A
Anton and Letters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to ti...
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Print a single number — the number of distinct letters in Anton's set.
[ "{a, b, c}\n", "{b, a, b, a}\n", "{}\n" ]
[ "3\n", "2\n", "0\n" ]
none
500
[ { "input": "{a, b, c}", "output": "3" }, { "input": "{b, a, b, a}", "output": "2" }, { "input": "{}", "output": "0" }, { "input": "{a, a, c, b, b, b, c, c, c, c}", "output": "3" }, { "input": "{a, c, b, b}", "output": "3" }, { "input": "{a, b}", "o...
1,688,144,001
2,147,483,647
Python 3
OK
TESTS
27
46
0
n=input() l=[] for i in n: if i!='{' and i!='}' and i!=',' and i!=" ": l.append(i) print(len(set(l)))
Title: Anton and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi...
```python n=input() l=[] for i in n: if i!='{' and i!='}' and i!=',' and i!=" ": l.append(i) print(len(set(l))) ```
3
965
A
Paper Airplanes
PROGRAMMING
800
[ "math" ]
null
null
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people....
The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Print a single integer — the minimum number of packs they should buy.
[ "5 3 2 3\n", "5 3 100 1\n" ]
[ "4\n", "5\n" ]
In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs. In the second sample they have to buy a pack for each person as they can't share sheets.
500
[ { "input": "5 3 2 3", "output": "4" }, { "input": "5 3 100 1", "output": "5" }, { "input": "10000 10000 1 1", "output": "100000000" }, { "input": "1 1 10000 10000", "output": "1" }, { "input": "300 300 21 23", "output": "196" }, { "input": "300 2 37 51...
1,689,830,214
2,147,483,647
Python 3
OK
TESTS
18
46
0
k, n, s, p = map(int,input().split()) if n%s==0: papersperperson = (n//s) else: papersperperson = (n//s)+1 paperneeded = k*papersperperson add = 0 if paperneeded%p !=0 : add = 1 print((paperneeded//p)+add)
Title: Paper Airplanes Time Limit: None seconds Memory Limit: None megabytes Problem Description: To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several p...
```python k, n, s, p = map(int,input().split()) if n%s==0: papersperperson = (n//s) else: papersperperson = (n//s)+1 paperneeded = k*papersperperson add = 0 if paperneeded%p !=0 : add = 1 print((paperneeded//p)+add) ```
3
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,656,324,207
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
1
1,000
4,710,400
def gcd(a, b): if(b == 0): return abs(a) else: return gcd(b, a % b) def fact(n:int): pro = 1 if n==0: return 1 else: for i in range(1,n+1): pro*=i return pro def main(a,b): return gcd(fact(a),fact(b)) a,b = map(int, input().split(...
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 def gcd(a, b): if(b == 0): return abs(a) else: return gcd(b, a % b) def fact(n:int): pro = 1 if n==0: return 1 else: for i in range(1,n+1): pro*=i return pro def main(a,b): return gcd(fact(a),fact(b)) a,b = map(int, inpu...
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,525,185,112
1,612
Python 3
OK
TESTS
30
467
10,137,600
n = int(input()) a = list(input().split()) o = [([0] * 26)for u in range(n)] for i in range(n): for u in range(len(a[i])): o[i][ord(a[i][u])-97] = 1 o.sort() kol = n for t in range(1,n): if o[n-t] == o[n-t-1]: kol -= 1 print(kol)
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 n = int(input()) a = list(input().split()) o = [([0] * 26)for u in range(n)] for i in range(n): for u in range(len(a[i])): o[i][ord(a[i][u])-97] = 1 o.sort() kol = n for t in range(1,n): if o[n-t] == o[n-t-1]: kol -= 1 print(kol) ```
3
433
B
Kuriyama Mirai's Stones
PROGRAMMING
1,200
[ "dp", "implementation", "sortings" ]
null
null
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones. The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t...
Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.
[ "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n", "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n" ]
[ "24\n9\n28\n", "10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n" ]
Please note that the answers to the questions may overflow 32-bit integer type.
1,500
[ { "input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6", "output": "24\n9\n28" }, { "input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2", "output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5" }, { "input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1...
1,663,786,022
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
2,000
2,457,600
n = int(input()) l1 = list(map(int, input().split())) l2 = sorted(l1) for i in range(int(input())): a,b,c = map(int,input().split()) s = 0 if(a==1): for i in l1[b-1:c]: s += i else: for i in l2[b-1:c]: s += i print(s)
Title: Kuriyama Mirai's Stones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s...
```python n = int(input()) l1 = list(map(int, input().split())) l2 = sorted(l1) for i in range(int(input())): a,b,c = map(int,input().split()) s = 0 if(a==1): for i in l1[b-1:c]: s += i else: for i in l2[b-1:c]: s += i print(s) ```
0
379
C
New Year Ratings Change
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors. There are *n* users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user *i* wants to get at least *a**...
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of users on the site. The next line contains integer sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print a sequence of integers *b*1,<=*b*2,<=...,<=*b**n*. Number *b**i* means that user *i* gets *b**i* of rating as a present. The printed sequence must meet the problem conditions. If there are multiple optimal solutions, print any of them.
[ "3\n5 1 1\n", "1\n1000000000\n" ]
[ "5 1 2\n", "1000000000\n" ]
none
1,500
[ { "input": "3\n5 1 1", "output": "5 1 2" }, { "input": "1\n1000000000", "output": "1000000000" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "1 2 3 4 5 6 7 8 9 10" }, { "input": "10\n1 10 1 10 1 1 7 8 6 7", "output": "1 10 2 11 3 4 7 9 6 8" }, { "input": "10\...
1,689,254,685
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689254685.2263858")# 1689254685.2264059
Title: New Year Ratings Change Time Limit: None seconds Memory Limit: None megabytes Problem Description: One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors. There are *n* users on the site, for each user we ...
```python print("_RANDOM_GUESS_1689254685.2263858")# 1689254685.2264059 ```
0
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ...
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Print a single line containing a positive integer *m* — the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" ...
1,615,205,700
2,147,483,647
PyPy 3
OK
TESTS
10
93
0
n = int(input()) table = [1 for i in range(n)] for _ in range(n - 1): buffer = table table[0] = 1 for j in range(1, n): table[j] = buffer[j] + table[j - 1] print(max(table))
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t...
```python n = int(input()) table = [1 for i in range(n)] for _ in range(n - 1): buffer = table table[0] = 1 for j in range(1, n): table[j] = buffer[j] + table[j - 1] print(max(table)) ```
3
550
A
Two Substrings
PROGRAMMING
1,500
[ "brute force", "dp", "greedy", "implementation", "strings" ]
null
null
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters.
Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
[ "ABA\n", "BACFAB\n", "AXBYBXA\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
1,000
[ { "input": "ABA", "output": "NO" }, { "input": "BACFAB", "output": "YES" }, { "input": "AXBYBXA", "output": "NO" }, { "input": "ABABAB", "output": "YES" }, { "input": "BBBBBBBBBB", "output": "NO" }, { "input": "ABBA", "output": "YES" }, { "...
1,696,916,694
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
def check(s): index=0 n=len(s) if(n<=3):return False for i in range(n-1): if(s[i]=='A' and s[i+1]=='B'): index=i+1 break if(index==n-1):return False for i in range(index+1,n-1): if(s[i]=='B' and s[i+1]=='A'): return True return ...
Title: Two Substrings Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). Input Specification: The only line of input contain...
```python def check(s): index=0 n=len(s) if(n<=3):return False for i in range(n-1): if(s[i]=='A' and s[i+1]=='B'): index=i+1 break if(index==n-1):return False for i in range(index+1,n-1): if(s[i]=='B' and s[i+1]=='A'): return True ...
0
330
A
Cakeminator
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains...
The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: ...
Output the maximum number of cake cells that the cakeminator can eat.
[ "3 4\nS...\n....\n..S.\n" ]
[ "8\n" ]
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
500
[ { "input": "3 4\nS...\n....\n..S.", "output": "8" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "2 2\nSS\nSS", "output": "0" }, { "input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "output": "14" }, { "input": "3 5\n..S..\nSSSSS\n..S..", "output": "...
1,656,354,530
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
2
216
20,377,600
import sys import os from collections import Counter, defaultdict, deque from heapq import heapify, heappush, heappop from functools import lru_cache from math import floor, ceil, sqrt, gcd from string import ascii_lowercase from bisect import bisect_left, bisect, bisect_right def __perform_setup__(): ...
Title: Cakeminator Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each ti...
```python import sys import os from collections import Counter, defaultdict, deque from heapq import heapify, heappush, heappop from functools import lru_cache from math import floor, ceil, sqrt, gcd from string import ascii_lowercase from bisect import bisect_left, bisect, bisect_right def __perform_setup_...
-1
652
B
z-sort
PROGRAMMING
1,000
[ "sortings" ]
null
null
A student of *z*-school found a kind of sorting called *z*-sort. The array *a* with *n* elements are *z*-sorted if two conditions hold: 1. *a**i*<=≥<=*a**i*<=-<=1 for all even *i*, 1. *a**i*<=≤<=*a**i*<=-<=1 for all odd *i*<=&gt;<=1. For example the arrays [1,2,1,2] and [1,1,1,1] are *z*-sorted while the array [1,2...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array *a*. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*.
If it's possible to make the array *a* *z*-sorted print *n* space separated integers *a**i* — the elements after *z*-sort. Otherwise print the only word "Impossible".
[ "4\n1 2 2 1\n", "5\n1 3 2 2 5\n" ]
[ "1 2 1 2\n", "1 5 2 3 2\n" ]
none
0
[ { "input": "4\n1 2 2 1", "output": "1 2 1 2" }, { "input": "5\n1 3 2 2 5", "output": "1 5 2 3 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "1 1 1 1 1 1 1 1 1 1" }, { "input": "10\n1 9 7 6 2 4 7 8 1 3", "output": "1 ...
1,520,030,292
2,147,483,647
Python 3
OK
TESTS
16
62
5,734,400
n = int(input()) li = list(map(int, input().split())) li.sort() for i in range(len(li) - 1): if(i%2==1): tp = li[i] li[i] = li[i+1] li[i+1] = tp for i in range(len(li)): print(li[i], end=" ")
Title: z-sort Time Limit: None seconds Memory Limit: None megabytes Problem Description: A student of *z*-school found a kind of sorting called *z*-sort. The array *a* with *n* elements are *z*-sorted if two conditions hold: 1. *a**i*<=≥<=*a**i*<=-<=1 for all even *i*, 1. *a**i*<=≤<=*a**i*<=-<=1 for all odd *i*<=...
```python n = int(input()) li = list(map(int, input().split())) li.sort() for i in range(len(li) - 1): if(i%2==1): tp = li[i] li[i] = li[i+1] li[i+1] = tp for i in range(len(li)): print(li[i], end=" ") ```
3
401
A
Vanya and Cards
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value. Natasha doesn't like when Vanya spends a long time p...
The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their a...
Print a single number — the answer to the problem.
[ "3 2\n-1 1 2\n", "2 3\n-2 -2\n" ]
[ "1\n", "2\n" ]
In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
500
[ { "input": "3 2\n-1 1 2", "output": "1" }, { "input": "2 3\n-2 -2", "output": "2" }, { "input": "4 4\n1 2 3 4", "output": "3" }, { "input": "2 2\n-1 -1", "output": "1" }, { "input": "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2", "output": "4" }, { "...
1,597,734,693
2,147,483,647
PyPy 3
OK
TESTS
47
140
0
import math n,x = map(int, input().split(' ')) li = list(map(int, input().split(' '))) y = 0-(sum(li)) if y == 0: print(0) elif abs(y) > x: print(math.ceil(abs(y)/x)) else: print(1)
Title: Vanya and Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each...
```python import math n,x = map(int, input().split(' ')) li = list(map(int, input().split(' '))) y = 0-(sum(li)) if y == 0: print(0) elif abs(y) > x: print(math.ceil(abs(y)/x)) else: print(1) ```
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,613,404,574
2,147,483,647
Python 3
OK
TESTS
80
311
614,400
n = int(input()) pokemons = input() last = {} start_of_all = 0 for i in range(n): ty = pokemons[i] if ty not in last: start_of_all = i last[ty] = 0 minlen = 100001 for i in range(n): ty = pokemons[i] last[ty] = i length = i + 1 - min(last.values()) if i >= start_of_all and length ...
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 n = int(input()) pokemons = input() last = {} start_of_all = 0 for i in range(n): ty = pokemons[i] if ty not in last: start_of_all = i last[ty] = 0 minlen = 100001 for i in range(n): ty = pokemons[i] last[ty] = i length = i + 1 - min(last.values()) if i >= start_of_all a...
3
330
A
Cakeminator
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains...
The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: ...
Output the maximum number of cake cells that the cakeminator can eat.
[ "3 4\nS...\n....\n..S.\n" ]
[ "8\n" ]
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
500
[ { "input": "3 4\nS...\n....\n..S.", "output": "8" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "2 2\nSS\nSS", "output": "0" }, { "input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "output": "14" }, { "input": "3 5\n..S..\nSSSSS\n..S..", "output": "...
1,589,184,622
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
156
6,963,200
n, m = map(int, input().split()) a = [] for i in range(n): b = list(input()) a.append(b) s = 0 z = 0 for i in range(n): if "S" not in a[i]: z = +1 s += len(a[i]) for i in range(m): d = [] for j in range(n): d.append(a[j][i]) if "S" not in d: s ...
Title: Cakeminator Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each ti...
```python n, m = map(int, input().split()) a = [] for i in range(n): b = list(input()) a.append(b) s = 0 z = 0 for i in range(n): if "S" not in a[i]: z = +1 s += len(a[i]) for i in range(m): d = [] for j in range(n): d.append(a[j][i]) if "S" not in d: ...
0
34
A
Reconnaissance 2
PROGRAMMING
800
[ "implementation" ]
A. Reconnaissance 2
2
256
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ...
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
[ "5\n10 12 13 15 10\n", "4\n10 20 30 40\n" ]
[ "5 1\n", "1 2\n" ]
none
500
[ { "input": "5\n10 12 13 15 10", "output": "5 1" }, { "input": "4\n10 20 30 40", "output": "1 2" }, { "input": "6\n744 359 230 586 944 442", "output": "2 3" }, { "input": "5\n826 747 849 687 437", "output": "1 2" }, { "input": "5\n999 999 993 969 999", "output"...
1,654,948,817
2,147,483,647
Python 3
OK
TESTS
20
92
0
n=int(input()) lst=[int(x) for x in input().split()] best=abs(lst[-1]-lst[0]) if best: ans1,ans2=1,n for i in range(n-1): if best>abs(lst[i+1]-lst[i]): best=abs(lst[i+1]-lst[i]) ans1,ans2=i+1,i+2 if best==0: print(ans1,ans2) break e...
Title: Reconnaissance 2 Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So...
```python n=int(input()) lst=[int(x) for x in input().split()] best=abs(lst[-1]-lst[0]) if best: ans1,ans2=1,n for i in range(n-1): if best>abs(lst[i+1]-lst[i]): best=abs(lst[i+1]-lst[i]) ans1,ans2=i+1,i+2 if best==0: print(ans1,ans2) br...
3.977