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
830
A
Office Keys
PROGRAMMING
1,800
[ "binary search", "brute force", "dp", "greedy", "sortings" ]
null
null
There are *n* people and *k* keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else. You are to determine the minimum time needed for all *n* people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
The first line contains three integers *n*, *k* and *p* (1<=≤<=*n*<=≤<=1<=000, *n*<=≤<=*k*<=≤<=2<=000, 1<=≤<=*p*<=≤<=109) — the number of people, the number of keys and the office location. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — positions in which people are located initially. The positions are given in arbitrary order. The third line contains *k* distinct integers *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b**j*<=≤<=109) — positions of the keys. The positions are given in arbitrary order. Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
Print the minimum time (in seconds) needed for all *n* to reach the office with keys.
[ "2 4 50\n20 100\n60 10 40 80\n", "1 2 10\n11\n15 7\n" ]
[ "50\n", "7\n" ]
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys.
500
[ { "input": "2 4 50\n20 100\n60 10 40 80", "output": "50" }, { "input": "1 2 10\n11\n15 7", "output": "7" }, { "input": "2 5 15\n10 4\n29 23 21 22 26", "output": "23" }, { "input": "3 10 1500\n106 160 129\n1333 1532 1181 1091 1656 1698 1291 1741 1242 1163", "output": "1394...
1,597,944,807
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
9
202
2,355,200
def check(x): j=0 for i in range(n): if j>k: return False while abs(b[j]-a[i])+abs(b[j]-p)>x: j+=1 if j>=k: return False j+=1 return True n,k,p=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a.sort() b.sort() l=0 r=10**18 ans=-1 while l<=r: mid=l+(r-l)//2 if check(mid): r=mid-1 ans=mid else: l=mid+1 print(ans)
Title: Office Keys Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* people and *k* keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else. You are to determine the minimum time needed for all *n* people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it. Input Specification: The first line contains three integers *n*, *k* and *p* (1<=≤<=*n*<=≤<=1<=000, *n*<=≤<=*k*<=≤<=2<=000, 1<=≤<=*p*<=≤<=109) — the number of people, the number of keys and the office location. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — positions in which people are located initially. The positions are given in arbitrary order. The third line contains *k* distinct integers *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b**j*<=≤<=109) — positions of the keys. The positions are given in arbitrary order. Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point. Output Specification: Print the minimum time (in seconds) needed for all *n* to reach the office with keys. Demo Input: ['2 4 50\n20 100\n60 10 40 80\n', '1 2 10\n11\n15 7\n'] Demo Output: ['50\n', '7\n'] Note: In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys.
```python def check(x): j=0 for i in range(n): if j>k: return False while abs(b[j]-a[i])+abs(b[j]-p)>x: j+=1 if j>=k: return False j+=1 return True n,k,p=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a.sort() b.sort() l=0 r=10**18 ans=-1 while l<=r: mid=l+(r-l)//2 if check(mid): r=mid-1 ans=mid else: l=mid+1 print(ans) ```
-1
258
A
Little Elephant and Bits
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation.
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
[ "101\n", "110010\n" ]
[ "11\n", "11010\n" ]
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
500
[ { "input": "101", "output": "11" }, { "input": "110010", "output": "11010" }, { "input": "10000", "output": "1000" }, { "input": "1111111110", "output": "111111111" }, { "input": "10100101011110101", "output": "1100101011110101" }, { "input": "11101001...
1,484,517,765
2,147,483,647
Python 3
OK
TESTS
37
186
9,830,400
l = list(map(int, input())) try: l.remove(0) print("".join(map(str, l))) except: l.remove(1) print("".join(map(str, l)))
Title: Little Elephant and Bits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input Specification: The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output Specification: In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Demo Input: ['101\n', '110010\n'] Demo Output: ['11\n', '11010\n'] Note: In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
```python l = list(map(int, input())) try: l.remove(0) print("".join(map(str, l))) except: l.remove(1) print("".join(map(str, l))) ```
3
988
B
Substrings Sort
PROGRAMMING
1,100
[ "sortings", "strings" ]
null
null
You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in such a way that they form $a$. For example, string "for" is contained as a substring in strings "codeforces", "for" and "therefore", but is not contained as a substring in strings "four", "fofo" and "rof".
The first line contains an integer $n$ ($1 \le n \le 100$) — the number of strings. The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters. Some strings might be equal.
If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes). Otherwise print "YES" (without quotes) and $n$ given strings in required order.
[ "5\na\naba\nabacaba\nba\naba\n", "5\na\nabacaba\nba\naba\nabab\n", "3\nqwerty\nqwerty\nqwerty\n" ]
[ "YES\na\nba\naba\naba\nabacaba\n", "NO\n", "YES\nqwerty\nqwerty\nqwerty\n" ]
In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba".
0
[ { "input": "5\na\naba\nabacaba\nba\naba", "output": "YES\na\nba\naba\naba\nabacaba" }, { "input": "5\na\nabacaba\nba\naba\nabab", "output": "NO" }, { "input": "3\nqwerty\nqwerty\nqwerty", "output": "YES\nqwerty\nqwerty\nqwerty" }, { "input": "1\nwronganswer", "output": "Y...
1,620,306,285
2,147,483,647
PyPy 3
OK
TESTS
56
124
20,582,400
# from collections import defaultdict, Counter # from bisect import bisect, bisect_left # from math import sqrt, gcd # def read(): return list(map(int, input().strip().split())) # ans_ = [] # def f(s): # last = -1 # dp = [0]*len(s) # count = 0 # for i in range(len(s)): # x = [0, 1][s[i] == "*"] # dp[i] += dp[last] # dp[i] += count*(i-last-x) # count += x # last = [last, i][x] # return(dp) # for _ in range(int(input())): # n = int(input()); s = input().strip() # a = f(s) # b = f(s[::-1])[::-1] # ca = s.count("*") # ans = float("inf") # c = 0 # for i in range(n): # if s[i] == "*": # c += 1 # ans = min(ans, (a[i]+b[i])) # else: # ans = min(ans, (a[i]+b[i]-max(c, ca-c))) # # print(a, "\n", b) # if c != 0: # ans_.append(ans) # else: # ans_.append(0) # # print(ans_) # for i in ans_: # print(i) # """ # 1 # 1 # 2 1 2 3 4 # 3 1 2 3 4 5 6 7 8 9 # 1 3 5 # 4 6 # """ from collections import defaultdict, Counter from bisect import bisect, bisect_left from math import sqrt, gcd def read(): return list(map(int, input().strip().split())) ans_ = [] def f(lis, n): for i in range(1, n): if not lis[i-1] in lis[i]:return(False) return(True) # for _ in range(int(input())): n = int(input()); arr = [input().strip() for i in range(n)] arr.sort(key = len) # print(arr) if f(arr, n): ans_.append("YES") ans_.append(("\n").join(arr)) else: ans_.append("NO") # print(ans_) for i in ans_: print(i) """ 9 + 9 + """
Title: Substrings Sort Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in such a way that they form $a$. For example, string "for" is contained as a substring in strings "codeforces", "for" and "therefore", but is not contained as a substring in strings "four", "fofo" and "rof". Input Specification: The first line contains an integer $n$ ($1 \le n \le 100$) — the number of strings. The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters. Some strings might be equal. Output Specification: If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes). Otherwise print "YES" (without quotes) and $n$ given strings in required order. Demo Input: ['5\na\naba\nabacaba\nba\naba\n', '5\na\nabacaba\nba\naba\nabab\n', '3\nqwerty\nqwerty\nqwerty\n'] Demo Output: ['YES\na\nba\naba\naba\nabacaba\n', 'NO\n', 'YES\nqwerty\nqwerty\nqwerty\n'] Note: In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba".
```python # from collections import defaultdict, Counter # from bisect import bisect, bisect_left # from math import sqrt, gcd # def read(): return list(map(int, input().strip().split())) # ans_ = [] # def f(s): # last = -1 # dp = [0]*len(s) # count = 0 # for i in range(len(s)): # x = [0, 1][s[i] == "*"] # dp[i] += dp[last] # dp[i] += count*(i-last-x) # count += x # last = [last, i][x] # return(dp) # for _ in range(int(input())): # n = int(input()); s = input().strip() # a = f(s) # b = f(s[::-1])[::-1] # ca = s.count("*") # ans = float("inf") # c = 0 # for i in range(n): # if s[i] == "*": # c += 1 # ans = min(ans, (a[i]+b[i])) # else: # ans = min(ans, (a[i]+b[i]-max(c, ca-c))) # # print(a, "\n", b) # if c != 0: # ans_.append(ans) # else: # ans_.append(0) # # print(ans_) # for i in ans_: # print(i) # """ # 1 # 1 # 2 1 2 3 4 # 3 1 2 3 4 5 6 7 8 9 # 1 3 5 # 4 6 # """ from collections import defaultdict, Counter from bisect import bisect, bisect_left from math import sqrt, gcd def read(): return list(map(int, input().strip().split())) ans_ = [] def f(lis, n): for i in range(1, n): if not lis[i-1] in lis[i]:return(False) return(True) # for _ in range(int(input())): n = int(input()); arr = [input().strip() for i in range(n)] arr.sort(key = len) # print(arr) if f(arr, n): ans_.append("YES") ans_.append(("\n").join(arr)) else: ans_.append("NO") # print(ans_) for i in ans_: print(i) """ 9 + 9 + """ ```
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 at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times. Please output the maximum number of cake cells that the cakeminator can eat.
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: - '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry.
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,605,368,285
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
216
0
x= input().split() li = [] for i in range(int(x[0])): li.append(input().split()) res = (int(x[0])*int(x[1]))-int(x[1]) print(res)
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 time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times. Please output the maximum number of cake cells that the cakeminator can eat. Input Specification: 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: - '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry. Output Specification: Output the maximum number of cake cells that the cakeminator can eat. Demo Input: ['3 4\nS...\n....\n..S.\n'] Demo Output: ['8\n'] Note: For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
```python x= input().split() li = [] for i in range(int(x[0])): li.append(input().split()) res = (int(x[0])*int(x[1]))-int(x[1]) print(res) ```
0
460
A
Vasya and Socks
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Print a single integer — the answer to the problem.
[ "2 2\n", "9 3\n" ]
[ "3\n", "13\n" ]
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
500
[ { "input": "2 2", "output": "3" }, { "input": "9 3", "output": "13" }, { "input": "1 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "1 99", "output": "1" }, { "input": "4 4", "output": "5" }, { "input": "10 2", "outp...
1,666,110,657
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
31
0
n,m=map(int,input().split()) k=n//m l=k//m print(l+k+n)
Title: Vasya and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks? Input Specification: The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['2 2\n', '9 3\n'] Demo Output: ['3\n', '13\n'] Note: In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
```python n,m=map(int,input().split()) k=n//m l=k//m print(l+k+n) ```
0
858
C
Did you mean...
PROGRAMMING
1,500
[ "dp", "greedy", "implementation" ]
null
null
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them. Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block. For example: - the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo". When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos. Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Print the given word without any changes if there are no typos. If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
[ "hellno\n", "abacaba\n", "asdfasdf\n" ]
[ "hell no \n", "abacaba \n", "asd fasd f \n" ]
none
1,500
[ { "input": "hellno", "output": "hell no " }, { "input": "abacaba", "output": "abacaba " }, { "input": "asdfasdf", "output": "asd fasd f " }, { "input": "ooo", "output": "ooo " }, { "input": "moyaoborona", "output": "moyaoborona " }, { "input": "jxegxxx...
1,505,660,497
6,997
Python 3
TIME_LIMIT_EXCEEDED
TESTS
44
1,000
5,836,800
s = input() count = 0 last = ' ' b = set('aeio u') flag = 1 while flag: flag = 0 for i in range(len(s)): if not(s[i] in b): count+=1 last+=s[i] else: count = 0 last = ' ' if (count>=3) and ((last[-1]!=last[-2]) or (last[-1]!=last[-3])): s = s[:i] + ' ' + s[i:] count = 0 last = ' ' flag = 1 break print (s)
Title: Did you mean... Time Limit: None seconds Memory Limit: None megabytes Problem Description: Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them. Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block. For example: - the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo". When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos. Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem. Input Specification: The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. Output Specification: Print the given word without any changes if there are no typos. If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. Demo Input: ['hellno\n', 'abacaba\n', 'asdfasdf\n'] Demo Output: ['hell no \n', 'abacaba \n', 'asd fasd f \n'] Note: none
```python s = input() count = 0 last = ' ' b = set('aeio u') flag = 1 while flag: flag = 0 for i in range(len(s)): if not(s[i] in b): count+=1 last+=s[i] else: count = 0 last = ' ' if (count>=3) and ((last[-1]!=last[-2]) or (last[-1]!=last[-3])): s = s[:i] + ' ' + s[i:] count = 0 last = ' ' flag = 1 break print (s) ```
0
921
05
Labyrinth-5
PROGRAMMING
3,200
[]
null
null
See the problem statement here: [http://codeforces.com/contest/921/problem/01](//codeforces.com/contest/921/problem/01).
none
none
[]
[]
none
0
[]
1,517,510,939
10,139
Python 3
PARTIAL
TESTS
0
124
21,913,600
import base64 import zlib print(zlib.decompress(base64.b64decode('eNrs3bkJgEAURdHcKmzAyJYcF1BHxKV9EVEDQTAxOtnwOUwHj9vFJWRFXPuk219jU9XT8ZyHx4njOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jPrv72Iby5Xb+R1EURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVHUr6qMY5anl01DX5hPcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcbJWFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFCVrJWvFcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHyVpRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRlKyVrBXHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRwna0VRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRslayVhzHcRzHcRzHcRzHcRzHcRzH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dxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHCdrZexHURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFUbJWHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxnKyVsR9FURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFyVpxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxslbGfhRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURQla8VxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMfJWhn7URRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFUZSsFcdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHCdrZexHURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFUbJWHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxnKyVrBVFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFyVpxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxnKwVRVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURclacRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcZysFUVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEXJWnEcx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3GcrBVFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFyVpxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxnKwVRVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURclacRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRz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URVEURVEURVEURVEURVEURVEURVEURVGyVhzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcZyslUkgRVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURclacRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcbJWJoEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEUJWvFcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHyVqZBFIURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVGUrBXHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRwna2USSFEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVGyVhzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcZyslUkgRVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURclacRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcbJWJoEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEUJWvFcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHyVoZ+1EURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVGUrBXHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRwna2XsR1EURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVGyVhzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcZyslbEfRVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURclacRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcbJWxn4URVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEUJWvFcRzHcRzHcRzHcRzHcR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4zhbK4qiKIqiKIqiKIqiKIqiKIqiKIqiKIqiKIqiKIqiKIqiKIqiKIqytZJPcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcbZWFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFGVrJZ/iOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jbK0oiqIoiqIoiqIoiqIoiqIoiqIoiqIoiqIoiqIoiqIoiqIoiqIoytZKPsVxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMfZWlEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVGUrZWtFcdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHGdrRVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVG2VrZWHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdx3OsCneUmSA==')))
Title: Labyrinth-5 Time Limit: None seconds Memory Limit: None megabytes Problem Description: See the problem statement here: [http://codeforces.com/contest/921/problem/01](//codeforces.com/contest/921/problem/01). Input Specification: none Output Specification: none Note: none
```python import base64 import zlib print(zlib.decompress(base64.b64decode('eNrs3bkJgEAURdHcKmzAyJYcF1BHxKV9EVEDQTAxOtnwOUwHj9vFJWRFXPuk219jU9XT8ZyHx4njOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jPrv72Iby5Xb+R1EURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVHUr6qMY5anl01DX5hPcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcbJWFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFCVrJWvFcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzH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xHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxslbGfhRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURQla8VxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMfJWhn7URRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFUZSsFcdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHCdrZexHURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFUbJWHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxnKyVsR9FURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFyVpxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxslbGfhRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURQla8VxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMfJWhn7URRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFUZSsFcdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHCdrZexHURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFUbJWHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxnKyVrBVFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFyVpxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxnKwVRVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURclacRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcZysFUVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEXJWnEcx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3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EVRFEVRFEVRFEVRslYcx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3GcrBVFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFUbJWHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxnKwVRVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVGyVhzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcZyslUkgRVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURclacRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcbJWJoEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEUJWvFcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHyVqZBFIURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVGUrBXHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRwna2USSFEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVGyVhzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcZyslUkgRVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURclacRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcbJWJoEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEUJWvFcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHyVoZ+1EURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVGUrBXHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRwna2XsR1EURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVGyVhzHcRzHcRzHcRzHcR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iiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKomyt5FMcx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3Ecx3GcrRVFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRFURRF2VrJpziO4ziO4ziO4ziO4ziO4ziO4ziO4ziO4ziO4ziO4ziO4ziO4ziO4zhbK4qiKIqiKIqiKIqiKIqiKIqiKIqiKIqiKIqiKIqiKIqiKIqiKIqytZJPcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcRzHcbZWFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFGVrJZ/iOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jOI7jbK0oiqIoiqIoiqIoiqIoiqIoiqIoiqIoiqIoiqIoiqIoiqIoiqIoytZKPsVxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMfZWlEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVGUrZWtFcdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHGdrRVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVEURVG2VrZWHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdxHMdx3OsCneUmSA=='))) ```
2
611
B
New Year and Old Property
PROGRAMMING
1,300
[ "bitmasks", "brute force", "implementation" ]
null
null
The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster? Assume that all positive integers are always written without leading zeros.
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively.
Print one integer – the number of years Limak will count in his chosen interval.
[ "5 10\n", "2015 2015\n", "100 105\n", "72057594000000000 72057595000000000\n" ]
[ "2\n", "1\n", "0\n", "26\n" ]
In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<sub class="lower-index">2</sub>, 9<sub class="lower-index">10</sub> = 1001<sub class="lower-index">2</sub> and 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>. Two of them (101<sub class="lower-index">2</sub> and 110<sub class="lower-index">2</sub>) have the described property.
750
[ { "input": "5 10", "output": "2" }, { "input": "2015 2015", "output": "1" }, { "input": "100 105", "output": "0" }, { "input": "72057594000000000 72057595000000000", "output": "26" }, { "input": "1 100", "output": "16" }, { "input": "100000000000000000...
1,607,599,320
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
155
2,048,000
a,b = map(int,input().split()) cnt = 0 for i in range(2,65): for j in range(i-1): cur = 0 for k in range(i): cur = cur * 2 + (k != j) if cur >= a and cur <= b: cnt += 1 print(cnt)
Title: New Year and Old Property Time Limit: None seconds Memory Limit: None megabytes Problem Description: The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster? Assume that all positive integers are always written without leading zeros. Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively. Output Specification: Print one integer – the number of years Limak will count in his chosen interval. Demo Input: ['5 10\n', '2015 2015\n', '100 105\n', '72057594000000000 72057595000000000\n'] Demo Output: ['2\n', '1\n', '0\n', '26\n'] Note: In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<sub class="lower-index">2</sub>, 9<sub class="lower-index">10</sub> = 1001<sub class="lower-index">2</sub> and 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>. Two of them (101<sub class="lower-index">2</sub> and 110<sub class="lower-index">2</sub>) have the described property.
```python a,b = map(int,input().split()) cnt = 0 for i in range(2,65): for j in range(i-1): cur = 0 for k in range(i): cur = cur * 2 + (k != j) if cur >= a and cur <= b: cnt += 1 print(cnt) ```
0
797
A
k-Factorization
PROGRAMMING
1,100
[ "implementation", "math", "number theory" ]
null
null
Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*.
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20).
If it's impossible to find the representation of *n* as a product of *k* numbers, print -1. Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them.
[ "100000 2\n", "100000 20\n", "1024 5\n" ]
[ "2 50000 \n", "-1\n", "2 64 2 2 2 \n" ]
none
0
[ { "input": "100000 2", "output": "2 50000 " }, { "input": "100000 20", "output": "-1" }, { "input": "1024 5", "output": "2 64 2 2 2 " }, { "input": "100000 10", "output": "2 2 2 2 2 5 5 5 5 5 " }, { "input": "99999 3", "output": "3 813 41 " }, { "input...
1,647,175,533
2,147,483,647
Python 3
OK
TESTS
166
46
0
def f(n): l, d = [], 2 while d**2 <= n: if n%d == 0 : l.append(d); n//=d else : d += 1 if n!=1 : l.append(n) return l n, k = [int(i) for i in input().split()] Q = f(n) if len(Q) >= k : for i in range(k-1) : print(Q[i], end = ' ') r = Q[k-1:] w = 1 for i in range(len(r)) : w *= r[i] print(w) else : print(-1)
Title: k-Factorization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*. Input Specification: The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20). Output Specification: If it's impossible to find the representation of *n* as a product of *k* numbers, print -1. Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them. Demo Input: ['100000 2\n', '100000 20\n', '1024 5\n'] Demo Output: ['2 50000 \n', '-1\n', '2 64 2 2 2 \n'] Note: none
```python def f(n): l, d = [], 2 while d**2 <= n: if n%d == 0 : l.append(d); n//=d else : d += 1 if n!=1 : l.append(n) return l n, k = [int(i) for i in input().split()] Q = f(n) if len(Q) >= k : for i in range(k-1) : print(Q[i], end = ' ') r = Q[k-1:] w = 1 for i in range(len(r)) : w *= r[i] print(w) else : print(-1) ```
3
0
none
none
none
0
[ "none" ]
null
null
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one. Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given. Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly.
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower).
[ "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n" ]
[ "Yes\nYes\nYes\nNo\nNo\nYes\n" ]
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won. The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
0
[ { "input": "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000", "output": "Yes\nYes\nYes\nNo\nNo\nYes" }, { "input": "3\n1 1\n8 27\n1000 1331", "output": "Yes\nNo\nNo" }, { "input": "1\n12004 18012002", "output": "Yes" }, { "input": "1\n3331 11095561", "output": "Yes...
1,557,015,809
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
1
1,000
6,348,800
import sys from math import * from fractions import gcd readints=lambda:map(int, input().strip('\n').split()) def cuberoot(x): eps = 10**-6 lo=0 hi=x while abs(lo-hi)>10**-10: mid = (lo+hi)/2 p3=mid*mid*mid # print(mid,p3,abs(p3-x)) if abs(p3-x)<eps: return int(round(mid)) elif p3<x: lo=mid elif p3>x: hi=mid return -1 def solve(): a,b=readints() x = cuberoot(a*b) if x==-1: return False return a%x==0 and b%x==0 n=int(input()) for _ in range(n): if solve(): print('Yes') else: print('No')
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one. Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. Input Specification: In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given. Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly. Output Specification: For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). Demo Input: ['6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n'] Demo Output: ['Yes\nYes\nYes\nNo\nNo\nYes\n'] Note: First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won. The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
```python import sys from math import * from fractions import gcd readints=lambda:map(int, input().strip('\n').split()) def cuberoot(x): eps = 10**-6 lo=0 hi=x while abs(lo-hi)>10**-10: mid = (lo+hi)/2 p3=mid*mid*mid # print(mid,p3,abs(p3-x)) if abs(p3-x)<eps: return int(round(mid)) elif p3<x: lo=mid elif p3>x: hi=mid return -1 def solve(): a,b=readints() x = cuberoot(a*b) if x==-1: return False return a%x==0 and b%x==0 n=int(input()) for _ in range(n): if solve(): print('Yes') else: print('No') ```
0
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,659,021,930
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
154
0
n=input() s=input() st=n[::-1] if(st==s): print("Yes") else: print("No")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. Input Specification: The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. Output Specification: If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. Demo Input: ['code\nedoc\n', 'abb\naba\n', 'code\ncode\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python n=input() s=input() st=n[::-1] if(st==s): print("Yes") else: print("No") ```
0
999
C
Alphabetic Removals
PROGRAMMING
1,200
[ "implementation" ]
null
null
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: - if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - ... - remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly $k$ times, thus removing exactly $k$ characters. Help Polycarp find the resulting string.
The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove. The second line contains the string $s$ consisting of $n$ lowercase Latin letters.
Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break).
[ "15 3\ncccaabababaccbc\n", "15 9\ncccaabababaccbc\n", "1 1\nu\n" ]
[ "cccbbabaccbc\n", "cccccc\n", "" ]
none
0
[ { "input": "15 3\ncccaabababaccbc", "output": "cccbbabaccbc" }, { "input": "15 9\ncccaabababaccbc", "output": "cccccc" }, { "input": "5 2\nzyzyx", "output": "zzy" }, { "input": "4 3\nhack", "output": "k" }, { "input": "4 3\nzzzz", "output": "z" }, { "i...
1,653,649,269
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
13,312,000
albhabets = "abcdefghijklmnopqrstuvwxyz" d = {} for i in albhabets: d[i] = 0 n,k = map(int,input().split()) s = input() for i in s: d[i] += 1 for key in d: if k ==0: break if d[key] == 0 : pass elif d[key]<k : k-= d[key] d[key] = 0 else: d[key]= d[key]-k k = 0 break j = len(s)-1 ans = "" while j>=0 : if d[s[j]] == 0 : pass else: ans = s[j]+ans d[s[j]]-=1 j-=1 print(ans)
Title: Alphabetic Removals Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: - if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - ... - remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly $k$ times, thus removing exactly $k$ characters. Help Polycarp find the resulting string. Input Specification: The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove. The second line contains the string $s$ consisting of $n$ lowercase Latin letters. Output Specification: Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). Demo Input: ['15 3\ncccaabababaccbc\n', '15 9\ncccaabababaccbc\n', '1 1\nu\n'] Demo Output: ['cccbbabaccbc\n', 'cccccc\n', ''] Note: none
```python albhabets = "abcdefghijklmnopqrstuvwxyz" d = {} for i in albhabets: d[i] = 0 n,k = map(int,input().split()) s = input() for i in s: d[i] += 1 for key in d: if k ==0: break if d[key] == 0 : pass elif d[key]<k : k-= d[key] d[key] = 0 else: d[key]= d[key]-k k = 0 break j = len(s)-1 ans = "" while j>=0 : if d[s[j]] == 0 : pass else: ans = s[j]+ans d[s[j]]-=1 j-=1 print(ans) ```
0
845
C
Two TVs
PROGRAMMING
1,500
[ "data structures", "greedy", "sortings" ]
null
null
Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*. Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given moment on a single TV. If one show ends at the same moment some other show starts then you can't watch them on a single TV. Polycarp wants to check out all *n* shows. Are two TVs enough to do so?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of shows. Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=109) — starting and ending time of *i*-th show.
If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).
[ "3\n1 2\n2 3\n4 5\n", "4\n1 2\n2 3\n2 3\n1 2\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "3\n1 2\n2 3\n4 5", "output": "YES" }, { "input": "4\n1 2\n2 3\n2 3\n1 2", "output": "NO" }, { "input": "4\n0 1\n1 2\n2 3\n3 4", "output": "YES" }, { "input": "3\n1 2\n2 3\n2 4", "output": "NO" }, { "input": "3\n0 100\n0 100\n0 100", "output": "NO" ...
1,644,654,799
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
7
2,000
15,769,600
import sys n=int(input()) arr=[] for i in range(n): l,r=map(int,input().split()) arr.append((l,r)) arr.sort() arr1=[] arr2=[] t1=0 t2=0 for j in range(n): if j%2==0: arr1.append(arr[j]) t1+=1 else: arr2.append(arr[j]) t2+=1 arr1.append((sys.maxsize,sys.maxsize)) arr2.append((sys.maxsize,sys.maxsize)) for j in range(1,t1): if arr1[j-1][1]>=arr1[j][0]: print("NO") exit() for j in range(1,t2): if arr2[j-1][1]>=arr2[j][0]: print("NO") exit() print("YES")
Title: Two TVs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*. Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given moment on a single TV. If one show ends at the same moment some other show starts then you can't watch them on a single TV. Polycarp wants to check out all *n* shows. Are two TVs enough to do so? Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of shows. Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=109) — starting and ending time of *i*-th show. Output Specification: If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes). Demo Input: ['3\n1 2\n2 3\n4 5\n', '4\n1 2\n2 3\n2 3\n1 2\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python import sys n=int(input()) arr=[] for i in range(n): l,r=map(int,input().split()) arr.append((l,r)) arr.sort() arr1=[] arr2=[] t1=0 t2=0 for j in range(n): if j%2==0: arr1.append(arr[j]) t1+=1 else: arr2.append(arr[j]) t2+=1 arr1.append((sys.maxsize,sys.maxsize)) arr2.append((sys.maxsize,sys.maxsize)) for j in range(1,t1): if arr1[j-1][1]>=arr1[j][0]: print("NO") exit() for j in range(1,t2): if arr2[j-1][1]>=arr2[j][0]: print("NO") exit() print("YES") ```
0
1,011
A
Stages
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages. There are $n$ stages available. The rocket must contain exactly $k$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'. For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — $26$ tons. Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once.
The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket. The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once.
Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.
[ "5 3\nxyabd\n", "7 4\nproblem\n", "2 2\nab\n", "12 1\nabaabbaaabbb\n" ]
[ "29", "34", "-1", "1" ]
In the first example, the following rockets satisfy the condition: - "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$). Rocket "adx" has the minimal weight, so the answer is $29$. In the second example, target rocket is "belo". Its weight is $2+5+12+15=34$. In the third example, $n=k=2$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1.
500
[ { "input": "5 3\nxyabd", "output": "29" }, { "input": "7 4\nproblem", "output": "34" }, { "input": "2 2\nab", "output": "-1" }, { "input": "12 1\nabaabbaaabbb", "output": "1" }, { "input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa", "output": ...
1,598,709,392
2,147,483,647
Python 3
OK
TESTS
29
109
307,200
# -*- coding: utf-8 -*- """ Created on Sat Aug 29 19:16:56 2020 @author: MridulSachdeva """ n, k = map(int, input().split()) s = sorted(list(set(input()))) stages = [] for i in range(len(s)): if i == 0: stages.append(s[i]) else: if ord(s[i]) - ord(stages[-1]) >= 2: stages.append(s[i]) if len(stages) == k: break if len(stages) == k: minsum = 0 for i in range(k): minsum += ord(stages[i]) - 96 print(minsum) else: print(-1)
Title: Stages Time Limit: None seconds Memory Limit: None megabytes Problem Description: Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages. There are $n$ stages available. The rocket must contain exactly $k$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'. For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — $26$ tons. Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once. Input Specification: The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket. The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once. Output Specification: Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all. Demo Input: ['5 3\nxyabd\n', '7 4\nproblem\n', '2 2\nab\n', '12 1\nabaabbaaabbb\n'] Demo Output: ['29', '34', '-1', '1'] Note: In the first example, the following rockets satisfy the condition: - "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$). Rocket "adx" has the minimal weight, so the answer is $29$. In the second example, target rocket is "belo". Its weight is $2+5+12+15=34$. In the third example, $n=k=2$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1.
```python # -*- coding: utf-8 -*- """ Created on Sat Aug 29 19:16:56 2020 @author: MridulSachdeva """ n, k = map(int, input().split()) s = sorted(list(set(input()))) stages = [] for i in range(len(s)): if i == 0: stages.append(s[i]) else: if ord(s[i]) - ord(stages[-1]) >= 2: stages.append(s[i]) if len(stages) == k: break if len(stages) == k: minsum = 0 for i in range(k): minsum += ord(stages[i]) - 96 print(minsum) else: print(-1) ```
3
53
C
Little Frog
PROGRAMMING
1,200
[ "constructive algorithms" ]
C. Little Frog
2
256
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him.
The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds.
Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan. - All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1). If there are several solutions, output any.
[ "2\n", "3\n" ]
[ "1 2 ", "1 3 2 " ]
none
1,500
[ { "input": "2", "output": "1 2 " }, { "input": "3", "output": "1 3 2 " }, { "input": "4", "output": "1 4 2 3 " }, { "input": "5", "output": "1 5 2 4 3 " }, { "input": "6", "output": "1 6 2 5 3 4 " }, { "input": "1", "output": "1 " }, { "inp...
1,610,214,270
2,147,483,647
PyPy 3
OK
TESTS
22
216
2,867,200
n = int(input()) k1 = 1 k2 = n ans = [] for i in range(n): if i % 2 == 0: ans.append(k1) k1 += 1 else: ans.append(k2) k2 -= 1 print(*ans)
Title: Little Frog Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him. Input Specification: The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds. Output Specification: Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan. - All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1). If there are several solutions, output any. Demo Input: ['2\n', '3\n'] Demo Output: ['1 2 ', '1 3 2 '] Note: none
```python n = int(input()) k1 = 1 k2 = n ans = [] for i in range(n): if i % 2 == 0: ans.append(k1) k1 += 1 else: ans.append(k2) k2 -= 1 print(*ans) ```
3.940659
767
A
Snacktower
PROGRAMMING
1,100
[ "data structures", "implementation" ]
null
null
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top. Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower. However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it. Write a program that models the behavior of Ankh-Morpork residents.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks. The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*.
Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
[ "3\n3 1 2\n", "5\n4 5 1 2 3\n" ]
[ "3\n \n2 1", "5 4\n \n \n3 2 1\n" ]
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
500
[ { "input": "3\n3 1 2", "output": "3 \n\n2 1 " }, { "input": "5\n4 5 1 2 3", "output": "5 4 \n\n\n3 2 1 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n1 2", "output": "2 1 " }, { "input": "10\n5 1 6 2 8 3 4 10 9 7", "output": "10 \n9 8 \n7 6 5 4 3 2 1...
1,601,659,107
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
7
2,000
7,065,600
n = int(input()) snacks = list(map(int, input().split(" "))) ja_foram = [] def procurar(valor, vetor): retorno = '' contagem = 0 while True: if valor in vetor: retorno += " %s"%(valor) contagem += 1 else: return retorno, contagem valor -= 1 for s in snacks: if s == n: add, sub = procurar(s-1, ja_foram) printar = "%s%s"%(s, add) n = n-sub-1 print(printar) else: print("") ja_foram.append(s)
Title: Snacktower Time Limit: None seconds Memory Limit: None megabytes Problem Description: According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top. Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower. However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it. Write a program that models the behavior of Ankh-Morpork residents. Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks. The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. Output Specification: Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. Demo Input: ['3\n3 1 2\n', '5\n4 5 1 2 3\n'] Demo Output: ['3\n\xa0\n2 1', '5 4\n\xa0\n\xa0\n3 2 1\n'] Note: In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
```python n = int(input()) snacks = list(map(int, input().split(" "))) ja_foram = [] def procurar(valor, vetor): retorno = '' contagem = 0 while True: if valor in vetor: retorno += " %s"%(valor) contagem += 1 else: return retorno, contagem valor -= 1 for s in snacks: if s == n: add, sub = procurar(s-1, ja_foram) printar = "%s%s"%(s, add) n = n-sub-1 print(printar) else: print("") ja_foram.append(s) ```
0
439
A
Devu, the Singer and Churu, the Joker
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly. People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest. You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions: - The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100).
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
[ "3 30\n2 2 1\n", "3 20\n2 1 1\n" ]
[ "5\n", "-1\n" ]
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: - First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes. Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes. Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1.
500
[ { "input": "3 30\n2 2 1", "output": "5" }, { "input": "3 20\n2 1 1", "output": "-1" }, { "input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1", "output": "1943" }, { "input": "50 10000\n4 7 15 9 11 12 ...
1,618,974,811
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
n,m=map(int,input().split()) t=input().split()[:n] sum=0 for i in range(len(t)): sum+=int(t[i]) d=m-sum z=d//5 if z>=(sum-1): print(z) else: print(-1)
Title: Devu, the Singer and Churu, the Joker Time Limit: None seconds Memory Limit: None megabytes Problem Description: Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly. People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest. You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions: - The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event. Input Specification: The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). Output Specification: If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. Demo Input: ['3 30\n2 2 1\n', '3 20\n2 1 1\n'] Demo Output: ['5\n', '-1\n'] Note: Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: - First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes. Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes. Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1.
```python n,m=map(int,input().split()) t=input().split()[:n] sum=0 for i in range(len(t)): sum+=int(t[i]) d=m-sum z=d//5 if z>=(sum-1): print(z) else: print(-1) ```
0
598
A
Tricky Sum
PROGRAMMING
900
[ "math" ]
null
null
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*.
The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed. Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109).
Print the requested sum for each of *t* integers *n* given in the input.
[ "2\n4\n1000000000\n" ]
[ "-4\n499999998352516354\n" ]
The answer for the first sample is explained in the statement.
0
[ { "input": "2\n4\n1000000000", "output": "-4\n499999998352516354" }, { "input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25" }, { "input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53", "output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n130...
1,627,886,238
2,147,483,647
PyPy 3
OK
TESTS
21
109
21,401,600
from sys import * input = lambda:stdin.readline() int_arr = lambda : list(map(int,stdin.readline().strip().split())) str_arr = lambda :list(map(str,stdin.readline().split())) get_str = lambda : map(str,stdin.readline().strip().split()) get_int = lambda: map(int,stdin.readline().strip().split()) get_float = lambda : map(float,stdin.readline().strip().split()) mod = 1000000007 setrecursionlimit(1000) for _ in range(int(input())): n = int(input()) val = 0 ct = 0 pow_sum = 0 while True: val = 1 << ct if not val <= n: break ct += 1 pow_sum += val print((n * (n + 1) // 2) - (pow_sum * 2))
Title: Tricky Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*. Input Specification: The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed. Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109). Output Specification: Print the requested sum for each of *t* integers *n* given in the input. Demo Input: ['2\n4\n1000000000\n'] Demo Output: ['-4\n499999998352516354\n'] Note: The answer for the first sample is explained in the statement.
```python from sys import * input = lambda:stdin.readline() int_arr = lambda : list(map(int,stdin.readline().strip().split())) str_arr = lambda :list(map(str,stdin.readline().split())) get_str = lambda : map(str,stdin.readline().strip().split()) get_int = lambda: map(int,stdin.readline().strip().split()) get_float = lambda : map(float,stdin.readline().strip().split()) mod = 1000000007 setrecursionlimit(1000) for _ in range(int(input())): n = int(input()) val = 0 ct = 0 pow_sum = 0 while True: val = 1 << ct if not val <= n: break ct += 1 pow_sum += val print((n * (n + 1) // 2) - (pow_sum * 2)) ```
3
268
C
Beautiful Sets of Points
PROGRAMMING
1,500
[ "constructive algorithms", "implementation" ]
null
null
Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 1. For any two points from the set, the distance between them is a non-integer. Consider all points (*x*,<=*y*) which satisfy the inequations: 0<=≤<=*x*<=≤<=*n*; 0<=≤<=*y*<=≤<=*m*; *x*<=+<=*y*<=&gt;<=0. Choose their subset of maximum size such that it is also a beautiful set of points.
The single line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
In the first line print a single integer — the size *k* of the found beautiful set. In each of the next *k* lines print a pair of space-separated integers — the *x*- and *y*- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them.
[ "2 2\n", "4 3\n" ]
[ "3\n0 1\n1 2\n2 0\n", "4\n0 3\n2 1\n3 0\n4 2\n" ]
Consider the first sample. The distance between points (0, 1) and (1, 2) equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bfe16f27ebc966df6f10ba356a1547b6e7242dd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>, between (0, 1) and (2, 0) — <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/23d63d8a57cddda72562a512c05111054cd85870.png" style="max-width: 100.0%;max-height: 100.0%;"/>, between (1, 2) and (2, 0) — <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/23d63d8a57cddda72562a512c05111054cd85870.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution.
1,500
[ { "input": "2 2", "output": "3\n0 1\n1 2\n2 0" }, { "input": "4 3", "output": "4\n0 3\n2 1\n3 0\n4 2" }, { "input": "21 21", "output": "22\n21 0\n20 1\n19 2\n18 3\n17 4\n16 5\n15 6\n14 7\n13 8\n12 9\n11 10\n10 11\n9 12\n8 13\n7 14\n6 15\n5 16\n4 17\n3 18\n2 19\n1 20\n0 21" }, { ...
1,678,038,487
2,147,483,647
Python 3
OK
TESTS
47
92
0
from math import * n,m=map(int,input().split()) t=min(n,m) print(t+1) for i in range(t+1): print(t-i,i)
Title: Beautiful Sets of Points Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 1. For any two points from the set, the distance between them is a non-integer. Consider all points (*x*,<=*y*) which satisfy the inequations: 0<=≤<=*x*<=≤<=*n*; 0<=≤<=*y*<=≤<=*m*; *x*<=+<=*y*<=&gt;<=0. Choose their subset of maximum size such that it is also a beautiful set of points. Input Specification: The single line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Output Specification: In the first line print a single integer — the size *k* of the found beautiful set. In each of the next *k* lines print a pair of space-separated integers — the *x*- and *y*- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Demo Input: ['2 2\n', '4 3\n'] Demo Output: ['3\n0 1\n1 2\n2 0\n', '4\n0 3\n2 1\n3 0\n4 2\n'] Note: Consider the first sample. The distance between points (0, 1) and (1, 2) equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bfe16f27ebc966df6f10ba356a1547b6e7242dd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>, between (0, 1) and (2, 0) — <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/23d63d8a57cddda72562a512c05111054cd85870.png" style="max-width: 100.0%;max-height: 100.0%;"/>, between (1, 2) and (2, 0) — <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/23d63d8a57cddda72562a512c05111054cd85870.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution.
```python from math import * n,m=map(int,input().split()) t=min(n,m) print(t+1) for i in range(t+1): print(t-i,i) ```
3
519
B
A and B and Compilation Errors
PROGRAMMING
1,100
[ "data structures", "implementation", "sortings" ]
null
null
A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake. However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change. Can you help B find out exactly what two errors he corrected?
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time. The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one. The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
[ "5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n", "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n" ]
[ "8\n123\n", "1\n3\n" ]
In the first test sample B first corrects the error number 8, then the error number 123. In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.
1,000
[ { "input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7", "output": "8\n123" }, { "input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5", "output": "1\n3" }, { "input": "3\n1 2 3\n3 2\n2", "output": "1\n3" }, { "input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6...
1,653,389,161
2,147,483,647
PyPy 3-64
OK
TESTS
33
436
37,683,200
from collections import Counter n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) print(*list((Counter(a) - Counter(b)).elements())) print(*list((Counter(b) - Counter(c)).elements()))
Title: A and B and Compilation Errors Time Limit: None seconds Memory Limit: None megabytes Problem Description: A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake. However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change. Can you help B find out exactly what two errors he corrected? Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time. The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one. The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one. Output Specification: Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. Demo Input: ['5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n', '6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n'] Demo Output: ['8\n123\n', '1\n3\n'] Note: In the first test sample B first corrects the error number 8, then the error number 123. In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.
```python from collections import Counter n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) print(*list((Counter(a) - Counter(b)).elements())) print(*list((Counter(b) - Counter(c)).elements())) ```
3
252
A
Little Xor
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that. The *xor* operation is the bitwise exclusive "OR", that is denoted as "xor" in Pascal and "^" in C/C++/Java.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230.
Print a single integer — the required maximal *xor* of a segment of consecutive elements.
[ "5\n1 2 1 1 2\n", "3\n1 2 7\n", "4\n4 2 4 8\n" ]
[ "3\n", "7\n", "14\n" ]
In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one. The second sample contains only one optimal segment, which contains exactly one array element (element with index three).
500
[ { "input": "5\n1 2 1 1 2", "output": "3" }, { "input": "3\n1 2 7", "output": "7" }, { "input": "4\n4 2 4 8", "output": "14" }, { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "output": "15" }, { "inpu...
1,580,852,190
2,147,483,647
Python 3
OK
TESTS
56
248
307,200
from itertools import accumulate from operator import xor n = int(input()) A = [0] + list(accumulate(map(int, input().split()), xor)) print(max(A[i]^A[j] for i in range(n+1) for j in range(i+1,n+1)))
Title: Little Xor Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that. The *xor* operation is the bitwise exclusive "OR", that is denoted as "xor" in Pascal and "^" in C/C++/Java. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230. Output Specification: Print a single integer — the required maximal *xor* of a segment of consecutive elements. Demo Input: ['5\n1 2 1 1 2\n', '3\n1 2 7\n', '4\n4 2 4 8\n'] Demo Output: ['3\n', '7\n', '14\n'] Note: In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one. The second sample contains only one optimal segment, which contains exactly one array element (element with index three).
```python from itertools import accumulate from operator import xor n = int(input()) A = [0] + list(accumulate(map(int, input().split()), xor)) print(max(A[i]^A[j] for i in range(n+1) for j in range(i+1,n+1))) ```
3
146
A
Lucky Ticket
PROGRAMMING
800
[ "implementation" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky.
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
[ "2\n47\n", "4\n4738\n", "4\n4774\n" ]
[ "NO\n", "NO\n", "YES\n" ]
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
500
[ { "input": "2\n47", "output": "NO" }, { "input": "4\n4738", "output": "NO" }, { "input": "4\n4774", "output": "YES" }, { "input": "4\n4570", "output": "NO" }, { "input": "6\n477477", "output": "YES" }, { "input": "6\n777777", "output": "YES" }, ...
1,588,860,540
2,147,483,647
PyPy 3
OK
TESTS
46
280
20,172,800
n = int(input()) b = input() c = sorted(list(set(list(b)))) if len(c)==1: if c[0]=="4" or c[0]=="7":f=0 else:f=1 elif len(c)==2: if c[0]=="4" and c[1]=="7":f=0 else:f=1 else:f=1 if f==0 : e,r=0,0 q = list(b[0:n//2]) w = list(b[n//2:]) for i in range(len(q)): e+=int(q[i]) r+=int(w[i]) if e == r:print("YES") else:print("NO") else:print("NO")
Title: Lucky Ticket Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky. Input Specification: The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. Output Specification: On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Demo Input: ['2\n47\n', '4\n4738\n', '4\n4774\n'] Demo Output: ['NO\n', 'NO\n', 'YES\n'] Note: In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
```python n = int(input()) b = input() c = sorted(list(set(list(b)))) if len(c)==1: if c[0]=="4" or c[0]=="7":f=0 else:f=1 elif len(c)==2: if c[0]=="4" and c[1]=="7":f=0 else:f=1 else:f=1 if f==0 : e,r=0,0 q = list(b[0:n//2]) w = list(b[n//2:]) for i in range(len(q)): e+=int(q[i]) r+=int(w[i]) if e == r:print("YES") else:print("NO") else:print("NO") ```
3
673
A
Bear and Game
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game.
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=... *t**n*<=≤<=90), given in the increasing order.
Print the number of minutes Limak will watch the game.
[ "3\n7 20 88\n", "9\n16 20 30 40 50 60 70 80 90\n", "9\n15 20 30 40 50 60 70 80 90\n" ]
[ "35\n", "15\n", "90\n" ]
In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
500
[ { "input": "3\n7 20 88", "output": "35" }, { "input": "9\n16 20 30 40 50 60 70 80 90", "output": "15" }, { "input": "9\n15 20 30 40 50 60 70 80 90", "output": "90" }, { "input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88", ...
1,463,282,519
2,147,483,647
Python 3
OK
TESTS
34
77
5,120,000
n = int(input()) a = [0]+list(map(int, input().strip().split())) ans = 15 for i in range(n+1): if a[i]+15 > ans: if a[i]+15-ans <= 15: ans = a[i]+15 ans = min(ans, 90) print(ans)
Title: Bear and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game. Input Specification: The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=... *t**n*<=≤<=90), given in the increasing order. Output Specification: Print the number of minutes Limak will watch the game. Demo Input: ['3\n7 20 88\n', '9\n16 20 30 40 50 60 70 80 90\n', '9\n15 20 30 40 50 60 70 80 90\n'] Demo Output: ['35\n', '15\n', '90\n'] Note: In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
```python n = int(input()) a = [0]+list(map(int, input().strip().split())) ans = 15 for i in range(n+1): if a[i]+15 > ans: if a[i]+15-ans <= 15: ans = a[i]+15 ans = min(ans, 90) print(ans) ```
3
918
A
Eleven
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where - *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=&gt;<=2). As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.
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,633,114,028
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
7
109
23,244,800
def fibonacci(n): if n == 1 or n == 2: return 1 else: return fibonacci(n-2) + fibonacci(n-1) def fibonacciSequence(n): output = [] for i in range(1, n+1): output.append(fibonacci(i)) if fibonacci(i) > n: break return output n = int(input("")) output = "" f = fibonacciSequence(n) for i in range(1, n+1): if i in f: output += "O" else: output += "o" print(output)
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 only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where - *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=&gt;<=2). As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name. Input Specification: The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). Output Specification: Print Eleven's new name on the first and only line of output. Demo Input: ['8\n', '15\n'] Demo Output: ['OOOoOooO\n', 'OOOoOooOooooOoo\n'] Note: none
```python def fibonacci(n): if n == 1 or n == 2: return 1 else: return fibonacci(n-2) + fibonacci(n-1) def fibonacciSequence(n): output = [] for i in range(1, n+1): output.append(fibonacci(i)) if fibonacci(i) > n: break return output n = int(input("")) output = "" f = fibonacciSequence(n) for i in range(1, n+1): if i in f: output += "O" else: output += "o" print(output) ```
0
447
A
DZY Loves Hash
PROGRAMMING
800
[ "implementation" ]
null
null
DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==<=*x* *mod* *p*. Operation *a* *mod* *b* denotes taking a remainder after division *a* by *b*. However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the *i*-th insertion, you should output *i*. If no conflict happens, just output -1.
The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109).
Output a single integer — the answer to the problem.
[ "10 5\n0\n21\n53\n41\n53\n", "5 5\n0\n1\n2\n3\n4\n" ]
[ "4\n", "-1\n" ]
none
500
[ { "input": "10 5\n0\n21\n53\n41\n53", "output": "4" }, { "input": "5 5\n0\n1\n2\n3\n4", "output": "-1" }, { "input": "10 6\n811966798\n734823552\n790326404\n929189974\n414343256\n560346537", "output": "4" }, { "input": "2 2\n788371161\n801743052", "output": "-1" }, { ...
1,591,430,486
2,147,483,647
Python 3
OK
TESTS
29
109
0
p,n=map(int,input().split()) h=[] flag=0 for i in range(n): x=int(input()) y=x%p if y in h and flag==0: print(i+1) flag=1 else: h.append(y) if flag==0 and i==n-1: print(-1)
Title: DZY Loves Hash Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==<=*x* *mod* *p*. Operation *a* *mod* *b* denotes taking a remainder after division *a* by *b*. However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the *i*-th insertion, you should output *i*. If no conflict happens, just output -1. Input Specification: The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109). Output Specification: Output a single integer — the answer to the problem. Demo Input: ['10 5\n0\n21\n53\n41\n53\n', '5 5\n0\n1\n2\n3\n4\n'] Demo Output: ['4\n', '-1\n'] Note: none
```python p,n=map(int,input().split()) h=[] flag=0 for i in range(n): x=int(input()) y=x%p if y in h and flag==0: print(i+1) flag=1 else: h.append(y) if flag==0 and i==n-1: print(-1) ```
3
992
A
Nastya and an Array
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero. - When all elements of the array become equal to zero, the array explodes. Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array.
Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero.
[ "5\n1 1 1 1 1\n", "3\n2 0 -1\n", "4\n5 -6 -5 1\n" ]
[ "1\n", "2\n", "4\n" ]
In the first example you can add  - 1 to all non-zero elements in one second and make them equal to zero. In the second example you can add  - 2 on the first second, then the array becomes equal to [0, 0,  - 3]. On the second second you can add 3 to the third (the only non-zero) element.
500
[ { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "3\n2 0 -1", "output": "2" }, { "input": "4\n5 -6 -5 1", "output": "4" }, { "input": "1\n0", "output": "0" }, { "input": "2\n21794 -79194", "output": "2" }, { "input": "3\n-63526 95085 -5239", ...
1,550,529,661
2,147,483,647
PyPy 3
OK
TESTS
79
202
10,956,800
n = int(input()) check=[0]*(pow(10,5)+5) a = list(map(int,input().split())) b=set(a) if 0 in b: print(len(b)-1) else: print(len(b))
Title: Nastya and an Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero. - When all elements of the array become equal to zero, the array explodes. Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array. Output Specification: Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero. Demo Input: ['5\n1 1 1 1 1\n', '3\n2 0 -1\n', '4\n5 -6 -5 1\n'] Demo Output: ['1\n', '2\n', '4\n'] Note: In the first example you can add  - 1 to all non-zero elements in one second and make them equal to zero. In the second example you can add  - 2 on the first second, then the array becomes equal to [0, 0,  - 3]. On the second second you can add 3 to the third (the only non-zero) element.
```python n = int(input()) check=[0]*(pow(10,5)+5) a = list(map(int,input().split())) b=set(a) if 0 in b: print(len(b)-1) else: print(len(b)) ```
3
653
B
Bear and Compressing
PROGRAMMING
1,300
[ "brute force", "dfs and similar", "dp", "strings" ]
null
null
Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of *q* possible operations. Limak can perform them in any order, any operation may be applied any number of times. The *i*-th operation is described by a string *a**i* of length two and a string *b**i* of length one. No two of *q* possible operations have the same string *a**i*. When Limak has a string *s* he can perform the *i*-th operation on *s* if the first two letters of *s* match a two-letter string *a**i*. Performing the *i*-th operation removes first two letters of *s* and inserts there a string *b**i*. See the notes section for further clarification. You may note that performing an operation decreases the length of a string *s* exactly by 1. Also, for some sets of operations there may be a string that cannot be compressed any further, because the first two letters don't match any *a**i*. Limak wants to start with a string of length *n* and perform *n*<=-<=1 operations to finally get a one-letter string "a". In how many ways can he choose the starting string to be able to get "a"? Remember that Limak can use only letters he knows.
The first line contains two integers *n* and *q* (2<=≤<=*n*<=≤<=6, 1<=≤<=*q*<=≤<=36) — the length of the initial string and the number of available operations. The next *q* lines describe the possible operations. The *i*-th of them contains two strings *a**i* and *b**i* (|*a**i*|<==<=2,<=|*b**i*|<==<=1). It's guaranteed that *a**i*<=≠<=*a**j* for *i*<=≠<=*j* and that all *a**i* and *b**i* consist of only first six lowercase English letters.
Print the number of strings of length *n* that Limak will be able to transform to string "a" by applying only operations given in the input.
[ "3 5\nab a\ncc c\nca a\nee c\nff d\n", "2 8\naf e\ndc d\ncc f\nbc b\nda b\neb a\nbb b\nff c\n", "6 2\nbb a\nba a\n" ]
[ "4\n", "1\n", "0\n" ]
In the first sample, we count initial strings of length 3 from which Limak can get a required string "a". There are 4 such strings: "abb", "cab", "cca", "eea". The first one Limak can compress using operation 1 two times (changing "ab" to a single "a"). The first operation would change "abb" to "ab" and the second operation would change "ab" to "a". Other three strings may be compressed as follows: - "cab" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ab" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "a" - "cca" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ca" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "a" - "eea" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ca" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "a" In the second sample, the only correct initial string is "eb" because it can be immediately compressed to "a".
1,000
[ { "input": "3 5\nab a\ncc c\nca a\nee c\nff d", "output": "4" }, { "input": "2 8\naf e\ndc d\ncc f\nbc b\nda b\neb a\nbb b\nff c", "output": "1" }, { "input": "6 2\nbb a\nba a", "output": "0" }, { "input": "2 5\nfe b\nbb a\naf b\nfd b\nbf c", "output": "1" }, { "i...
1,462,238,812
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
4,608,000
def main(): (n, q) = (int(x) for x in input().split()) L = [None] * q for i in range(q): (a, b) = (int(x) for x in input().split()) L[i] = (a, b) print(solver(n, L)) def solver(n, L): count = 0 for (a, b) in L: if b == 'a': count += helper(n - 2, L, a[0]) return count def helper(n, L, last): if n == 0: return 1 else: count = 0 for (a, b) in L: if b == last: count += helper(n - 1, L, a[0]) return count # L = [('ab', 'a'), ('cc', 'c'), ('ca', 'a'), ('ee', 'c'), # ('ff', 'd')] # L2 = [('bb', 'a'), ('ba', 'a')] # print(solver(6, L2)) main()
Title: Bear and Compressing Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of *q* possible operations. Limak can perform them in any order, any operation may be applied any number of times. The *i*-th operation is described by a string *a**i* of length two and a string *b**i* of length one. No two of *q* possible operations have the same string *a**i*. When Limak has a string *s* he can perform the *i*-th operation on *s* if the first two letters of *s* match a two-letter string *a**i*. Performing the *i*-th operation removes first two letters of *s* and inserts there a string *b**i*. See the notes section for further clarification. You may note that performing an operation decreases the length of a string *s* exactly by 1. Also, for some sets of operations there may be a string that cannot be compressed any further, because the first two letters don't match any *a**i*. Limak wants to start with a string of length *n* and perform *n*<=-<=1 operations to finally get a one-letter string "a". In how many ways can he choose the starting string to be able to get "a"? Remember that Limak can use only letters he knows. Input Specification: The first line contains two integers *n* and *q* (2<=≤<=*n*<=≤<=6, 1<=≤<=*q*<=≤<=36) — the length of the initial string and the number of available operations. The next *q* lines describe the possible operations. The *i*-th of them contains two strings *a**i* and *b**i* (|*a**i*|<==<=2,<=|*b**i*|<==<=1). It's guaranteed that *a**i*<=≠<=*a**j* for *i*<=≠<=*j* and that all *a**i* and *b**i* consist of only first six lowercase English letters. Output Specification: Print the number of strings of length *n* that Limak will be able to transform to string "a" by applying only operations given in the input. Demo Input: ['3 5\nab a\ncc c\nca a\nee c\nff d\n', '2 8\naf e\ndc d\ncc f\nbc b\nda b\neb a\nbb b\nff c\n', '6 2\nbb a\nba a\n'] Demo Output: ['4\n', '1\n', '0\n'] Note: In the first sample, we count initial strings of length 3 from which Limak can get a required string "a". There are 4 such strings: "abb", "cab", "cca", "eea". The first one Limak can compress using operation 1 two times (changing "ab" to a single "a"). The first operation would change "abb" to "ab" and the second operation would change "ab" to "a". Other three strings may be compressed as follows: - "cab" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ab" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "a" - "cca" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ca" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "a" - "eea" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ca" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "a" In the second sample, the only correct initial string is "eb" because it can be immediately compressed to "a".
```python def main(): (n, q) = (int(x) for x in input().split()) L = [None] * q for i in range(q): (a, b) = (int(x) for x in input().split()) L[i] = (a, b) print(solver(n, L)) def solver(n, L): count = 0 for (a, b) in L: if b == 'a': count += helper(n - 2, L, a[0]) return count def helper(n, L, last): if n == 0: return 1 else: count = 0 for (a, b) in L: if b == last: count += helper(n - 1, L, a[0]) return count # L = [('ab', 'a'), ('cc', 'c'), ('ca', 'a'), ('ee', 'c'), # ('ff', 'd')] # L2 = [('bb', 'a'), ('ba', 'a')] # print(solver(6, L2)) main() ```
-1
954
A
Diagonal Walking
PROGRAMMING
800
[ "implementation" ]
null
null
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left. Your problem is to print the minimum possible length of the sequence of moves after the replacements.
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R.
Print the minimum possible length of the sequence of moves after all replacements are done.
[ "5\nRUURU\n", "17\nUUURRRRRUUURURUUU\n" ]
[ "3\n", "13\n" ]
In the first test the shortened sequence of moves may be DUD (its length is 3). In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).
0
[ { "input": "5\nRUURU", "output": "3" }, { "input": "17\nUUURRRRRUUURURUUU", "output": "13" }, { "input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", "output": "100" }, { "input": "100\nRRURRUUUURURRRURRRRURRRRRR...
1,637,572,483
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
x=int(input()) a=input() b=a.count('RU') d=b e=x-d print(e-1)
Title: Diagonal Walking Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left. Your problem is to print the minimum possible length of the sequence of moves after the replacements. Input Specification: The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. Output Specification: Print the minimum possible length of the sequence of moves after all replacements are done. Demo Input: ['5\nRUURU\n', '17\nUUURRRRRUUURURUUU\n'] Demo Output: ['3\n', '13\n'] Note: In the first test the shortened sequence of moves may be DUD (its length is 3). In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).
```python x=int(input()) a=input() b=a.count('RU') d=b e=x-d print(e-1) ```
0
440
A
Forgotten Episode
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to *n*. The second line contains *n*<=-<=1 integer *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the numbers of episodes that Polycarpus has watched. All values of *a**i* are distinct.
Print the number of the episode that Polycarpus hasn't watched.
[ "10\n3 8 10 1 7 9 6 5 2\n" ]
[ "4\n" ]
none
500
[ { "input": "10\n3 8 10 1 7 9 6 5 2", "output": "4" }, { "input": "5\n4 3 2 1", "output": "5" }, { "input": "2\n1", "output": "2" }, { "input": "2\n2", "output": "1" }, { "input": "3\n1 2", "output": "3" }, { "input": "3\n1 3", "output": "2" }, ...
1,675,668,628
2,147,483,647
Python 3
OK
TESTS
35
93
6,553,600
# LUOGU_RID: 101569075 n, *a = map(int, open(0).read().split()) s = set(a) for i in range(1, n + 1): if not i in s: exit(print(i))
Title: Forgotten Episode Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input Specification: The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to *n*. The second line contains *n*<=-<=1 integer *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the numbers of episodes that Polycarpus has watched. All values of *a**i* are distinct. Output Specification: Print the number of the episode that Polycarpus hasn't watched. Demo Input: ['10\n3 8 10 1 7 9 6 5 2\n'] Demo Output: ['4\n'] Note: none
```python # LUOGU_RID: 101569075 n, *a = map(int, open(0).read().split()) s = set(a) for i in range(1, n + 1): if not i in s: exit(print(i)) ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,697,098,770
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
n=int(input()) w=[0,0,0] for i in range(n): x,y,z=map(int,input().split()) w[0]=w[0]+x w[1]=w[0]+y w[2]=w[0]+z if w[0]==0 and w[1]==0 and w[2]==0 : print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python n=int(input()) w=[0,0,0] for i in range(n): x,y,z=map(int,input().split()) w[0]=w[0]+x w[1]=w[0]+y w[2]=w[0]+z if w[0]==0 and w[1]==0 and w[2]==0 : print("YES") else: print("NO") ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,619,610,928
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
216
2,048,000
n=input() u=0 l=0 flag=0 lst=["HoUse","ViP","maTRIx"] lst1=["house","VIP","matrix"] for i in range(len(lst)): if lst[i]==n: print(lst1[i]) flag=1 break if falg==0: for i in n: if i.isupper(): u+=1 else: l+=1 if l==u: print(n.lower()) else: print(n.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python n=input() u=0 l=0 flag=0 lst=["HoUse","ViP","maTRIx"] lst1=["house","VIP","matrix"] for i in range(len(lst)): if lst[i]==n: print(lst1[i]) flag=1 break if falg==0: for i in n: if i.isupper(): u+=1 else: l+=1 if l==u: print(n.lower()) else: print(n.upper()) ```
-1
851
B
Arpa and an exam about geometry
PROGRAMMING
1,400
[ "geometry", "math" ]
null
null
Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points *a*,<=*b*,<=*c*. Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old position of *c*. Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct.
Print "Yes" if the problem has a solution, "No" otherwise. You can print each letter in any case (upper or lower).
[ "0 1 1 1 1 0\n", "1 1 0 0 1000 1000\n" ]
[ "Yes\n", "No\n" ]
In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test, you can't find any solution.
1,000
[ { "input": "0 1 1 1 1 0", "output": "Yes" }, { "input": "1 1 0 0 1000 1000", "output": "No" }, { "input": "1 0 2 0 3 0", "output": "No" }, { "input": "3 4 0 0 4 3", "output": "Yes" }, { "input": "-1000000000 1 0 0 1000000000 1", "output": "Yes" }, { "i...
1,534,351,839
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
108
0
import math ax,ay,bx,by,cx,cy=map(int,input().split()) dis1=((ax-bx)**2+(ay-by)**2)**0.5 dis2=((cx-bx)**2+(cy-by)**2)**0.5 #print(dis1,dis2) if(dis1!=dis2):print("No") else: if(ax!=bx and bx!=cx): if((ay-by)/(ax-bx)!=(by-cy)/(bx-cx)):print("No") else: print("Yes") elif(ax==bx and bx==cx): print("No") elif(ax==bx or bx==cx): print("Yes")
Title: Arpa and an exam about geometry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points *a*,<=*b*,<=*c*. Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old position of *c*. Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not. Input Specification: The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct. Output Specification: Print "Yes" if the problem has a solution, "No" otherwise. You can print each letter in any case (upper or lower). Demo Input: ['0 1 1 1 1 0\n', '1 1 0 0 1000 1000\n'] Demo Output: ['Yes\n', 'No\n'] Note: In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test, you can't find any solution.
```python import math ax,ay,bx,by,cx,cy=map(int,input().split()) dis1=((ax-bx)**2+(ay-by)**2)**0.5 dis2=((cx-bx)**2+(cy-by)**2)**0.5 #print(dis1,dis2) if(dis1!=dis2):print("No") else: if(ax!=bx and bx!=cx): if((ay-by)/(ax-bx)!=(by-cy)/(bx-cx)):print("No") else: print("Yes") elif(ax==bx and bx==cx): print("No") elif(ax==bx or bx==cx): print("Yes") ```
0
412
C
Pattern
PROGRAMMING
1,200
[ "implementation", "strings" ]
null
null
Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules. In this task, a pattern will be a string consisting of small English letters and question marks ('?'). The question mark in the pattern is a metacharacter that denotes an arbitrary small letter of the English alphabet. We will assume that a string matches the pattern if we can transform the string into the pattern by replacing the question marks by the appropriate characters. For example, string aba matches patterns: ???, ??a, a?a, aba. Programmers that work for the R1 company love puzzling each other (and themselves) with riddles. One of them is as follows: you are given *n* patterns of the same length, you need to find a pattern that contains as few question marks as possible, and intersects with each of the given patterns. Two patterns intersect if there is a string that matches both the first and the second pattern. Can you solve this riddle?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of patterns. Next *n* lines contain the patterns. It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does not exceed 105 characters.
In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them.
[ "2\n?ab\n??b\n", "2\na\nb\n", "1\n?a?b\n" ]
[ "xab\n", "?\n", "cacb\n" ]
Consider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot of other optimal answers, for example: aab, bab, cab, dab and so on.
1,500
[ { "input": "2\n?ab\n??b", "output": "xab" }, { "input": "2\na\nb", "output": "?" }, { "input": "1\n?a?b", "output": "cacb" }, { "input": "1\n?", "output": "x" }, { "input": "3\nabacaba\nabacaba\nabacaba", "output": "abacaba" }, { "input": "3\nabc?t\n?b...
1,669,445,435
2,147,483,647
PyPy 3-64
OK
TESTS
70
576
11,161,600
from collections import defaultdict tests = int(input()) arr = [] ans = [] for _ in range(tests): arr.append(input()) size = len(arr[0]) for i in range(size): char = 'a' count = defaultdict(int) for j in range(len(arr)): if arr[j][i] != '?': count[arr[j][i]] += 1 char = arr[j][i] if len(count) <= 1: ans.append(char) else: ans.append('?') print(''.join(ans))
Title: Pattern Time Limit: None seconds Memory Limit: None megabytes Problem Description: Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules. In this task, a pattern will be a string consisting of small English letters and question marks ('?'). The question mark in the pattern is a metacharacter that denotes an arbitrary small letter of the English alphabet. We will assume that a string matches the pattern if we can transform the string into the pattern by replacing the question marks by the appropriate characters. For example, string aba matches patterns: ???, ??a, a?a, aba. Programmers that work for the R1 company love puzzling each other (and themselves) with riddles. One of them is as follows: you are given *n* patterns of the same length, you need to find a pattern that contains as few question marks as possible, and intersects with each of the given patterns. Two patterns intersect if there is a string that matches both the first and the second pattern. Can you solve this riddle? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of patterns. Next *n* lines contain the patterns. It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does not exceed 105 characters. Output Specification: In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them. Demo Input: ['2\n?ab\n??b\n', '2\na\nb\n', '1\n?a?b\n'] Demo Output: ['xab\n', '?\n', 'cacb\n'] Note: Consider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot of other optimal answers, for example: aab, bab, cab, dab and so on.
```python from collections import defaultdict tests = int(input()) arr = [] ans = [] for _ in range(tests): arr.append(input()) size = len(arr[0]) for i in range(size): char = 'a' count = defaultdict(int) for j in range(len(arr)): if arr[j][i] != '?': count[arr[j][i]] += 1 char = arr[j][i] if len(count) <= 1: ans.append(char) else: ans.append('?') print(''.join(ans)) ```
3
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 Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally.
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,518,628,052
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
5,632,000
n, m = map(int, raw_input().split()) a = list(map(int, raw_input().split())) b = list(map(int, raw_input().split())) q = [int(-1e18)] * n for x in xrange(n): for y in b: q[x] = max(q[x], a[x] * y) q.sort() print(q[n-2])
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 cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally. Input Specification: 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. Output Specification: Print a single integer — the brightness of the chosen pair. Demo Input: ['2 2\n20 18\n2 14\n', '5 3\n-1 0 1 2 3\n-1 0 1\n'] Demo Output: ['252\n', '2\n'] Note: 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.
```python n, m = map(int, raw_input().split()) a = list(map(int, raw_input().split())) b = list(map(int, raw_input().split())) q = [int(-1e18)] * n for x in xrange(n): for y in b: q[x] = max(q[x], a[x] * y) q.sort() print(q[n-2]) ```
-1
479
A
Expression
PROGRAMMING
1,000
[ "brute force", "math" ]
null
null
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: - 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9 Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given *a*, *b* and *c* print the maximum value that you can get.
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Print the maximum value of the expression that you can obtain.
[ "1\n2\n3\n", "2\n10\n3\n" ]
[ "9\n", "60\n" ]
none
500
[ { "input": "1\n2\n3", "output": "9" }, { "input": "2\n10\n3", "output": "60" }, { "input": "1\n1\n1", "output": "3" }, { "input": "1\n2\n1", "output": "4" }, { "input": "10\n10\n10", "output": "1000" }, { "input": "5\n1\n3", "output": "20" }, {...
1,694,758,242
2,147,483,647
Python 3
OK
TESTS
29
31
0
n = [] a = int(input()) n.append(a) a = int(input()) n.append(a) a = int(input()) n.append(a) eqs = ["a+b*c", "a*(b+c)", "a*b*c", "(a+b)*c", "a+b+c"] maxi = -1 for eq in eqs: eq = eq.replace('a', str(n[0])) eq = eq.replace('b', str(n[1])) eq = eq.replace('c', str(n[2])) res = eval(eq) if res > maxi: maxi = res print(maxi)
Title: Expression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: - 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9 Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given *a*, *b* and *c* print the maximum value that you can get. Input Specification: The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). Output Specification: Print the maximum value of the expression that you can obtain. Demo Input: ['1\n2\n3\n', '2\n10\n3\n'] Demo Output: ['9\n', '60\n'] Note: none
```python n = [] a = int(input()) n.append(a) a = int(input()) n.append(a) a = int(input()) n.append(a) eqs = ["a+b*c", "a*(b+c)", "a*b*c", "(a+b)*c", "a+b+c"] maxi = -1 for eq in eqs: eq = eq.replace('a', str(n[0])) eq = eq.replace('b', str(n[1])) eq = eq.replace('c', str(n[2])) res = eval(eq) if res > maxi: maxi = res print(maxi) ```
3
266
A
Stones on the Table
PROGRAMMING
800
[ "implementation" ]
null
null
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
Print a single integer — the answer to the problem.
[ "3\nRRG\n", "5\nRRRRR\n", "4\nBRBG\n" ]
[ "1\n", "4\n", "0\n" ]
none
500
[ { "input": "3\nRRG", "output": "1" }, { "input": "5\nRRRRR", "output": "4" }, { "input": "4\nBRBG", "output": "0" }, { "input": "1\nB", "output": "0" }, { "input": "2\nBG", "output": "0" }, { "input": "3\nBGB", "output": "0" }, { "input": "...
1,696,094,719
2,147,483,647
Python 3
OK
TESTS
34
92
0
n = eval(input()) s = input() m = 0 for i in range(n-1): if s[i] == s[i+1]: m += 1 print(m)
Title: Stones on the Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['3\nRRG\n', '5\nRRRRR\n', '4\nBRBG\n'] Demo Output: ['1\n', '4\n', '0\n'] Note: none
```python n = eval(input()) s = input() m = 0 for i in range(n-1): if s[i] == s[i+1]: m += 1 print(m) ```
3
141
A
Amusing Joke
PROGRAMMING
800
[ "implementation", "sortings", "strings" ]
null
null
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door. The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters. Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.
The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.
Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.
[ "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n", "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n", "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n" ]
[ "YES\n", "NO\n", "NO\n" ]
In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left. In the second sample letter "P" is missing from the pile and there's an extra letter "L". In the third sample there's an extra letter "L".
500
[ { "input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS", "output": "YES" }, { "input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI", "output": "NO" }, { "input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER", "output": "NO" }, { "input": "B\nA\nAB", "output": ...
1,679,978,692
2,147,483,647
Python 3
OK
TESTS
54
92
0
# -*- coding: utf-8 -*- """ Created on Tue Mar 28 01:36:26 2023 @author: Srusty Sahoo """ n1=[*input()] n2=[*input()] n3=[*input()] if sorted(n1+n2)==sorted(n3): print("YES") else: print("NO")
Title: Amusing Joke Time Limit: None seconds Memory Limit: None megabytes Problem Description: So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door. The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters. Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning. Input Specification: The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100. Output Specification: Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. Demo Input: ['SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n', 'PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n', 'BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left. In the second sample letter "P" is missing from the pile and there's an extra letter "L". In the third sample there's an extra letter "L".
```python # -*- coding: utf-8 -*- """ Created on Tue Mar 28 01:36:26 2023 @author: Srusty Sahoo """ n1=[*input()] n2=[*input()] n3=[*input()] if sorted(n1+n2)==sorted(n3): print("YES") else: print("NO") ```
3
508
A
Pasha and Pixels
PROGRAMMING
1,100
[ "brute force" ]
null
null
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed. Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move. Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed.
The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform. The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move.
If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed. If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0.
[ "2 2 4\n1 1\n1 2\n2 1\n2 2\n", "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n", "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n" ]
[ "4\n", "5\n", "0\n" ]
none
500
[ { "input": "2 2 4\n1 1\n1 2\n2 1\n2 2", "output": "4" }, { "input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1", "output": "5" }, { "input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2", "output": "0" }, { "input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3", ...
1,697,557,273
2,147,483,647
Python 3
OK
TESTS
52
436
10,649,600
# -*- coding: utf-8 -*- """ Created on Tue Oct 17 23:17:29 2023 @author: 2300011794 """ n,m,k=map(int,input().split()) rec=[] flag=-1 for i in range (n+2): rec.append([]) for j in range (m+2): rec[i].append(0) for i in range (k): x,y=map(int,input().split()) if n+m<4: flag=0 if flag!=-1: continue rec[x][y]=1 if rec[x-1][y-1]+rec[x-1][y]+rec[x][y-1]+rec[x][y]==4 or rec[x+1][y-1]+rec[x+1][y]+rec[x][y-1]+rec[x][y]==4 or rec[x-1][y+1]+rec[x-1][y]+rec[x][y+1]+rec[x][y]==4 or rec[x+1][y+1]+rec[x+1][y]+rec[x][y+1]+rec[x][y]==4: flag=i+1 continue if flag==-1: flag=0 print(flag)
Title: Pasha and Pixels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed. Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move. Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed. Input Specification: The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform. The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move. Output Specification: If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed. If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0. Demo Input: ['2 2 4\n1 1\n1 2\n2 1\n2 2\n', '2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n', '5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n'] Demo Output: ['4\n', '5\n', '0\n'] Note: none
```python # -*- coding: utf-8 -*- """ Created on Tue Oct 17 23:17:29 2023 @author: 2300011794 """ n,m,k=map(int,input().split()) rec=[] flag=-1 for i in range (n+2): rec.append([]) for j in range (m+2): rec[i].append(0) for i in range (k): x,y=map(int,input().split()) if n+m<4: flag=0 if flag!=-1: continue rec[x][y]=1 if rec[x-1][y-1]+rec[x-1][y]+rec[x][y-1]+rec[x][y]==4 or rec[x+1][y-1]+rec[x+1][y]+rec[x][y-1]+rec[x][y]==4 or rec[x-1][y+1]+rec[x-1][y]+rec[x][y+1]+rec[x][y]==4 or rec[x+1][y+1]+rec[x+1][y]+rec[x][y+1]+rec[x][y]==4: flag=i+1 continue if flag==-1: flag=0 print(flag) ```
3
591
B
Rebranding
PROGRAMMING
1,200
[ "implementation", "strings" ]
null
null
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name. For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation. Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive. Satisfy Arkady's curiosity and tell him the final version of the name.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively. The second line consists of *n* lowercase English letters and represents the original name of the corporation. Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*.
Print the new name of the corporation.
[ "6 1\npolice\np m\n", "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n" ]
[ "molice\n", "cdcbcdcfcdc\n" ]
In the second sample the name of the corporation consecutively changes as follows: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/de89ad7bc7f27c46ec34f5e66ce0dc23bd5bc90a.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/812e653c8d7ff496e6a0f04c676423806751531e.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19c564fcefb8dde36256240a8b877bb6a4792bfe.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1cafd93792430ad1a49e893e04715383bdae757.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "6 1\npolice\np m", "output": "molice" }, { "input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b", "output": "cdcbcdcfcdc" }, { "input": "1 1\nf\nz h", "output": "f" }, { "input": "1 1\na\na b", "output": "b" }, { "input": "10 10\nlellelleel\ne l\n...
1,445,769,992
6,392
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
4
2,000
0
n, m = map(int, input().split()) name=input() for i in range(0,m,1): x,y=map( str , input().split()) newStr="" for j in range(0,n,1): if name[j]==x: newStr=newStr+y elif name[j]==y: newStr=newStr+x else: newStr=newStr+name[j] name=newStr print(name)
Title: Rebranding Time Limit: None seconds Memory Limit: None megabytes Problem Description: The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name. For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation. Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive. Satisfy Arkady's curiosity and tell him the final version of the name. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively. The second line consists of *n* lowercase English letters and represents the original name of the corporation. Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*. Output Specification: Print the new name of the corporation. Demo Input: ['6 1\npolice\np m\n', '11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n'] Demo Output: ['molice\n', 'cdcbcdcfcdc\n'] Note: In the second sample the name of the corporation consecutively changes as follows: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/de89ad7bc7f27c46ec34f5e66ce0dc23bd5bc90a.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/812e653c8d7ff496e6a0f04c676423806751531e.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19c564fcefb8dde36256240a8b877bb6a4792bfe.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1cafd93792430ad1a49e893e04715383bdae757.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python n, m = map(int, input().split()) name=input() for i in range(0,m,1): x,y=map( str , input().split()) newStr="" for j in range(0,n,1): if name[j]==x: newStr=newStr+y elif name[j]==y: newStr=newStr+x else: newStr=newStr+name[j] name=newStr print(name) ```
0
63
A
Sinking Ship
PROGRAMMING
900
[ "implementation", "sortings", "strings" ]
A. Sinking Ship
2
256
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically: The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last. If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less). For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew.
The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain.
Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship.
[ "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n" ]
[ "Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n" ]
none
500
[ { "input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack" }, { "input": "1\nA captain", "output": "A" }, { "input": "1\nAbcdefjhij captain", "output": "Abcdefjhij" }, { "input": "5\nA captain...
1,600,958,193
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
186
307,200
c = [] m = [] wc = [] r = [] n = int(input()) n = 6 con = 0 while n > 0: fl = [] name = input() fl = name.split() if fl[1] == 'captain': c.append(fl[0]) if fl[1] == 'man': m.append(fl[0]) if fl[1] == 'child' or fl[1] == 'woman': wc.append(fl[0]) if fl[1] == 'rat': r.append(fl[0]) n = n-1 con=con+1 s = (r , wc , m , c) for x in s: for y in x: print(y)
Title: Sinking Ship Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically: The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last. If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less). For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. Input Specification: The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. Output Specification: Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. Demo Input: ['6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n'] Demo Output: ['Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n'] Note: none
```python c = [] m = [] wc = [] r = [] n = int(input()) n = 6 con = 0 while n > 0: fl = [] name = input() fl = name.split() if fl[1] == 'captain': c.append(fl[0]) if fl[1] == 'man': m.append(fl[0]) if fl[1] == 'child' or fl[1] == 'woman': wc.append(fl[0]) if fl[1] == 'rat': r.append(fl[0]) n = n-1 con=con+1 s = (r , wc , m , c) for x in s: for y in x: print(y) ```
-1
873
A
Chores
PROGRAMMING
800
[ "implementation" ]
null
null
Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted. Also Luba can work really hard on some chores. She can choose not more than *k* any chores and do each of them in *x* units of time instead of *a**i* (). Luba is very responsible, so she has to do all *n* chores, and now she wants to know the minimum time she needs to do everything. Luba cannot do two chores simultaneously.
The first line contains three integers *n*,<=*k*,<=*x* (1<=≤<=*k*<=≤<=*n*<=≤<=100,<=1<=≤<=*x*<=≤<=99) — the number of chores Luba has to do, the number of chores she can do in *x* units of time, and the number *x* itself. The second line contains *n* integer numbers *a**i* (2<=≤<=*a**i*<=≤<=100) — the time Luba has to spend to do *i*-th chore. It is guaranteed that , and for each *a**i*<=≥<=*a**i*<=-<=1.
Print one number — minimum time Luba needs to do all *n* chores.
[ "4 2 2\n3 6 7 10\n", "5 2 1\n100 100 100 100 100\n" ]
[ "13\n", "302\n" ]
In the first example the best option would be to do the third and the fourth chore, spending *x* = 2 time on each instead of *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, respectively. Then the answer is 3 + 6 + 2 + 2 = 13. In the second example Luba can choose any two chores to spend *x* time on them instead of *a*<sub class="lower-index">*i*</sub>. So the answer is 100·3 + 2·1 = 302.
0
[ { "input": "4 2 2\n3 6 7 10", "output": "13" }, { "input": "5 2 1\n100 100 100 100 100", "output": "302" }, { "input": "1 1 1\n100", "output": "1" }, { "input": "100 1 99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ...
1,636,256,939
2,147,483,647
Python 3
OK
TESTS
11
46
4,300,800
n, k, x = map(int, input().split()) a = list(map(int, input().split())) print(x * min(k, n) + sum(a[:max(0, n - k)]))
Title: Chores Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted. Also Luba can work really hard on some chores. She can choose not more than *k* any chores and do each of them in *x* units of time instead of *a**i* (). Luba is very responsible, so she has to do all *n* chores, and now she wants to know the minimum time she needs to do everything. Luba cannot do two chores simultaneously. Input Specification: The first line contains three integers *n*,<=*k*,<=*x* (1<=≤<=*k*<=≤<=*n*<=≤<=100,<=1<=≤<=*x*<=≤<=99) — the number of chores Luba has to do, the number of chores she can do in *x* units of time, and the number *x* itself. The second line contains *n* integer numbers *a**i* (2<=≤<=*a**i*<=≤<=100) — the time Luba has to spend to do *i*-th chore. It is guaranteed that , and for each *a**i*<=≥<=*a**i*<=-<=1. Output Specification: Print one number — minimum time Luba needs to do all *n* chores. Demo Input: ['4 2 2\n3 6 7 10\n', '5 2 1\n100 100 100 100 100\n'] Demo Output: ['13\n', '302\n'] Note: In the first example the best option would be to do the third and the fourth chore, spending *x* = 2 time on each instead of *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, respectively. Then the answer is 3 + 6 + 2 + 2 = 13. In the second example Luba can choose any two chores to spend *x* time on them instead of *a*<sub class="lower-index">*i*</sub>. So the answer is 100·3 + 2·1 = 302.
```python n, k, x = map(int, input().split()) a = list(map(int, input().split())) print(x * min(k, n) + sum(a[:max(0, n - k)])) ```
3
978
A
Remove Duplicates
PROGRAMMING
800
[ "implementation" ]
null
null
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.
The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array. The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array.
In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.
[ "6\n1 5 5 1 6 1\n", "5\n2 4 2 4 4\n", "5\n6 6 6 6 6\n" ]
[ "3\n5 6 1 \n", "2\n2 4 \n", "1\n6 \n" ]
In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$. In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$. In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$.
0
[ { "input": "6\n1 5 5 1 6 1", "output": "3\n5 6 1 " }, { "input": "5\n2 4 2 4 4", "output": "2\n2 4 " }, { "input": "5\n6 6 6 6 6", "output": "1\n6 " }, { "input": "7\n1 2 3 4 2 2 3", "output": "4\n1 4 2 3 " }, { "input": "9\n100 100 100 99 99 99 100 100 100", ...
1,683,445,893
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
def remove_duplicates(n, arr): last_index = {} for i in range(n - 1, -1, -1): last_index[arr[i]] = i unique_elements = list(last_index.keys()) return len(unique_elements), unique_elements def main(): n = int(input()) arr = list(map(int, input().split())) count, unique_elements = remove_duplicates(n, arr) print(count) print(' '.join(map(str, unique_elements))) if __name__ == '__main__': main()
Title: Remove Duplicates Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input Specification: The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array. The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array. Output Specification: In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Demo Input: ['6\n1 5 5 1 6 1\n', '5\n2 4 2 4 4\n', '5\n6 6 6 6 6\n'] Demo Output: ['3\n5 6 1 \n', '2\n2 4 \n', '1\n6 \n'] Note: In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$. In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$. In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$.
```python def remove_duplicates(n, arr): last_index = {} for i in range(n - 1, -1, -1): last_index[arr[i]] = i unique_elements = list(last_index.keys()) return len(unique_elements), unique_elements def main(): n = int(input()) arr = list(map(int, input().split())) count, unique_elements = remove_duplicates(n, arr) print(count) print(' '.join(map(str, unique_elements))) if __name__ == '__main__': main() ```
0
0
none
none
none
0
[ "none" ]
null
null
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play.
In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3\n3 2 2\n", "4\n2 2 2 2\n" ]
[ "4\n", "3\n" ]
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
0
[ { "input": "3\n3 2 2", "output": "4" }, { "input": "4\n2 2 2 2", "output": "3" }, { "input": "7\n9 7 7 8 8 7 8", "output": "9" }, { "input": "10\n13 12 10 13 13 14 10 10 12 12", "output": "14" }, { "input": "10\n94 96 91 95 99 94 96 92 95 99", "output": "106" ...
1,611,314,890
5,110
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
7
2,000
1,843,200
t=int(input()) a=list(map(int,input().split())) count=0 while max(a)!=0: p=min(a) q=a.index(p) for i in range(len(a)): if i==q: continue; else: a[i]=a[i]-1; count=count+1; print(count)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play. Output Specification: In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Demo Input: ['3\n3 2 2\n', '4\n2 2 2 2\n'] Demo Output: ['4\n', '3\n'] Note: You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
```python t=int(input()) a=list(map(int,input().split())) count=0 while max(a)!=0: p=min(a) q=a.index(p) for i in range(len(a)): if i==q: continue; else: a[i]=a[i]-1; count=count+1; print(count) ```
0
0
none
none
none
0
[ "none" ]
null
null
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one. Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given. Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly.
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower).
[ "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n" ]
[ "Yes\nYes\nYes\nNo\nNo\nYes\n" ]
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won. The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
0
[ { "input": "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000", "output": "Yes\nYes\nYes\nNo\nNo\nYes" }, { "input": "3\n1 1\n8 27\n1000 1331", "output": "Yes\nNo\nNo" }, { "input": "1\n12004 18012002", "output": "Yes" }, { "input": "1\n3331 11095561", "output": "Yes...
1,510,231,312
1,912
Python 3
WRONG_ANSWER
TESTS
1
77
0
def cube_root(x): l = 0 r = x while r-l > 1: mid = (l+r)//2; if mid*mid*mid >= x: r=mid; else: l = mid; return r t = int(input()) for t_ in range(t): a, b = input().split(" ") a = int(a) b=int(b) d = cube_root(a*b) if d*d*d == a*b: print("Yes") else: print("No")
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one. Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. Input Specification: In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given. Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly. Output Specification: For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). Demo Input: ['6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n'] Demo Output: ['Yes\nYes\nYes\nNo\nNo\nYes\n'] Note: First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won. The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
```python def cube_root(x): l = 0 r = x while r-l > 1: mid = (l+r)//2; if mid*mid*mid >= x: r=mid; else: l = mid; return r t = int(input()) for t_ in range(t): a, b = input().split(" ") a = int(a) b=int(b) d = cube_root(a*b) if d*d*d == a*b: print("Yes") else: print("No") ```
0
675
B
Restoring Painting
PROGRAMMING
1,400
[ "brute force", "constructive algorithms", "math" ]
null
null
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. - The painting is a square 3<=×<=3, each cell contains a single integer from 1 to *n*, and different cells may contain either different or equal integers. - The sum of integers in each of four squares 2<=×<=2 is equal to the sum of integers in the top left square 2<=×<=2. - Four elements *a*, *b*, *c* and *d* are known and are located as shown on the picture below. Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong. Two squares are considered to be different, if there exists a cell that contains two different integers in different squares.
The first line of the input contains five integers *n*, *a*, *b*, *c* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=*n*) — maximum possible value of an integer in the cell and four integers that Vasya remembers.
Print one integer — the number of distinct valid squares.
[ "2 1 1 1 2\n", "3 3 1 2 3\n" ]
[ "2\n", "6\n" ]
Below are all the possible paintings for the first sample. <img class="tex-graphics" src="https://espresso.codeforces.com/c4c53d4e7b6814d8aad7b72604b6089d61dadb48.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/46a6ad6a5d3db202f3779b045b9dc77fc2348cf1.png" style="max-width: 100.0%;max-height: 100.0%;"/> In the second sample, only paintings displayed below satisfy all the rules. <img class="tex-graphics" src="https://espresso.codeforces.com/776f231305f8ce7c33e79e887722ce46aa8b6e61.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/2fce9e9a31e70f1e46ea26f11d7305b3414e9b6b.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/be084a4d1f7e475be1183f7dff10e9c89eb175ef.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/96afdb4a35ac14f595d29bea2282f621098902f4.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/79ca8d720334a74910514f017ecf1d0166009a03.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/ad3c37e950bf5702d54f05756db35c831da59ad9.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "2 1 1 1 2", "output": "2" }, { "input": "3 3 1 2 3", "output": "6" }, { "input": "1 1 1 1 1", "output": "1" }, { "input": "1000 522 575 426 445", "output": "774000" }, { "input": "99000 52853 14347 64237 88869", "output": "1296306000" }, { ...
1,625,270,228
2,147,483,647
PyPy 3
OK
TESTS
58
124
1,433,600
n,a,b,c,d = map(int,input().split()) ans = 0 for i in range(1,n+1): p = i+b-c q = i+a+b-c-d r = i+a-d if 1<=p<=n and 1<=q<=n and 1<=r<=n: ans+=1 print(ans*n)
Title: Restoring Painting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. - The painting is a square 3<=×<=3, each cell contains a single integer from 1 to *n*, and different cells may contain either different or equal integers. - The sum of integers in each of four squares 2<=×<=2 is equal to the sum of integers in the top left square 2<=×<=2. - Four elements *a*, *b*, *c* and *d* are known and are located as shown on the picture below. Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong. Two squares are considered to be different, if there exists a cell that contains two different integers in different squares. Input Specification: The first line of the input contains five integers *n*, *a*, *b*, *c* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=*n*) — maximum possible value of an integer in the cell and four integers that Vasya remembers. Output Specification: Print one integer — the number of distinct valid squares. Demo Input: ['2 1 1 1 2\n', '3 3 1 2 3\n'] Demo Output: ['2\n', '6\n'] Note: Below are all the possible paintings for the first sample. <img class="tex-graphics" src="https://espresso.codeforces.com/c4c53d4e7b6814d8aad7b72604b6089d61dadb48.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/46a6ad6a5d3db202f3779b045b9dc77fc2348cf1.png" style="max-width: 100.0%;max-height: 100.0%;"/> In the second sample, only paintings displayed below satisfy all the rules. <img class="tex-graphics" src="https://espresso.codeforces.com/776f231305f8ce7c33e79e887722ce46aa8b6e61.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/2fce9e9a31e70f1e46ea26f11d7305b3414e9b6b.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/be084a4d1f7e475be1183f7dff10e9c89eb175ef.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/96afdb4a35ac14f595d29bea2282f621098902f4.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/79ca8d720334a74910514f017ecf1d0166009a03.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/ad3c37e950bf5702d54f05756db35c831da59ad9.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python n,a,b,c,d = map(int,input().split()) ans = 0 for i in range(1,n+1): p = i+b-c q = i+a+b-c-d r = i+a-d if 1<=p<=n and 1<=q<=n and 1<=r<=n: ans+=1 print(ans*n) ```
3
30
A
Accounting
PROGRAMMING
1,400
[ "brute force", "math" ]
A. Accounting
2
256
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there was a loss in the correspondent year). King wants to show financial stability. To do this, he needs to find common coefficient *X* — the coefficient of income growth during one year. This coefficient should satisfy the equation: Surely, the king is not going to do this job by himself, and demands you to find such number *X*. It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient *X* must be integers. The number *X* may be zero or negative.
The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10).
Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them.
[ "2 18 2\n", "-1 8 3\n", "0 0 10\n", "1 16 5\n" ]
[ "3", "-2", "5", "No solution" ]
none
500
[ { "input": "2 18 2", "output": "3" }, { "input": "-1 8 3", "output": "-2" }, { "input": "0 0 10", "output": "5" }, { "input": "1 16 5", "output": "No solution" }, { "input": "0 1 2", "output": "No solution" }, { "input": "3 0 4", "output": "0" },...
1,606,465,819
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
186
307,200
# seg=[0]*100005 # def build_query(ind,low,high): # if low==high: # seg[ind]=arr[low] # return # mid=low+(high-low)//2 # build_query(2*ind+1,low,mid) #left call # build_query(2*ind+2,mid+1,high) #right call # seg[ind]=min(seg[2*ind+1],seg[2*ind+2]) # def query(ind,low,high,l,r): # #Completely overlap # if low>=l and high<=r: # return seg[ind] # #No overlap # if high<l or low>r: # return 3636838 # #Partially overlap # mid=low+(high-low)//2 # left=query(2*ind+1,low,mid,l,r) # right=query(2*ind+2,mid+1,high,l,r) # return min(left,right) # # arr=[10,20,30,40,11,22,33,44,15,5] # n,m=map(int,input().split()) # arr=list(map(int,input().split())) # low=0 # high=len(arr)-1 # build_query(0,low,high) # # m=1 # # print("Enter your l and r values ") # while m: # l,r=map(int,input().split()) # ans=query(0,0,high,l,r) # print(ans) # m-=1 # import math # #Seive of erasthones # MAX_VALUE=1000001 # seive=[0]*MAX_VALUE # def seive_ers(seive): # i=3 # while i<MAX_VALUE: # seive[i]=1 # i+=2 # i=3 # while i<MAX_VALUE: # if seive[i]==1: # j=i*i # while j<MAX_VALUE: # seive[j]=0 # j+=i # i+=2 # seive[2]=1 # seive[1]=0 # seive[0]=0 def solve(): a,b,n=map(int,input().split()) if a==0 and b==0: print(n//2) return if a==0 or b==0: print("No solution") return sign=1 if a<0 or b<0: sign=-1 temp=1/n x=((abs(b)/abs(a))**temp) temp_str=str(x) temp_str=temp_str.split('.')[1] if int(temp_str)==0 and int(x)!=0: print(int(sign*x)) else: print("No solution") solve() # t=int(input()) # # seive_ers(seive) # while t: # solve() # t-=1 # # # # solve(
Title: Accounting Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there was a loss in the correspondent year). King wants to show financial stability. To do this, he needs to find common coefficient *X* — the coefficient of income growth during one year. This coefficient should satisfy the equation: Surely, the king is not going to do this job by himself, and demands you to find such number *X*. It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient *X* must be integers. The number *X* may be zero or negative. Input Specification: The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10). Output Specification: Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them. Demo Input: ['2 18 2\n', '-1 8 3\n', '0 0 10\n', '1 16 5\n'] Demo Output: ['3', '-2', '5', 'No solution'] Note: none
```python # seg=[0]*100005 # def build_query(ind,low,high): # if low==high: # seg[ind]=arr[low] # return # mid=low+(high-low)//2 # build_query(2*ind+1,low,mid) #left call # build_query(2*ind+2,mid+1,high) #right call # seg[ind]=min(seg[2*ind+1],seg[2*ind+2]) # def query(ind,low,high,l,r): # #Completely overlap # if low>=l and high<=r: # return seg[ind] # #No overlap # if high<l or low>r: # return 3636838 # #Partially overlap # mid=low+(high-low)//2 # left=query(2*ind+1,low,mid,l,r) # right=query(2*ind+2,mid+1,high,l,r) # return min(left,right) # # arr=[10,20,30,40,11,22,33,44,15,5] # n,m=map(int,input().split()) # arr=list(map(int,input().split())) # low=0 # high=len(arr)-1 # build_query(0,low,high) # # m=1 # # print("Enter your l and r values ") # while m: # l,r=map(int,input().split()) # ans=query(0,0,high,l,r) # print(ans) # m-=1 # import math # #Seive of erasthones # MAX_VALUE=1000001 # seive=[0]*MAX_VALUE # def seive_ers(seive): # i=3 # while i<MAX_VALUE: # seive[i]=1 # i+=2 # i=3 # while i<MAX_VALUE: # if seive[i]==1: # j=i*i # while j<MAX_VALUE: # seive[j]=0 # j+=i # i+=2 # seive[2]=1 # seive[1]=0 # seive[0]=0 def solve(): a,b,n=map(int,input().split()) if a==0 and b==0: print(n//2) return if a==0 or b==0: print("No solution") return sign=1 if a<0 or b<0: sign=-1 temp=1/n x=((abs(b)/abs(a))**temp) temp_str=str(x) temp_str=temp_str.split('.')[1] if int(temp_str)==0 and int(x)!=0: print(int(sign*x)) else: print("No solution") solve() # t=int(input()) # # seive_ers(seive) # while t: # solve() # t-=1 # # # # solve( ```
0
26
A
Almost Prime
PROGRAMMING
900
[ "number theory" ]
A. Almost Prime
2
256
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive.
Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000).
Output the amount of almost prime numbers between 1 and *n*, inclusive.
[ "10\n", "21\n" ]
[ "2\n", "8\n" ]
none
500
[ { "input": "10", "output": "2" }, { "input": "21", "output": "8" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "4", "output": "0" }, { "input": "3", "output": "0" }, { "input": "8", "output": "1" }, ...
1,637,848,213
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
11
2,000
0
a=int(input()) m=0 for i in range(2,a+1): n=0 for j in range(2,i+1): for x in range(2,j+1): if j%x==0: break if j==x and i%j==0: n=n+1 if n==2: m=m+1 print(m)
Title: Almost Prime Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. Input Specification: Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). Output Specification: Output the amount of almost prime numbers between 1 and *n*, inclusive. Demo Input: ['10\n', '21\n'] Demo Output: ['2\n', '8\n'] Note: none
```python a=int(input()) m=0 for i in range(2,a+1): n=0 for j in range(2,i+1): for x in range(2,j+1): if j%x==0: break if j==x and i%j==0: n=n+1 if n==2: m=m+1 print(m) ```
0
435
A
Queue on Bus Stop
PROGRAMMING
1,000
[ "implementation" ]
null
null
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups. The bus stop queue has *n* groups of people. The *i*-th group from the beginning has *a**i* people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most *m* people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue. Your task is to determine how many buses is needed to transport all *n* groups to the dacha countryside.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*m*).
Print a single integer — the number of buses that is needed to transport all *n* groups to the dacha countryside.
[ "4 3\n2 3 2 1\n", "3 4\n1 2 1\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "4 3\n2 3 2 1", "output": "3" }, { "input": "3 4\n1 2 1", "output": "1" }, { "input": "1 5\n4", "output": "1" }, { "input": "5 1\n1 1 1 1 1", "output": "5" }, { "input": "6 4\n1 3 2 3 4 1", "output": "5" }, { "input": "6 8\n6 1 1 1 4 5", ...
1,401,598,672
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
77
0
n, m = map(int, input().split()) a = list(map(int, input().split())) i, ans = 0, 0 while i < n: ans += 1 cap = a[i] while i < n - 1 and a[i] + a[i+1] <= m: i += 1 cap += a[i] i += 1 print(ans)
Title: Queue on Bus Stop Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups. The bus stop queue has *n* groups of people. The *i*-th group from the beginning has *a**i* people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most *m* people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue. Your task is to determine how many buses is needed to transport all *n* groups to the dacha countryside. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*m*). Output Specification: Print a single integer — the number of buses that is needed to transport all *n* groups to the dacha countryside. Demo Input: ['4 3\n2 3 2 1\n', '3 4\n1 2 1\n'] Demo Output: ['3\n', '1\n'] Note: none
```python n, m = map(int, input().split()) a = list(map(int, input().split())) i, ans = 0, 0 while i < n: ans += 1 cap = a[i] while i < n - 1 and a[i] + a[i+1] <= m: i += 1 cap += a[i] i += 1 print(ans) ```
0
630
C
Lucky Numbers
PROGRAMMING
1,100
[ "combinatorics", "math" ]
null
null
The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than *n* digits.
The only line of input contains one integer *n* (1<=≤<=*n*<=≤<=55) — the maximum length of a number that a door-plate can hold.
Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than *n* digits.
[ "2\n" ]
[ "6" ]
none
0
[ { "input": "2", "output": "6" }, { "input": "1", "output": "2" }, { "input": "3", "output": "14" }, { "input": "5", "output": "62" }, { "input": "12", "output": "8190" }, { "input": "34", "output": "34359738366" }, { "input": "43", "out...
1,690,716,342
2,147,483,647
PyPy 3-64
OK
TESTS
10
46
0
n = int(input()) print(sum(2**x for x in range(1,n+1)))
Title: Lucky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than *n* digits. Input Specification: The only line of input contains one integer *n* (1<=≤<=*n*<=≤<=55) — the maximum length of a number that a door-plate can hold. Output Specification: Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than *n* digits. Demo Input: ['2\n'] Demo Output: ['6'] Note: none
```python n = int(input()) print(sum(2**x for x in range(1,n+1))) ```
3
931
A
Friends Meeting
PROGRAMMING
800
[ "brute force", "greedy", "implementation", "math" ]
null
null
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*.
Print the minimum possible total tiredness if the friends meet in the same point.
[ "3\n4\n", "101\n99\n", "5\n10\n" ]
[ "1\n", "2\n", "9\n" ]
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9.
500
[ { "input": "3\n4", "output": "1" }, { "input": "101\n99", "output": "2" }, { "input": "5\n10", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n1000", "output": "250000" }, { "input": "999\n1000", "output": "1" }, { "inpu...
1,520,199,352
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
5,632,000
import math f = input() s = input() dis1 = 0 dis2 = 0 avg = (s+f) /2 dis1 = math.fabs(avg - f) dis2 = math.fabs(avg - s) print (dis1*(dis1+1))/2 + (dis2*(dis2+1))/2
Title: Friends Meeting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. Input Specification: The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*. Output Specification: Print the minimum possible total tiredness if the friends meet in the same point. Demo Input: ['3\n4\n', '101\n99\n', '5\n10\n'] Demo Output: ['1\n', '2\n', '9\n'] Note: In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9.
```python import math f = input() s = input() dis1 = 0 dis2 = 0 avg = (s+f) /2 dis1 = math.fabs(avg - f) dis2 = math.fabs(avg - s) print (dis1*(dis1+1))/2 + (dis2*(dis2+1))/2 ```
-1
993
A
Two Squares
PROGRAMMING
1,600
[ "geometry", "implementation" ]
null
null
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between $-100$ and $100$.
Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower).
[ "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1\n", "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1\n", "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples:
500
[ { "input": "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1", "output": "YES" }, { "input": "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1", "output": "NO" }, { "input": "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7", "output": "YES" }, { "input": "0 0 6 0 6 6 0 6\n8 4 4 8 8 12 12 8", "output": "YES" }, ...
1,529,746,935
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
text=input() l=text.split() a=[((int(l[i]),int(l[i+1]))) for i in range(0,7,2)] text2=input() l2=text2.split() b=[((int(l[i]),int(l[i+1]))) for i in range(0,7,2)] def inside(a,b): for i in range (3): if b[i][0]>=a[0][0] and b[i][0]<=a[1][0] and b[i][1]>=a[0][0] and b[i][1] <=a[3][1]:return True return False if inside (a,b): print('yes') else: print('no')
Title: Two Squares Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input Specification: The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between $-100$ and $100$. Output Specification: Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Demo Input: ['0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1\n', '0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1\n', '6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples:
```python text=input() l=text.split() a=[((int(l[i]),int(l[i+1]))) for i in range(0,7,2)] text2=input() l2=text2.split() b=[((int(l[i]),int(l[i+1]))) for i in range(0,7,2)] def inside(a,b): for i in range (3): if b[i][0]>=a[0][0] and b[i][0]<=a[1][0] and b[i][1]>=a[0][0] and b[i][1] <=a[3][1]:return True return False if inside (a,b): print('yes') else: print('no') ```
0
1,005
B
Delete from the Left
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "". You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings. Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal.
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
[ "test\nwest\n", "codeforces\nyes\n", "test\nyes\n", "b\nab\n" ]
[ "2\n", "9\n", "7\n", "1\n" ]
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es". In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty. In the fourth example, the first character of the second string should be deleted.
0
[ { "input": "test\nwest", "output": "2" }, { "input": "codeforces\nyes", "output": "9" }, { "input": "test\nyes", "output": "7" }, { "input": "b\nab", "output": "1" }, { "input": "z\nz", "output": "0" }, { "input": "abacabadabacaba\nabacabadacaba", ...
1,693,768,226
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
921,600
word_1, word_2 = input(), input() total = 0 while word_1 != "": if len(word_1) != len(word_2): if len(word_1) > len(word_2): word_1 = word_1[1:] total += 1 if len(word_2) > len(word_1): word_2 = word_2[1:] total += 1 else: if word_1 == word_2 : break else: word_1, word_2 = word_1[1:], word_2[1:] total += 2 print(total) # Sun Sep 03 2023 22:10:26 GMT+0300 (Moscow Standard Time)
Title: Delete from the Left Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "". You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings. Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal. Input Specification: The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. Output Specification: Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. Demo Input: ['test\nwest\n', 'codeforces\nyes\n', 'test\nyes\n', 'b\nab\n'] Demo Output: ['2\n', '9\n', '7\n', '1\n'] Note: In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es". In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty. In the fourth example, the first character of the second string should be deleted.
```python word_1, word_2 = input(), input() total = 0 while word_1 != "": if len(word_1) != len(word_2): if len(word_1) > len(word_2): word_1 = word_1[1:] total += 1 if len(word_2) > len(word_1): word_2 = word_2[1:] total += 1 else: if word_1 == word_2 : break else: word_1, word_2 = word_1[1:], word_2[1:] total += 2 print(total) # Sun Sep 03 2023 22:10:26 GMT+0300 (Moscow Standard Time) ```
0
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "1000022...
1,631,444,183
2,147,483,647
Python 3
OK
TESTS
30
124
6,963,200
s=input() i=0 for j in range(len(s)): if i>=len(s): break else: if s[i]=='-'and s[i+1]=='.': i+=2 print('1',end='') elif s[i]=='-'and s[i+1]=='-': i+=2 print("2",end='') elif s[i]=='.': i+=1 print('0',end='')
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. Input Specification: The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). Output Specification: Output the decoded ternary number. It can have leading zeroes. Demo Input: ['.-.--\n', '--.\n', '-..-.--\n'] Demo Output: ['012', '20', '1012'] Note: none
```python s=input() i=0 for j in range(len(s)): if i>=len(s): break else: if s[i]=='-'and s[i+1]=='.': i+=2 print('1',end='') elif s[i]=='-'and s[i+1]=='-': i+=2 print("2",end='') elif s[i]=='.': i+=1 print('0',end='') ```
3.95603
792
E
Colored Balls
PROGRAMMING
2,500
[ "greedy", "math", "number theory" ]
null
null
There are *n* boxes with colored balls on the table. Colors are numbered from 1 to *n*. *i*-th box contains *a**i* balls, all of which have color *i*. You have to write a program that will divide all balls into sets such that: - each ball belongs to exactly one of the sets, - there are no empty sets, - there is no set containing two (or more) balls of different colors (each set contains only balls of one color), - there are no two sets such that the difference between their sizes is greater than 1. Print the minimum possible number of sets.
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=500). The second line contains *n* integer numbers *a*1,<=*a*2,<=... ,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print one integer number — the minimum possible number of sets.
[ "3\n4 7 8\n", "2\n2 7\n" ]
[ "5\n", "4\n" ]
In the first example the balls can be divided into sets like that: one set with 4 balls of the first color, two sets with 3 and 4 balls, respectively, of the second color, and two sets with 4 balls of the third color.
0
[ { "input": "3\n4 7 8", "output": "5" }, { "input": "2\n2 7", "output": "4" }, { "input": "1\n1", "output": "1" }, { "input": "1\n1000000000", "output": "1" }, { "input": "2\n1000000000 1", "output": "500000001" }, { "input": "2\n9 6", "output": "5"...
1,600,183,749
7,149
PyPy 3
WRONG_ANSWER
TESTS
2
140
409,600
import sys from math import sqrt from collections import Counter n = int(input()) a = list(map(int, input().split())) cnt = Counter() for x in a: sq = int(sqrt(x))+1 for d in range(2, sq): if x // d > x % d: cnt[d, d+1] += 1 d = sq while d <= x: mod = x % d if mod >= d: d += mod // d assert d > x % d cnt[d, d+1] += 1 d += 1 for key in sorted(cnt.keys(), reverse=True): if cnt[key] == n: ans = 0 d = key[1] for x in a: ans += (x+d-1) // d print(ans) break
Title: Colored Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* boxes with colored balls on the table. Colors are numbered from 1 to *n*. *i*-th box contains *a**i* balls, all of which have color *i*. You have to write a program that will divide all balls into sets such that: - each ball belongs to exactly one of the sets, - there are no empty sets, - there is no set containing two (or more) balls of different colors (each set contains only balls of one color), - there are no two sets such that the difference between their sizes is greater than 1. Print the minimum possible number of sets. Input Specification: The first line contains one integer number *n* (1<=≤<=*n*<=≤<=500). The second line contains *n* integer numbers *a*1,<=*a*2,<=... ,<=*a**n* (1<=≤<=*a**i*<=≤<=109). Output Specification: Print one integer number — the minimum possible number of sets. Demo Input: ['3\n4 7 8\n', '2\n2 7\n'] Demo Output: ['5\n', '4\n'] Note: In the first example the balls can be divided into sets like that: one set with 4 balls of the first color, two sets with 3 and 4 balls, respectively, of the second color, and two sets with 4 balls of the third color.
```python import sys from math import sqrt from collections import Counter n = int(input()) a = list(map(int, input().split())) cnt = Counter() for x in a: sq = int(sqrt(x))+1 for d in range(2, sq): if x // d > x % d: cnt[d, d+1] += 1 d = sq while d <= x: mod = x % d if mod >= d: d += mod // d assert d > x % d cnt[d, d+1] += 1 d += 1 for key in sorted(cnt.keys(), reverse=True): if cnt[key] == n: ans = 0 d = key[1] for x in a: ans += (x+d-1) // d print(ans) break ```
0
17
A
Noldbach problem
PROGRAMMING
1,000
[ "brute force", "math", "number theory" ]
A. Noldbach problem
2
64
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least *k* prime numbers from 2 to *n* inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1. Two prime numbers are called neighboring if there are no other prime numbers between them. You are to help Nick, and find out if he is right or wrong.
The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000).
Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO.
[ "27 2\n", "45 7\n" ]
[ "YES", "NO" ]
In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.
0
[ { "input": "27 2", "output": "YES" }, { "input": "45 7", "output": "NO" }, { "input": "2 0", "output": "YES" }, { "input": "15 1", "output": "YES" }, { "input": "17 1", "output": "YES" }, { "input": "34 5", "output": "NO" }, { "input": "37 ...
1,683,724,149
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
92
0
from sys import stdin def get_input(): input_str = stdin.read().strip().split(' ') n, k = input_str return int(n), int(k) def is_possible(n, k): is_prime = [True] * (n + 1) for i in range(2, n + 1): if is_prime[i]: for j in range(i * i, n + 1, i): is_prime[j] = False primes = [i for i in range(2, n + 1) if is_prime[i]] for prime in primes: if k == 0: return 'YES' for i in range(len(primes) - 1): if primes[i] + primes[i + 1] == prime - 1: k -= 1 break return 'NO' print(is_possible(*get_input()))
Title: Noldbach problem Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least *k* prime numbers from 2 to *n* inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1. Two prime numbers are called neighboring if there are no other prime numbers between them. You are to help Nick, and find out if he is right or wrong. Input Specification: The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000). Output Specification: Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO. Demo Input: ['27 2\n', '45 7\n'] Demo Output: ['YES', 'NO'] Note: In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.
```python from sys import stdin def get_input(): input_str = stdin.read().strip().split(' ') n, k = input_str return int(n), int(k) def is_possible(n, k): is_prime = [True] * (n + 1) for i in range(2, n + 1): if is_prime[i]: for j in range(i * i, n + 1, i): is_prime[j] = False primes = [i for i in range(2, n + 1) if is_prime[i]] for prime in primes: if k == 0: return 'YES' for i in range(len(primes) - 1): if primes[i] + primes[i + 1] == prime - 1: k -= 1 break return 'NO' print(is_possible(*get_input())) ```
0
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", ...
1,696,237,704
2,147,483,647
Python 3
OK
TESTS
34
92
0
n = int(input()) team1, team2, score1, score2 = '', '', 0, 0 for i in range(n): team = input() if team1 == '': team1 = team score1 = 1 elif team == team1: score1 += 1 elif team2 == '': team2 = team score2 = 1 else: score2 += 1 print(team1 if score1 > score2 else team2)
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. Output Specification: Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. Demo Input: ['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n'] Demo Output: ['ABC\n', 'A\n'] Note: none
```python n = int(input()) team1, team2, score1, score2 = '', '', 0, 0 for i in range(n): team = input() if team1 == '': team1 = team score1 = 1 elif team == team1: score1 += 1 elif team2 == '': team2 = team score2 = 1 else: score2 += 1 print(team1 if score1 > score2 else team2) ```
3.977
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 calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
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,590,124,952
2,147,483,647
PyPy 3
OK
TESTS
102
233
2,150,400
import string n1 = str(input()) n2 = str(input()) a = "" for i in range(len(n1)): if n1[i] != n2[i]: a += "1" else: a += "0" print(a)
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 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: 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. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python import string n1 = str(input()) n2 = str(input()) a = "" for i in range(len(n1)): if n1[i] != n2[i]: a += "1" else: a += "0" print(a) ```
3.937745
577
A
Multiplication Table
PROGRAMMING
1,000
[ "implementation", "number theory" ]
null
null
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1. You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*.
The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table.
Print a single number: the number of times *x* occurs in the table.
[ "10 5\n", "6 12\n", "5 13\n" ]
[ "2\n", "4\n", "0\n" ]
A table for the second sample test is given below. The occurrences of number 12 are marked bold.
500
[ { "input": "10 5", "output": "2" }, { "input": "6 12", "output": "4" }, { "input": "5 13", "output": "0" }, { "input": "1 1", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "100000 1", "output": "1" }, { "input": "1 10000000...
1,665,400,459
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
170,393,600
n,x = map(int,input().split()) num = 0 numbers = [] for i in range(1,n+1): for j in range(1,n+1): numbers.append(i*j) print(numbers.count(x))
Title: Multiplication Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1. You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*. Input Specification: The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. Output Specification: Print a single number: the number of times *x* occurs in the table. Demo Input: ['10 5\n', '6 12\n', '5 13\n'] Demo Output: ['2\n', '4\n', '0\n'] Note: A table for the second sample test is given below. The occurrences of number 12 are marked bold.
```python n,x = map(int,input().split()) num = 0 numbers = [] for i in range(1,n+1): for j in range(1,n+1): numbers.append(i*j) print(numbers.count(x)) ```
0
379
A
New Year Candles
PROGRAMMING
1,000
[ "implementation" ]
null
null
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle. Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000).
Print a single integer — the number of hours Vasily can light up the room for.
[ "4 2\n", "6 3\n" ]
[ "7\n", "8\n" ]
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.
500
[ { "input": "4 2", "output": "7" }, { "input": "6 3", "output": "8" }, { "input": "1000 1000", "output": "1001" }, { "input": "123 5", "output": "153" }, { "input": "1000 2", "output": "1999" }, { "input": "1 2", "output": "1" }, { "input": ...
1,690,890,520
2,147,483,647
Python 3
OK
TESTS
32
46
0
n,m = map(int,input().split()) s = 0 a = n b = 0 while True: s += a if a+b<m: break a = (a+b)//m b = s%m print(s)
Title: New Year Candles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle. Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number. Input Specification: The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). Output Specification: Print a single integer — the number of hours Vasily can light up the room for. Demo Input: ['4 2\n', '6 3\n'] Demo Output: ['7\n', '8\n'] Note: Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.
```python n,m = map(int,input().split()) s = 0 a = n b = 0 while True: s += a if a+b<m: break a = (a+b)//m b = s%m print(s) ```
3
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink.
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39...
1,688,297,921
2,147,483,647
Python 3
OK
TESTS
31
92
0
n=int(input()) f=list(map(int, input().split())) tf=sum(f) af=tf/n print(af)
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink. Input Specification: The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. Output Specification: Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. Demo Input: ['3\n50 50 100\n', '4\n0 25 50 75\n'] Demo Output: ['66.666666666667\n', '37.500000000000\n'] Note: Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
```python n=int(input()) f=list(map(int, input().split())) tf=sum(f) af=tf/n print(af) ```
3
316
A2
Special Task
PROGRAMMING
1,400
[ "math" ]
null
null
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there. The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe. And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string *s* with the following structure: - if *s**i* = "?", then the digit that goes *i*-th in the safe code can be anything (between 0 to 9, inclusively); - if *s**i* is a digit (between 0 to 9, inclusively), then it means that there is digit *s**i* on position *i* in code; - if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits. - The length of the safe code coincides with the length of the hint. For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666". After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint. At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
The first line contains string *s* — the hint to the safe code. String *s* consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string *s* doesn't equal to character 0. The input limits for scoring 30 points are (subproblem A1): - 1<=≤<=|*s*|<=≤<=5. The input limits for scoring 100 points are (subproblems A1+A2): - 1<=≤<=|*s*|<=≤<=105. Here |*s*| means the length of string *s*.
Print the number of codes that match the given hint.
[ "AJ\n", "1?AA\n" ]
[ "81\n", "100\n" ]
none
70
[ { "input": "AJ", "output": "81" }, { "input": "1?AA", "output": "100" }, { "input": "?", "output": "9" }, { "input": "7", "output": "1" }, { "input": "A", "output": "9" }, { "input": "BBB?", "output": "90" }, { "input": "BC??", "output"...
1,589,636,833
2,147,483,647
Python 3
WRONG_ANSWER
TESTS2
0
186
6,860,800
u=input() u=list(set(u)) v=1 k=0 for i in range(len(u)): if i=='0': if u[i]=='?': v*=9 if ord(u[i])>64 and ord(u[i])<75: v*=9 if ord(u[i])>74 and ord(u[i])<91: k+=1 else: if u[i]=='?': v*=10 if ord(u[i])>74 and ord(u[i])<91: k+=1 if ord(u[i])>64 and ord(u[i])<75: v*=10 g=9 for i in range(k): v*=g if g>0: g-=1 else: break print(v)
Title: Special Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there. The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe. And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string *s* with the following structure: - if *s**i* = "?", then the digit that goes *i*-th in the safe code can be anything (between 0 to 9, inclusively); - if *s**i* is a digit (between 0 to 9, inclusively), then it means that there is digit *s**i* on position *i* in code; - if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits. - The length of the safe code coincides with the length of the hint. For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666". After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint. At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night... Input Specification: The first line contains string *s* — the hint to the safe code. String *s* consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string *s* doesn't equal to character 0. The input limits for scoring 30 points are (subproblem A1): - 1<=≤<=|*s*|<=≤<=5. The input limits for scoring 100 points are (subproblems A1+A2): - 1<=≤<=|*s*|<=≤<=105. Here |*s*| means the length of string *s*. Output Specification: Print the number of codes that match the given hint. Demo Input: ['AJ\n', '1?AA\n'] Demo Output: ['81\n', '100\n'] Note: none
```python u=input() u=list(set(u)) v=1 k=0 for i in range(len(u)): if i=='0': if u[i]=='?': v*=9 if ord(u[i])>64 and ord(u[i])<75: v*=9 if ord(u[i])>74 and ord(u[i])<91: k+=1 else: if u[i]=='?': v*=10 if ord(u[i])>74 and ord(u[i])<91: k+=1 if ord(u[i])>64 and ord(u[i])<75: v*=10 g=9 for i in range(k): v*=g if g>0: g-=1 else: break print(v) ```
0
743
A
Vladik and flights
PROGRAMMING
1,200
[ "constructive algorithms", "greedy", "implementation" ]
null
null
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad. Vladik knows *n* airports. All the airports are located on a straight line. Each airport has unique id from 1 to *n*, Vladik's house is situated next to the airport with id *a*, and the place of the olympiad is situated next to the airport with id *b*. It is possible that Vladik's house and the place of the olympiad are located near the same airport. To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport *a* and finish it at the airport *b*. Each airport belongs to one of two companies. The cost of flight from the airport *i* to the airport *j* is zero if both airports belong to the same company, and |*i*<=-<=*j*| if they belong to different companies. Print the minimum cost Vladik has to pay to get to the olympiad.
The first line contains three integers *n*, *a*, and *b* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach. The second line contains a string with length *n*, which consists only of characters 0 and 1. If the *i*-th character in this string is 0, then *i*-th airport belongs to first company, otherwise it belongs to the second.
Print single integer — the minimum cost Vladik has to pay to get to the olympiad.
[ "4 1 4\n1010\n", "5 5 2\n10110\n" ]
[ "1", "0" ]
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1. In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
500
[ { "input": "4 1 4\n1010", "output": "1" }, { "input": "5 5 2\n10110", "output": "0" }, { "input": "10 9 5\n1011111001", "output": "1" }, { "input": "7 3 7\n1110111", "output": "0" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "10 3 3\n100101101...
1,481,758,778
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
n,a,b=map(int,input().split()) a-=1 b-=1 F=input() A=[int(F[i]) for i in range(len(F))] ans=0 if F[a]!=F[b]: ans=F[min(a,b):].index(F[max(a,b)]) print(ans)
Title: Vladik and flights Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad. Vladik knows *n* airports. All the airports are located on a straight line. Each airport has unique id from 1 to *n*, Vladik's house is situated next to the airport with id *a*, and the place of the olympiad is situated next to the airport with id *b*. It is possible that Vladik's house and the place of the olympiad are located near the same airport. To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport *a* and finish it at the airport *b*. Each airport belongs to one of two companies. The cost of flight from the airport *i* to the airport *j* is zero if both airports belong to the same company, and |*i*<=-<=*j*| if they belong to different companies. Print the minimum cost Vladik has to pay to get to the olympiad. Input Specification: The first line contains three integers *n*, *a*, and *b* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach. The second line contains a string with length *n*, which consists only of characters 0 and 1. If the *i*-th character in this string is 0, then *i*-th airport belongs to first company, otherwise it belongs to the second. Output Specification: Print single integer — the minimum cost Vladik has to pay to get to the olympiad. Demo Input: ['4 1 4\n1010\n', '5 5 2\n10110\n'] Demo Output: ['1', '0'] Note: In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1. In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
```python n,a,b=map(int,input().split()) a-=1 b-=1 F=input() A=[int(F[i]) for i in range(len(F))] ans=0 if F[a]!=F[b]: ans=F[min(a,b):].index(F[max(a,b)]) print(ans) ```
0
456
A
Laptops
PROGRAMMING
1,100
[ "sortings" ]
null
null
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop. Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality). All *a**i* are distinct. All *b**i* are distinct.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
[ "2\n1 2\n2 1\n" ]
[ "Happy Alex\n" ]
none
500
[ { "input": "2\n1 2\n2 1", "output": "Happy Alex" }, { "input": "2\n1 1\n2 2", "output": "Poor Alex" }, { "input": "3\n2 2\n3 3\n1 1", "output": "Poor Alex" }, { "input": "3\n3 3\n1 2\n2 1", "output": "Happy Alex" }, { "input": "1\n1 1", "output": "Poor Alex" ...
1,684,992,913
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
171
8,192,000
class Data: def __init__(self, p, q): self.p = p self.q = q class Different(Exception): def __init__(self, *args: object) -> None: super().__init__(*args) pass def same(x, y): for i in range(len(x)): if x[i].p == y[i].p: if x[i].q == y[i].q: pass else: raise Different return times = int(input()) price = [] quality = [] for i in range(times): info = input() temp = info.split(" ") price.append(Data(temp[0], temp[1])) quality = price.copy() price.sort(key=lambda x: x.p) quality.sort(key=lambda x: x.q, reverse=True) try: same(price, quality) print("Happy Alex") except Different: print("Poor Alex")
Title: Laptops Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop. Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality). All *a**i* are distinct. All *b**i* are distinct. Output Specification: If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). Demo Input: ['2\n1 2\n2 1\n'] Demo Output: ['Happy Alex\n'] Note: none
```python class Data: def __init__(self, p, q): self.p = p self.q = q class Different(Exception): def __init__(self, *args: object) -> None: super().__init__(*args) pass def same(x, y): for i in range(len(x)): if x[i].p == y[i].p: if x[i].q == y[i].q: pass else: raise Different return times = int(input()) price = [] quality = [] for i in range(times): info = input() temp = info.split(" ") price.append(Data(temp[0], temp[1])) quality = price.copy() price.sort(key=lambda x: x.p) quality.sort(key=lambda x: x.q, reverse=True) try: same(price, quality) print("Happy Alex") except Different: print("Poor Alex") ```
0
447
B
DZY Loves Strings
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103). The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103). The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000.
Print a single integer — the largest possible value of the resulting string DZY could get.
[ "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n" ]
[ "41\n" ]
In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
1,000
[ { "input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "41" }, { "input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453", "output": "29978" }, { "input": "ajeeseerqnpaujubmajpibxrccazaawetyw...
1,585,425,649
2,147,483,647
PyPy 3
OK
TESTS
24
155
1,331,200
s=input() x=int(input()) a=list(map(int,input().split())) s=s+chr(97+a.index(max(a)))*x p=0 for i in range(1,len(s)+1): p=p+i*a[ord(s[i-1])-97] print(p)
Title: DZY Loves Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get? Input Specification: The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103). The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103). The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. Output Specification: Print a single integer — the largest possible value of the resulting string DZY could get. Demo Input: ['abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n'] Demo Output: ['41\n'] Note: In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
```python s=input() x=int(input()) a=list(map(int,input().split())) s=s+chr(97+a.index(max(a)))*x p=0 for i in range(1,len(s)+1): p=p+i*a[ord(s[i-1])-97] print(p) ```
3
155
A
I_love_\%username\%
PROGRAMMING
800
[ "brute force" ]
null
null
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
[ "5\n100 50 200 150 200\n", "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n" ]
[ "2\n", "4\n" ]
In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
500
[ { "input": "5\n100 50 200 150 200", "output": "2" }, { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242", "output": "4" }, { "input": "1\n6", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "5\n100 36 53 7 81", "output": "2" ...
1,673,912,279
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
0
n=int(input()) a=list(map(int,input().split()));sm=0;mx=a[0];mn=a[0] for i in range(len(a)): if(a[i]>mx): sm+=1 mx=a[i] elif(a[i]<mn): sm+=1 mx=a[i] print(sm)
Title: I_love_\%username\% Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input Specification: The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Specification: Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. Demo Input: ['5\n100 50 200 150 200\n', '10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n'] Demo Output: ['2\n', '4\n'] Note: In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
```python n=int(input()) a=list(map(int,input().split()));sm=0;mx=a[0];mn=a[0] for i in range(len(a)): if(a[i]>mx): sm+=1 mx=a[i] elif(a[i]<mn): sm+=1 mx=a[i] print(sm) ```
0
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 Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
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,692,526,570
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
0
a = int(input()) print("YES" if a % 2 == 0 or a // 2 != 1 else "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, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. Input Specification: The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. Output Specification: 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. Demo Input: ['8\n'] Demo Output: ['YES\n'] Note: 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).
```python a = int(input()) print("YES" if a % 2 == 0 or a // 2 != 1 else "NO") ```
0
703
A
Mishka and Game
PROGRAMMING
800
[ "implementation" ]
null
null
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds. The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively.
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
[ "3\n3 5\n2 1\n4 2\n", "2\n6 1\n1 6\n", "3\n1 5\n3 3\n2 2\n" ]
[ "Mishka", "Friendship is magic!^^", "Chris" ]
In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
500
[ { "input": "3\n3 5\n2 1\n4 2", "output": "Mishka" }, { "input": "2\n6 1\n1 6", "output": "Friendship is magic!^^" }, { "input": "3\n1 5\n3 3\n2 2", "output": "Chris" }, { "input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1", "output": "Mishka" }, { "input": "8\n2 4\n1 4\n1 ...
1,668,076,894
2,147,483,647
PyPy 3
OK
TESTS
69
78
0
m = 0 c = 0 for _ in range(int(input())): x, y = [int(x) for x in input().split()] if x > y: m = m + 2 elif x < y: c = c + 2 elif x == y: m = m + 1 c = c + 1 if m > c: print("Mishka") elif m < c: print("Chris") elif m == c: print("Friendship is magic!^^")
Title: Mishka and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input Specification: The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds. The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively. Output Specification: If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Demo Input: ['3\n3 5\n2 1\n4 2\n', '2\n6 1\n1 6\n', '3\n1 5\n3 3\n2 2\n'] Demo Output: ['Mishka', 'Friendship is magic!^^', 'Chris'] Note: In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
```python m = 0 c = 0 for _ in range(int(input())): x, y = [int(x) for x in input().split()] if x > y: m = m + 2 elif x < y: c = c + 2 elif x == y: m = m + 1 c = c + 1 if m > c: print("Mishka") elif m < c: print("Chris") elif m == c: print("Friendship is magic!^^") ```
3
118
A
String Task
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string. Help Petya cope with this easy task.
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
Print the resulting string. It is guaranteed that this string is not empty.
[ "tour\n", "Codeforces\n", "aBAcAba\n" ]
[ ".t.r\n", ".c.d.f.r.c.s\n", ".b.c.b\n" ]
none
500
[ { "input": "tour", "output": ".t.r" }, { "input": "Codeforces", "output": ".c.d.f.r.c.s" }, { "input": "aBAcAba", "output": ".b.c.b" }, { "input": "obn", "output": ".b.n" }, { "input": "wpwl", "output": ".w.p.w.l" }, { "input": "ggdvq", "output": "...
1,694,021,764
2,147,483,647
Python 3
OK
TESTS
42
92
0
l = ['a', 'e', 'i', 'o', 'u', 'y'] L = ["A", "E", "I", "O", "U", "Y"] n = input() string = "" for i in n: if i not in (l + L): if i.isupper(): string += '.' + i.lower() else: string += '.' + i print(string)
Title: String Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string. Help Petya cope with this easy task. Input Specification: The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. Output Specification: Print the resulting string. It is guaranteed that this string is not empty. Demo Input: ['tour\n', 'Codeforces\n', 'aBAcAba\n'] Demo Output: ['.t.r\n', '.c.d.f.r.c.s\n', '.b.c.b\n'] Note: none
```python l = ['a', 'e', 'i', 'o', 'u', 'y'] L = ["A", "E", "I", "O", "U", "Y"] n = input() string = "" for i in n: if i not in (l + L): if i.isupper(): string += '.' + i.lower() else: string += '.' + i print(string) ```
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
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,620,214,669
2,147,483,647
Python 3
OK
TESTS
35
124
0
x,y = [int(x) for x in input().split()] c = x*y//2 print(c)
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 possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python x,y = [int(x) for x in input().split()] c = x*y//2 print(c) ```
3.969
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 Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
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,696,453,207
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
w= int(input()) if (w mod 2) and (w!2): return "YES" return"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, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. Input Specification: The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. Output Specification: 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. Demo Input: ['8\n'] Demo Output: ['YES\n'] Note: 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).
```python w= int(input()) if (w mod 2) and (w!2): return "YES" return"NO" ```
-1
577
A
Multiplication Table
PROGRAMMING
1,000
[ "implementation", "number theory" ]
null
null
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1. You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*.
The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table.
Print a single number: the number of times *x* occurs in the table.
[ "10 5\n", "6 12\n", "5 13\n" ]
[ "2\n", "4\n", "0\n" ]
A table for the second sample test is given below. The occurrences of number 12 are marked bold.
500
[ { "input": "10 5", "output": "2" }, { "input": "6 12", "output": "4" }, { "input": "5 13", "output": "0" }, { "input": "1 1", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "100000 1", "output": "1" }, { "input": "1 10000000...
1,677,323,411
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
1,000
107,827,200
import math # n table contions x ,prime factors of x def helper(n,x): prime=[[1] for i in range(0,x+1)] for i in range(2,int(math.sqrt(x))+1): if len(prime[i])==1: for j in range(i*i,x+1,i): prime[j].append(i) count=0 # print(prime[x]) for f in prime[x]: if f in range(1,n+1) and x/f in range(1,n+1): # print(f,x/f) if f==x/f: count+=1 else: count+=2 return count n,x=list(map(int,input().split())) print(helper(n,x))
Title: Multiplication Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1. You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*. Input Specification: The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. Output Specification: Print a single number: the number of times *x* occurs in the table. Demo Input: ['10 5\n', '6 12\n', '5 13\n'] Demo Output: ['2\n', '4\n', '0\n'] Note: A table for the second sample test is given below. The occurrences of number 12 are marked bold.
```python import math # n table contions x ,prime factors of x def helper(n,x): prime=[[1] for i in range(0,x+1)] for i in range(2,int(math.sqrt(x))+1): if len(prime[i])==1: for j in range(i*i,x+1,i): prime[j].append(i) count=0 # print(prime[x]) for f in prime[x]: if f in range(1,n+1) and x/f in range(1,n+1): # print(f,x/f) if f==x/f: count+=1 else: count+=2 return count n,x=list(map(int,input().split())) print(helper(n,x)) ```
0
632
A
Grandma Laura and Apples
PROGRAMMING
1,200
[]
null
null
Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market. She precisely remembers she had *n* buyers and each of them bought exactly half of the apples she had at the moment of the purchase and also she gave a half of an apple to some of them as a gift (if the number of apples at the moment of purchase was odd), until she sold all the apples she had. So each buyer took some integral positive number of apples, but maybe he didn't pay for a half of an apple (if the number of apples at the moment of the purchase was odd). For each buyer grandma remembers if she gave a half of an apple as a gift or not. The cost of an apple is *p* (the number *p* is even). Print the total money grandma should have at the end of the day to check if some buyers cheated her.
The first line contains two integers *n* and *p* (1<=≤<=*n*<=≤<=40,<=2<=≤<=*p*<=≤<=1000) — the number of the buyers and the cost of one apple. It is guaranteed that the number *p* is even. The next *n* lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of the apples and with the string halfplus if grandma also gave him a half of an apple as a gift. It is guaranteed that grandma has at least one apple at the start of the day and she has no apples at the end of the day.
Print the only integer *a* — the total money grandma should have at the end of the day. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
[ "2 10\nhalf\nhalfplus\n", "3 10\nhalfplus\nhalfplus\nhalfplus\n" ]
[ "15\n", "55\n" ]
In the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer.
0
[ { "input": "2 10\nhalf\nhalfplus", "output": "15" }, { "input": "3 10\nhalfplus\nhalfplus\nhalfplus", "output": "55" }, { "input": "10 328\nhalf\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalf\nhalf\nhalfplus\nhalfplus", "output": "258300" }, { "input": "1 2\nhalfplus", "...
1,630,177,620
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
93
20,172,800
import sys input = sys.stdin.readline n, p = map(int, input().split()) s = [input().rstrip() for _ in range(n)] s.pop() ans = p // 2 now = 2 while s: ans += now * p // 2 now *= 2 if s.pop() == "halfplus": now *= 2 print(ans)
Title: Grandma Laura and Apples Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market. She precisely remembers she had *n* buyers and each of them bought exactly half of the apples she had at the moment of the purchase and also she gave a half of an apple to some of them as a gift (if the number of apples at the moment of purchase was odd), until she sold all the apples she had. So each buyer took some integral positive number of apples, but maybe he didn't pay for a half of an apple (if the number of apples at the moment of the purchase was odd). For each buyer grandma remembers if she gave a half of an apple as a gift or not. The cost of an apple is *p* (the number *p* is even). Print the total money grandma should have at the end of the day to check if some buyers cheated her. Input Specification: The first line contains two integers *n* and *p* (1<=≤<=*n*<=≤<=40,<=2<=≤<=*p*<=≤<=1000) — the number of the buyers and the cost of one apple. It is guaranteed that the number *p* is even. The next *n* lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of the apples and with the string halfplus if grandma also gave him a half of an apple as a gift. It is guaranteed that grandma has at least one apple at the start of the day and she has no apples at the end of the day. Output Specification: Print the only integer *a* — the total money grandma should have at the end of the day. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Demo Input: ['2 10\nhalf\nhalfplus\n', '3 10\nhalfplus\nhalfplus\nhalfplus\n'] Demo Output: ['15\n', '55\n'] Note: In the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer.
```python import sys input = sys.stdin.readline n, p = map(int, input().split()) s = [input().rstrip() for _ in range(n)] s.pop() ans = p // 2 now = 2 while s: ans += now * p // 2 now *= 2 if s.pop() == "halfplus": now *= 2 print(ans) ```
0
698
A
Vacations
PROGRAMMING
1,400
[ "dp" ]
null
null
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out.
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days.
[ "4\n1 3 2 0\n", "7\n1 3 3 2 1 2 3\n", "2\n2 2\n" ]
[ "2\n", "0\n", "1\n" ]
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
500
[ { "input": "4\n1 3 2 0", "output": "2" }, { "input": "7\n1 3 3 2 1 2 3", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "1\n0", "output": "1" }, { "input": "10\n0 0 1 1 0 0 0 0 1 0", "output": "8" }, { "input": "100\n3 2 3 3 3 2 3 1 ...
1,696,659,751
2,147,483,647
Python 3
OK
TESTS
88
46
0
a=int(input()) s=input() A=[0,0,0] for i in range(0,2*a-1,2): b=int(s[i]) if b==0:A=[max(A),0,0] elif b==1:A=[max(A),max(A[0],A[2])+1,0] elif b==2:A=[max(A),0,max(A[0],A[1])+1] else:A=[max(A),max(A[0],A[2])+1,max(A[0],A[1])+1] print(a-max(A))
Title: Vacations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out. Output Specification: Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days. Demo Input: ['4\n1 3 2 0\n', '7\n1 3 3 2 1 2 3\n', '2\n2 2\n'] Demo Output: ['2\n', '0\n', '1\n'] Note: In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
```python a=int(input()) s=input() A=[0,0,0] for i in range(0,2*a-1,2): b=int(s[i]) if b==0:A=[max(A),0,0] elif b==1:A=[max(A),max(A[0],A[2])+1,0] elif b==2:A=[max(A),0,max(A[0],A[1])+1] else:A=[max(A),max(A[0],A[2])+1,max(A[0],A[1])+1] print(a-max(A)) ```
3
814
A
An abandoned sentiment from past
PROGRAMMING
900
[ "constructive algorithms", "greedy", "implementation", "sortings" ]
null
null
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity. Hitagi's sequence *a* has a length of *n*. Lost elements in it are denoted by zeros. Kaiki provides another sequence *b*, whose length *k* equals the number of lost elements in *a* (i.e. the number of zeros). Hitagi is to replace each zero in *a* with an element from *b* so that each element in *b* should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in *a* and *b* more than once in total. If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in *a* with an integer from *b* so that each integer from *b* is used exactly once, and the resulting sequence is not increasing.
The first line of input contains two space-separated positive integers *n* (2<=≤<=*n*<=≤<=100) and *k* (1<=≤<=*k*<=≤<=*n*) — the lengths of sequence *a* and *b* respectively. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=200) — Hitagi's broken sequence with exactly *k* zero elements. The third line contains *k* space-separated integers *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b**i*<=≤<=200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in *a* and *b* more than once in total.
Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise.
[ "4 2\n11 0 0 14\n5 4\n", "6 1\n2 3 0 8 9 10\n5\n", "4 1\n8 94 0 4\n89\n", "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n" ]
[ "Yes\n", "No\n", "Yes\n", "Yes\n" ]
In the first sample: - Sequence *a* is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.
500
[ { "input": "4 2\n11 0 0 14\n5 4", "output": "Yes" }, { "input": "6 1\n2 3 0 8 9 10\n5", "output": "No" }, { "input": "4 1\n8 94 0 4\n89", "output": "Yes" }, { "input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes" }, { "input": "40 1\n23 26 27 28 31 35 38 4...
1,496,839,630
1,930
Python 3
COMPILATION_ERROR
PRETESTS
0
0
0
import java.util.Arrays; import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ public class Codeforces { public static boolean creciente(int[] arr){ int cont=0; for (int i = 1; i < arr.length; i++) { if(arr[i-1]<=arr[i]){ cont++; } } return cont==arr.length-1; } public static void main(String[] args) { Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int[] hitagi=new int[a]; int[] kakis=new int[b]; for (int i = 0; i < a; i++) { hitagi[i]=sc.nextInt(); } for (int i = 0; i < b; i++) { kakis[i]=sc.nextInt(); } int pos=0; int fullzeros=0; for (int i = 0; i < a; i++) { if(hitagi[i]==0){ hitagi[i]=kakis[pos]; pos++; fullzeros++; } } if(!creciente(hitagi) || fullzeros==hitagi.length){ System.out.println("Yes"); } else{ System.out.println("No"); } } }
Title: An abandoned sentiment from past Time Limit: None seconds Memory Limit: None megabytes Problem Description: A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity. Hitagi's sequence *a* has a length of *n*. Lost elements in it are denoted by zeros. Kaiki provides another sequence *b*, whose length *k* equals the number of lost elements in *a* (i.e. the number of zeros). Hitagi is to replace each zero in *a* with an element from *b* so that each element in *b* should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in *a* and *b* more than once in total. If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in *a* with an integer from *b* so that each integer from *b* is used exactly once, and the resulting sequence is not increasing. Input Specification: The first line of input contains two space-separated positive integers *n* (2<=≤<=*n*<=≤<=100) and *k* (1<=≤<=*k*<=≤<=*n*) — the lengths of sequence *a* and *b* respectively. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=200) — Hitagi's broken sequence with exactly *k* zero elements. The third line contains *k* space-separated integers *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b**i*<=≤<=200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in *a* and *b* more than once in total. Output Specification: Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise. Demo Input: ['4 2\n11 0 0 14\n5 4\n', '6 1\n2 3 0 8 9 10\n5\n', '4 1\n8 94 0 4\n89\n', '7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n'] Demo Output: ['Yes\n', 'No\n', 'Yes\n', 'Yes\n'] Note: In the first sample: - Sequence *a* is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.
```python import java.util.Arrays; import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ public class Codeforces { public static boolean creciente(int[] arr){ int cont=0; for (int i = 1; i < arr.length; i++) { if(arr[i-1]<=arr[i]){ cont++; } } return cont==arr.length-1; } public static void main(String[] args) { Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int[] hitagi=new int[a]; int[] kakis=new int[b]; for (int i = 0; i < a; i++) { hitagi[i]=sc.nextInt(); } for (int i = 0; i < b; i++) { kakis[i]=sc.nextInt(); } int pos=0; int fullzeros=0; for (int i = 0; i < a; i++) { if(hitagi[i]==0){ hitagi[i]=kakis[pos]; pos++; fullzeros++; } } if(!creciente(hitagi) || fullzeros==hitagi.length){ System.out.println("Yes"); } else{ System.out.println("No"); } } } ```
-1
614
B
Gena's Code
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse! There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful. Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case.
The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country. It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000.
Print a single number without leading zeroes — the product of the number of tanks presented by each country.
[ "3\n5 10 1\n", "4\n1 1 10 11\n", "5\n0 3 1 100 1\n" ]
[ "50", "110", "0" ]
In sample 1 numbers 10 and 1 are beautiful, number 5 is not not. In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful. In sample 3 number 3 is not beautiful, all others are beautiful.
1,000
[ { "input": "3\n5 10 1", "output": "50" }, { "input": "4\n1 1 10 11", "output": "110" }, { "input": "5\n0 3 1 100 1", "output": "0" }, { "input": "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 ...
1,640,451,139
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
9
500
409,600
n = int(input()) line = [0]*n line = input().split(" ") num = 1 for i in range(n): num = num * int(line[i]) print(num)
Title: Gena's Code Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse! There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful. Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case. Input Specification: The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country. It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000. Output Specification: Print a single number without leading zeroes — the product of the number of tanks presented by each country. Demo Input: ['3\n5 10 1\n', '4\n1 1 10 11\n', '5\n0 3 1 100 1\n'] Demo Output: ['50', '110', '0'] Note: In sample 1 numbers 10 and 1 are beautiful, number 5 is not not. In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful. In sample 3 number 3 is not beautiful, all others are beautiful.
```python n = int(input()) line = [0]*n line = input().split(" ") num = 1 for i in range(n): num = num * int(line[i]) print(num) ```
0
305
B
Continued Fractions
PROGRAMMING
1,700
[ "brute force", "implementation", "math" ]
null
null
A continued fraction of height *n* is a fraction of form . You are given two rational numbers, one is represented as and the other one is represented as a finite fraction of height *n*. Check if they are equal.
The first line contains two space-separated integers *p*,<=*q* (1<=≤<=*q*<=≤<=*p*<=≤<=1018) — the numerator and the denominator of the first fraction. The second line contains integer *n* (1<=≤<=*n*<=≤<=90) — the height of the second fraction. The third line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1018) — the continued fraction. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Print "YES" if these fractions are equal and "NO" otherwise.
[ "9 4\n2\n2 4\n", "9 4\n3\n2 3 1\n", "9 4\n3\n1 2 4\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5ff92f27aebea2560d99ad61202d20bab5ee5390.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/221368c79c05fc0ecad4e5f7a64f30b832fd99f5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the third sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4fb4b411afc0fbad27a1c8fdd08ba88ec3830ef5.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
1,000
[ { "input": "9 4\n2\n2 4", "output": "YES" }, { "input": "9 4\n3\n2 3 1", "output": "YES" }, { "input": "9 4\n3\n1 2 4", "output": "NO" }, { "input": "39088169 24157817\n36\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2", "output": "YES" }, { ...
1,517,819,305
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
122
5,632,000
import sys p, q = [int(x) for x in sys.stdin.readline().strip().split(" ")] n = sys.stdin.readline().strip() frac = [float(x) for x in sys.stdin.readline().strip().split(" ")] frac.reverse() cur = frac[0] for i in range(1, len(frac)): a = frac[i] cur = a + (1/cur) if(cur == (p/q)): print("YES") else: print("NO")
Title: Continued Fractions Time Limit: None seconds Memory Limit: None megabytes Problem Description: A continued fraction of height *n* is a fraction of form . You are given two rational numbers, one is represented as and the other one is represented as a finite fraction of height *n*. Check if they are equal. Input Specification: The first line contains two space-separated integers *p*,<=*q* (1<=≤<=*q*<=≤<=*p*<=≤<=1018) — the numerator and the denominator of the first fraction. The second line contains integer *n* (1<=≤<=*n*<=≤<=90) — the height of the second fraction. The third line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1018) — the continued fraction. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Output Specification: Print "YES" if these fractions are equal and "NO" otherwise. Demo Input: ['9 4\n2\n2 4\n', '9 4\n3\n2 3 1\n', '9 4\n3\n1 2 4\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: In the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5ff92f27aebea2560d99ad61202d20bab5ee5390.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/221368c79c05fc0ecad4e5f7a64f30b832fd99f5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the third sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4fb4b411afc0fbad27a1c8fdd08ba88ec3830ef5.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python import sys p, q = [int(x) for x in sys.stdin.readline().strip().split(" ")] n = sys.stdin.readline().strip() frac = [float(x) for x in sys.stdin.readline().strip().split(" ")] frac.reverse() cur = frac[0] for i in range(1, len(frac)): a = frac[i] cur = a + (1/cur) if(cur == (p/q)): print("YES") else: print("NO") ```
0
253
B
Physics Practical
PROGRAMMING
1,400
[ "binary search", "dp", "sortings", "two pointers" ]
null
null
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result *x*, and the largest result *y*, then the inequality *y*<=≤<=2·*x* must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes. Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=5000) — the results of the measurements. The numbers on the second line are separated by single spaces.
Print a single integer — the minimum number of results Vasya will have to remove.
[ "6\n4 5 3 8 3 7\n", "4\n4 3 2 4\n" ]
[ "2\n", "0\n" ]
In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
1,000
[ { "input": "6\n4 5 3 8 3 7", "output": "2" }, { "input": "4\n4 3 2 4", "output": "0" }, { "input": "6\n5 6 4 9 4 8", "output": "1" }, { "input": "4\n5 4 1 5", "output": "1" }, { "input": "2\n3 2", "output": "0" }, { "input": "10\n39 9 18 13 6 16 47 15 ...
1,669,015,571
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
156
2,150,400
n=input() c=input().split() print(r)
Title: Physics Practical Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result *x*, and the largest result *y*, then the inequality *y*<=≤<=2·*x* must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes. Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times. Input Specification: The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=5000) — the results of the measurements. The numbers on the second line are separated by single spaces. Output Specification: Print a single integer — the minimum number of results Vasya will have to remove. Demo Input: ['6\n4 5 3 8 3 7\n', '4\n4 3 2 4\n'] Demo Output: ['2\n', '0\n'] Note: In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
```python n=input() c=input().split() print(r) ```
-1
36
A
Extra-terrestrial Intelligence
PROGRAMMING
1,300
[ "implementation" ]
A. Extra-terrestrial Intelligence
2
64
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of days during which Vasya checked if there were any signals. The second line contains *n* characters 1 or 0 — the record Vasya kept each of those *n* days. It’s guaranteed that the given record sequence contains at least three 1s.
If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO.
[ "8\n00111000\n", "7\n1001011\n", "7\n1010100\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "8\n00111000", "output": "YES" }, { "input": "7\n1001011", "output": "NO" }, { "input": "7\n1010100", "output": "YES" }, { "input": "5\n10101", "output": "YES" }, { "input": "3\n111", "output": "YES" }, { "input": "10\n0011111011", "outp...
1,546,856,653
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
186
0
k=int(input()) n=input() strs=[] result='YES' while True: if n[0]=='0': n=n[1:] else: break while True: if n[-1]=='0': n=n[:-1] else: break m=1 for i in n[1:]: if i!='1': m+=1 else: break for i in n[::m]: if i=='1': strs.append('1') else: result='NO' break if n.count('1')!=len(strs): result='NO' print(result)
Title: Extra-terrestrial Intelligence Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of days during which Vasya checked if there were any signals. The second line contains *n* characters 1 or 0 — the record Vasya kept each of those *n* days. It’s guaranteed that the given record sequence contains at least three 1s. Output Specification: If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. Demo Input: ['8\n00111000\n', '7\n1001011\n', '7\n1010100\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: none
```python k=int(input()) n=input() strs=[] result='YES' while True: if n[0]=='0': n=n[1:] else: break while True: if n[-1]=='0': n=n[:-1] else: break m=1 for i in n[1:]: if i!='1': m+=1 else: break for i in n[::m]: if i=='1': strs.append('1') else: result='NO' break if n.count('1')!=len(strs): result='NO' print(result) ```
-1
525
A
Vitaliy and Pie
PROGRAMMING
1,100
[ "greedy", "hashing", "strings" ]
null
null
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (*n*<=-<=1)-th room to the *n*-th room. Thus, you can go to room *x* only from room *x*<=-<=1. The potato pie is located in the *n*-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room *x* from room *x*<=-<=1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type *t* can open the door of type *T* if and only if *t* and *T* are the same letter, written in different cases. For example, key f can open door F. Each of the first *n*<=-<=1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door. Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room *n*. Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room *n*, which has a delicious potato pie. Write a program that will help Vitaly find out this number.
The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house. The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string *s* contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position *i* of the given string *s* contains a lowercase Latin letter — the type of the key that lies in room number (*i*<=+<=1)<=/<=2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position *i* of the given string *s* contains an uppercase letter — the type of the door that leads from room *i*<=/<=2 to room *i*<=/<=2<=+<=1.
Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*.
[ "3\naAbB\n", "4\naBaCaB\n", "5\nxYyXzZaZ\n" ]
[ "0\n", "3\n", "2\n" ]
none
250
[ { "input": "3\naAbB", "output": "0" }, { "input": "4\naBaCaB", "output": "3" }, { "input": "5\nxYyXzZaZ", "output": "2" }, { "input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY", "output": "0" }, { "input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg...
1,674,203,758
2,147,483,647
PyPy 3-64
OK
TESTS
46
92
2,867,200
import collections n = int(input()) s = input() keys = collections.defaultdict(int) req = 0 for j in range(1, 2 * n - 2, 2): keys[s[j - 1].upper()] += 1 if keys[s[j]]: keys[s[j]] -= 1 else: req += 1 print(req)
Title: Vitaliy and Pie Time Limit: None seconds Memory Limit: None megabytes Problem Description: After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (*n*<=-<=1)-th room to the *n*-th room. Thus, you can go to room *x* only from room *x*<=-<=1. The potato pie is located in the *n*-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room *x* from room *x*<=-<=1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type *t* can open the door of type *T* if and only if *t* and *T* are the same letter, written in different cases. For example, key f can open door F. Each of the first *n*<=-<=1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door. Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room *n*. Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room *n*, which has a delicious potato pie. Write a program that will help Vitaly find out this number. Input Specification: The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house. The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string *s* contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position *i* of the given string *s* contains a lowercase Latin letter — the type of the key that lies in room number (*i*<=+<=1)<=/<=2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position *i* of the given string *s* contains an uppercase letter — the type of the door that leads from room *i*<=/<=2 to room *i*<=/<=2<=+<=1. Output Specification: Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. Demo Input: ['3\naAbB\n', '4\naBaCaB\n', '5\nxYyXzZaZ\n'] Demo Output: ['0\n', '3\n', '2\n'] Note: none
```python import collections n = int(input()) s = input() keys = collections.defaultdict(int) req = 0 for j in range(1, 2 * n - 2, 2): keys[s[j - 1].upper()] += 1 if keys[s[j]]: keys[s[j]] -= 1 else: req += 1 print(req) ```
3
7
D
Palindrome Degree
PROGRAMMING
2,200
[ "hashing", "strings" ]
D. Palindrome Degree
1
256
String *s* of length *n* is called *k*-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (*k*<=-<=1)-palindromes. By definition, any string (even empty) is 0-palindrome. Let's call the palindrome degree of string *s* such a maximum number *k*, for which *s* is *k*-palindrome. For example, "abaaba" has degree equals to 3. You are given a string. Your task is to find the sum of the palindrome degrees of all its prefixes.
The first line of the input data contains a non-empty string, consisting of Latin letters and digits. The length of the string does not exceed 5·106. The string is case-sensitive.
Output the only number — the sum of the polindrome degrees of all the string's prefixes.
[ "a2A\n", "abacaba\n" ]
[ "1", "6" ]
none
0
[ { "input": "a2A", "output": "1" }, { "input": "abacaba", "output": "6" }, { "input": "CCeCeCCCee", "output": "4" }, { "input": "opooppppopppopoppopoooppopopooopopppooopppoppoppoppppoooppooooooopppoopoopooooppooooppppppppooopooop", "output": "3" }, { "input": "odri...
1,463,282,860
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
11
1,000
59,187,200
#a2A:1 #abacaba:1+(0+2)+0+0+0+(3) #CCeCeCCCee:1+(2+0)+0+0+0+1+0+0+0 def change(x): y = ord(x)-48 return y #79 constant = 107 cons = 1000000009 string = list(input()) hash1 = 0 hash2 = 0 power = 1 ans = 0 l = len(string) degree = [0]+[0 for i in range(l)] for i in range(0,l): #print(power) hash1 = (hash1+(change(string[i]))*power)%cons #print(hash1) hash2 = (constant*hash2 + change(string[i]))%cons #print(hash2) power = (power*constant)%cons #print(power) if hash1 == hash2: temp = degree[((i+1)//2)-1]+1 ans += temp degree[i] = temp print(ans)
Title: Palindrome Degree Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: String *s* of length *n* is called *k*-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (*k*<=-<=1)-palindromes. By definition, any string (even empty) is 0-palindrome. Let's call the palindrome degree of string *s* such a maximum number *k*, for which *s* is *k*-palindrome. For example, "abaaba" has degree equals to 3. You are given a string. Your task is to find the sum of the palindrome degrees of all its prefixes. Input Specification: The first line of the input data contains a non-empty string, consisting of Latin letters and digits. The length of the string does not exceed 5·106. The string is case-sensitive. Output Specification: Output the only number — the sum of the polindrome degrees of all the string's prefixes. Demo Input: ['a2A\n', 'abacaba\n'] Demo Output: ['1', '6'] Note: none
```python #a2A:1 #abacaba:1+(0+2)+0+0+0+(3) #CCeCeCCCee:1+(2+0)+0+0+0+1+0+0+0 def change(x): y = ord(x)-48 return y #79 constant = 107 cons = 1000000009 string = list(input()) hash1 = 0 hash2 = 0 power = 1 ans = 0 l = len(string) degree = [0]+[0 for i in range(l)] for i in range(0,l): #print(power) hash1 = (hash1+(change(string[i]))*power)%cons #print(hash1) hash2 = (constant*hash2 + change(string[i]))%cons #print(hash2) power = (power*constant)%cons #print(power) if hash1 == hash2: temp = degree[((i+1)//2)-1]+1 ans += temp degree[i] = temp print(ans) ```
0
679
A
Bear and Prime 100
PROGRAMMING
1,400
[ "constructive algorithms", "interactive", "math" ]
null
null
This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite. Integer *x*<=&gt;<=1 is called prime if it has exactly two distinct divisors, 1 and *x*. If integer *x*<=&gt;<=1 is not prime, it's called composite. You can ask up to 20 queries about divisors of the hidden number. In each query you should print an integer from interval [2,<=100]. The system will answer "yes" if your integer is a divisor of the hidden number. Otherwise, the answer will be "no". For example, if the hidden number is 14 then the system will answer "yes" only if you print 2, 7 or 14. When you are done asking queries, print "prime" or "composite" and terminate your program. You will get the Wrong Answer verdict if you ask more than 20 queries, or if you print an integer not from the range [2,<=100]. Also, you will get the Wrong Answer verdict if the printed answer isn't correct. You will get the Idleness Limit Exceeded verdict if you don't print anything (but you should) or if you forget about flushing the output (more info below).
After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise.
Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input. In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flush the output and terminate your program. To flush you can use (just after printing an integer and end-of-line): - fflush(stdout) in C++; - System.out.flush() in Java; - stdout.flush() in Python; - flush(output) in Pascal; - See the documentation for other languages. Hacking. To hack someone, as the input you should print the hidden number — one integer from the interval [2,<=100]. Of course, his/her solution won't be able to read the hidden number from the input.
[ "yes\nno\nyes\n", "no\nyes\nno\nno\nno\n" ]
[ "2\n80\n5\ncomposite\n", "58\n59\n78\n78\n2\nprime\n" ]
The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/> The hidden number is divisible by both 2 and 5. Thus, it must be composite. Note that it isn't necessary to know the exact value of the hidden number. In this test, the hidden number is 30. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/35c6952617fa94ec3e0ea8e63aa1c3c49b3ba420.png" style="max-width: 100.0%;max-height: 100.0%;"/> 59 is a divisor of the hidden number. In the interval [2, 100] there is only one number with this divisor. The hidden number must be 59, which is prime. Note that the answer is known even after the second query and you could print it then and terminate. Though, it isn't forbidden to ask unnecessary queries (unless you exceed the limit of 20 queries).
750
[ { "input": "30", "output": "composite 4" }, { "input": "59", "output": "prime 15" }, { "input": "2", "output": "prime 16" }, { "input": "7", "output": "prime 16" }, { "input": "9", "output": "composite 3" }, { "input": "13", "output": "prime 15" ...
1,622,581,507
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
217
2,048,000
prime=[1 for i in range(101)] prime[0]=0 prime[1]=0 for i in range(2,101): if prime[i]==1: for j in range(i*i,101,i): prime[j]=0 ans=[] for i in range(2,72): if prime[i]: ans.append(i) count=0 for i in prime: print(i,flush=True) s=input() if s=="yes": count+=1 if count<=1: print("prime",flush=True) else: print("composite",flush=True)
Title: Bear and Prime 100 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. Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite. Integer *x*<=&gt;<=1 is called prime if it has exactly two distinct divisors, 1 and *x*. If integer *x*<=&gt;<=1 is not prime, it's called composite. You can ask up to 20 queries about divisors of the hidden number. In each query you should print an integer from interval [2,<=100]. The system will answer "yes" if your integer is a divisor of the hidden number. Otherwise, the answer will be "no". For example, if the hidden number is 14 then the system will answer "yes" only if you print 2, 7 or 14. When you are done asking queries, print "prime" or "composite" and terminate your program. You will get the Wrong Answer verdict if you ask more than 20 queries, or if you print an integer not from the range [2,<=100]. Also, you will get the Wrong Answer verdict if the printed answer isn't correct. You will get the Idleness Limit Exceeded verdict if you don't print anything (but you should) or if you forget about flushing the output (more info below). Input Specification: After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise. Output Specification: Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input. In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flush the output and terminate your program. To flush you can use (just after printing an integer and end-of-line): - fflush(stdout) in C++; - System.out.flush() in Java; - stdout.flush() in Python; - flush(output) in Pascal; - See the documentation for other languages. Hacking. To hack someone, as the input you should print the hidden number — one integer from the interval [2,<=100]. Of course, his/her solution won't be able to read the hidden number from the input. Demo Input: ['yes\nno\nyes\n', 'no\nyes\nno\nno\nno\n'] Demo Output: ['2\n80\n5\ncomposite\n', '58\n59\n78\n78\n2\nprime\n'] Note: The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/> The hidden number is divisible by both 2 and 5. Thus, it must be composite. Note that it isn't necessary to know the exact value of the hidden number. In this test, the hidden number is 30. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/35c6952617fa94ec3e0ea8e63aa1c3c49b3ba420.png" style="max-width: 100.0%;max-height: 100.0%;"/> 59 is a divisor of the hidden number. In the interval [2, 100] there is only one number with this divisor. The hidden number must be 59, which is prime. Note that the answer is known even after the second query and you could print it then and terminate. Though, it isn't forbidden to ask unnecessary queries (unless you exceed the limit of 20 queries).
```python prime=[1 for i in range(101)] prime[0]=0 prime[1]=0 for i in range(2,101): if prime[i]==1: for j in range(i*i,101,i): prime[j]=0 ans=[] for i in range(2,72): if prime[i]: ans.append(i) count=0 for i in prime: print(i,flush=True) s=input() if s=="yes": count+=1 if count<=1: print("prime",flush=True) else: print("composite",flush=True) ```
0
0
none
none
none
0
[ "none" ]
null
null
In the year of $30XX$ participants of some world programming championship live in a single large hotel. The hotel has $n$ floors. Each floor has $m$ sections with a single corridor connecting all of them. The sections are enumerated from $1$ to $m$ along the corridor, and all sections with equal numbers on different floors are located exactly one above the other. Thus, the hotel can be represented as a rectangle of height $n$ and width $m$. We can denote sections with pairs of integers $(i, j)$, where $i$ is the floor, and $j$ is the section number on the floor. The guests can walk along the corridor on each floor, use stairs and elevators. Each stairs or elevator occupies all sections $(1, x)$, $(2, x)$, $\ldots$, $(n, x)$ for some $x$ between $1$ and $m$. All sections not occupied with stairs or elevators contain guest rooms. It takes one time unit to move between neighboring sections on the same floor or to move one floor up or down using stairs. It takes one time unit to move up to $v$ floors in any direction using an elevator. You can assume you don't have to wait for an elevator, and the time needed to enter or exit an elevator is negligible. You are to process $q$ queries. Each query is a question "what is the minimum time needed to go from a room in section $(x_1, y_1)$ to a room in section $(x_2, y_2)$?"
The first line contains five integers $n, m, c_l, c_e, v$ ($2 \leq n, m \leq 10^8$, $0 \leq c_l, c_e \leq 10^5$, $1 \leq c_l + c_e \leq m - 1$, $1 \leq v \leq n - 1$) — the number of floors and section on each floor, the number of stairs, the number of elevators and the maximum speed of an elevator, respectively. The second line contains $c_l$ integers $l_1, \ldots, l_{c_l}$ in increasing order ($1 \leq l_i \leq m$), denoting the positions of the stairs. If $c_l = 0$, the second line is empty. The third line contains $c_e$ integers $e_1, \ldots, e_{c_e}$ in increasing order, denoting the elevators positions in the same format. It is guaranteed that all integers $l_i$ and $e_i$ are distinct. The fourth line contains a single integer $q$ ($1 \leq q \leq 10^5$) — the number of queries. The next $q$ lines describe queries. Each of these lines contains four integers $x_1, y_1, x_2, y_2$ ($1 \leq x_1, x_2 \leq n$, $1 \leq y_1, y_2 \leq m$) — the coordinates of starting and finishing sections for the query. It is guaranteed that the starting and finishing sections are distinct. It is also guaranteed that these sections contain guest rooms, i. e. $y_1$ and $y_2$ are not among $l_i$ and $e_i$.
Print $q$ integers, one per line — the answers for the queries.
[ "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3\n" ]
[ "7\n5\n4\n" ]
In the first query the optimal way is to go to the elevator in the 5-th section in four time units, use it to go to the fifth floor in two time units and go to the destination in one more time unit. In the second query it is still optimal to use the elevator, but in the third query it is better to use the stairs in the section 2.
0
[ { "input": "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3", "output": "7\n5\n4" }, { "input": "2 2 0 1 1\n\n1\n1\n1 2 2 2", "output": "3" }, { "input": "4 4 1 0 1\n4\n\n5\n1 1 2 2\n1 3 2 2\n3 3 4 3\n3 2 2 2\n1 2 2 3", "output": "6\n4\n3\n5\n4" }, { "input": "10 10 1 8 4\n10\n...
1,525,015,410
7,710
Python 3
RUNTIME_ERROR
PRETESTS
1
77
7,065,600
from bisect import bisect_left,bisect_right from math import ceil n,m,s,e,v = map(int,input().split()) if s > 0: stairs = list(map(int,input().split())) if e > 0: elevators = list(map(int,input().split())) Q = int(input()) for i in range(Q): x1,y1,x2,y2 = map(int,input().split()) if x1 == x2: print(abs(y1-y2)) else: stair_time = 1000*1000*1000 elevator_time = 1000*1000*1000 if s > 0: closest=-1 lo = bisect_left(stairs,y1) hi = bisect_right(stairs,y1) if lo >= len(stairs): lo = 0 if hi >= len(stairs): hi -= 1 if abs(stairs[lo] - y1) < abs(stairs[hi] - y1): closest = stairs[lo] else: closest = stairs[hi] stair_time = abs(closest-y1) + abs(x1-x2) + abs(closest-y2) if e > 0: closest=-1 lo = bisect_left(elevators,y1) hi = bisect_right(elevators,y1) if lo >= len(elevators): lo = 0 if hi >= len(elevators): hi -= 1 if abs(elevators[lo] - y1) < abs(elevators[hi] - y1): closest = elevators[lo] else: closest = elevators[hi] horiz_time= abs(closest-y1) + abs(closest-y2) vert_time = ceil(abs(x1-x2)/v) elevator_time = vert_time+horiz_time print(min(elevator_time,stair_time))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the year of $30XX$ participants of some world programming championship live in a single large hotel. The hotel has $n$ floors. Each floor has $m$ sections with a single corridor connecting all of them. The sections are enumerated from $1$ to $m$ along the corridor, and all sections with equal numbers on different floors are located exactly one above the other. Thus, the hotel can be represented as a rectangle of height $n$ and width $m$. We can denote sections with pairs of integers $(i, j)$, where $i$ is the floor, and $j$ is the section number on the floor. The guests can walk along the corridor on each floor, use stairs and elevators. Each stairs or elevator occupies all sections $(1, x)$, $(2, x)$, $\ldots$, $(n, x)$ for some $x$ between $1$ and $m$. All sections not occupied with stairs or elevators contain guest rooms. It takes one time unit to move between neighboring sections on the same floor or to move one floor up or down using stairs. It takes one time unit to move up to $v$ floors in any direction using an elevator. You can assume you don't have to wait for an elevator, and the time needed to enter or exit an elevator is negligible. You are to process $q$ queries. Each query is a question "what is the minimum time needed to go from a room in section $(x_1, y_1)$ to a room in section $(x_2, y_2)$?" Input Specification: The first line contains five integers $n, m, c_l, c_e, v$ ($2 \leq n, m \leq 10^8$, $0 \leq c_l, c_e \leq 10^5$, $1 \leq c_l + c_e \leq m - 1$, $1 \leq v \leq n - 1$) — the number of floors and section on each floor, the number of stairs, the number of elevators and the maximum speed of an elevator, respectively. The second line contains $c_l$ integers $l_1, \ldots, l_{c_l}$ in increasing order ($1 \leq l_i \leq m$), denoting the positions of the stairs. If $c_l = 0$, the second line is empty. The third line contains $c_e$ integers $e_1, \ldots, e_{c_e}$ in increasing order, denoting the elevators positions in the same format. It is guaranteed that all integers $l_i$ and $e_i$ are distinct. The fourth line contains a single integer $q$ ($1 \leq q \leq 10^5$) — the number of queries. The next $q$ lines describe queries. Each of these lines contains four integers $x_1, y_1, x_2, y_2$ ($1 \leq x_1, x_2 \leq n$, $1 \leq y_1, y_2 \leq m$) — the coordinates of starting and finishing sections for the query. It is guaranteed that the starting and finishing sections are distinct. It is also guaranteed that these sections contain guest rooms, i. e. $y_1$ and $y_2$ are not among $l_i$ and $e_i$. Output Specification: Print $q$ integers, one per line — the answers for the queries. Demo Input: ['5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3\n'] Demo Output: ['7\n5\n4\n'] Note: In the first query the optimal way is to go to the elevator in the 5-th section in four time units, use it to go to the fifth floor in two time units and go to the destination in one more time unit. In the second query it is still optimal to use the elevator, but in the third query it is better to use the stairs in the section 2.
```python from bisect import bisect_left,bisect_right from math import ceil n,m,s,e,v = map(int,input().split()) if s > 0: stairs = list(map(int,input().split())) if e > 0: elevators = list(map(int,input().split())) Q = int(input()) for i in range(Q): x1,y1,x2,y2 = map(int,input().split()) if x1 == x2: print(abs(y1-y2)) else: stair_time = 1000*1000*1000 elevator_time = 1000*1000*1000 if s > 0: closest=-1 lo = bisect_left(stairs,y1) hi = bisect_right(stairs,y1) if lo >= len(stairs): lo = 0 if hi >= len(stairs): hi -= 1 if abs(stairs[lo] - y1) < abs(stairs[hi] - y1): closest = stairs[lo] else: closest = stairs[hi] stair_time = abs(closest-y1) + abs(x1-x2) + abs(closest-y2) if e > 0: closest=-1 lo = bisect_left(elevators,y1) hi = bisect_right(elevators,y1) if lo >= len(elevators): lo = 0 if hi >= len(elevators): hi -= 1 if abs(elevators[lo] - y1) < abs(elevators[hi] - y1): closest = elevators[lo] else: closest = elevators[hi] horiz_time= abs(closest-y1) + abs(closest-y2) vert_time = ceil(abs(x1-x2)/v) elevator_time = vert_time+horiz_time print(min(elevator_time,stair_time)) ```
-1
29
A
Spit Problem
PROGRAMMING
1,000
[ "brute force" ]
A. Spit Problem
2
256
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. The trajectory of a camel's spit is an arc, i.e. if the camel in position *x* spits *d* meters right, he can hit only the camel in position *x*<=+<=*d*, if such a camel exists.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at which the *i*-th camel spitted. Positive values of *d**i* correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position.
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
[ "2\n0 1\n1 -1\n", "3\n0 1\n1 1\n2 -2\n", "5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "2\n0 1\n1 -1", "output": "YES" }, { "input": "3\n0 1\n1 1\n2 -2", "output": "NO" }, { "input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES" }, { "input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n759...
1,672,221,525
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
124
0
c = d = 0 flag = 0 for n in range(int(input())): a, b = map(int, input().split()) if a + b == c and c+d == a: flag = 1 c , d = a, b if flag == 1: print("YES") else: print("NO")
Title: Spit Problem Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. The trajectory of a camel's spit is an arc, i.e. if the camel in position *x* spits *d* meters right, he can hit only the camel in position *x*<=+<=*d*, if such a camel exists. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at which the *i*-th camel spitted. Positive values of *d**i* correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position. Output Specification: If there are two camels, which spitted at each other, output YES. Otherwise, output NO. Demo Input: ['2\n0 1\n1 -1\n', '3\n0 1\n1 1\n2 -2\n', '5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: none
```python c = d = 0 flag = 0 for n in range(int(input())): a, b = map(int, input().split()) if a + b == c and c+d == a: flag = 1 c , d = a, b if flag == 1: print("YES") else: print("NO") ```
0
797
A
k-Factorization
PROGRAMMING
1,100
[ "implementation", "math", "number theory" ]
null
null
Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*.
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20).
If it's impossible to find the representation of *n* as a product of *k* numbers, print -1. Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them.
[ "100000 2\n", "100000 20\n", "1024 5\n" ]
[ "2 50000 \n", "-1\n", "2 64 2 2 2 \n" ]
none
0
[ { "input": "100000 2", "output": "2 50000 " }, { "input": "100000 20", "output": "-1" }, { "input": "1024 5", "output": "2 64 2 2 2 " }, { "input": "100000 10", "output": "2 2 2 2 2 5 5 5 5 5 " }, { "input": "99999 3", "output": "3 813 41 " }, { "input...
1,699,680,445
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
46
0
n,k = map(int,input().split()) a=[] flag = 1 if n < 2**k: flag = 0 else: while(len(a)<k): for i in range(2,int(n**0.2)+1): if n%i==0: if a != []: a.pop() a.append(i) n//=i a.append(n) break else: break if flag: for i in a: print(i,end=" ") else: print(-1)
Title: k-Factorization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*. Input Specification: The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20). Output Specification: If it's impossible to find the representation of *n* as a product of *k* numbers, print -1. Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them. Demo Input: ['100000 2\n', '100000 20\n', '1024 5\n'] Demo Output: ['2 50000 \n', '-1\n', '2 64 2 2 2 \n'] Note: none
```python n,k = map(int,input().split()) a=[] flag = 1 if n < 2**k: flag = 0 else: while(len(a)<k): for i in range(2,int(n**0.2)+1): if n%i==0: if a != []: a.pop() a.append(i) n//=i a.append(n) break else: break if flag: for i in a: print(i,end=" ") else: print(-1) ```
0
446
A
DZY Loves Sequences
PROGRAMMING
1,600
[ "dp", "implementation", "two pointers" ]
null
null
DZY has a sequence *a*, consisting of *n* integers. We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment. Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
In a single line print the answer to the problem — the maximum length of the required subsegment.
[ "6\n7 2 3 1 5 6\n" ]
[ "5\n" ]
You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4.
500
[ { "input": "6\n7 2 3 1 5 6", "output": "5" }, { "input": "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422", "output": "9" }, { "input": "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 1...
1,586,439,548
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
139
0
n=int(input()) a=list(map(int,input().split())) ls=[] temp=[a[0]] for i in range(1,n): if(a[i]>a[i-1]): temp.append(a[i]) else: ls.append(temp) temp=[a[i]] if(len(temp)): ls.append(temp) ans=0 for i in range(len(ls)-1): if(len(ls[i+1])==1): ans=max(ans,len(ls[i])+1) else: if(ls[i+1][1]-ls[i][-1]>1): ans=max(ans,len(ls[i])+len(ls[i+1])) print(ans)
Title: DZY Loves Sequences Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY has a sequence *a*, consisting of *n* integers. We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment. Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). Output Specification: In a single line print the answer to the problem — the maximum length of the required subsegment. Demo Input: ['6\n7 2 3 1 5 6\n'] Demo Output: ['5\n'] Note: You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4.
```python n=int(input()) a=list(map(int,input().split())) ls=[] temp=[a[0]] for i in range(1,n): if(a[i]>a[i-1]): temp.append(a[i]) else: ls.append(temp) temp=[a[i]] if(len(temp)): ls.append(temp) ans=0 for i in range(len(ls)-1): if(len(ls[i+1])==1): ans=max(ans,len(ls[i])+1) else: if(ls[i+1][1]-ls[i][-1]>1): ans=max(ans,len(ls[i])+len(ls[i+1])) print(ans) ```
0
520
A
Pangram
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output "YES", if the string is a pangram and "NO" otherwise.
[ "12\ntoosmallword\n", "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "12\ntoosmallword", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog", "output": "YES" }, { "input": "1\na", "output": "NO" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "YES" }, { "input": "26\nABCDEFGHIJKLMNOPQRSTUVWXY...
1,693,578,099
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
0
n=int(input()) x=input() x.lower() if(len(set(list(x))) == 26): print("YES") else: print("NO")
Title: Pangram Time Limit: None seconds Memory Limit: None megabytes Problem Description: A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters. Output Specification: Output "YES", if the string is a pangram and "NO" otherwise. Demo Input: ['12\ntoosmallword\n', '35\nTheQuickBrownFoxJumpsOverTheLazyDog\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python n=int(input()) x=input() x.lower() if(len(set(list(x))) == 26): print("YES") else: print("NO") ```
0
343
B
Alternating Current
PROGRAMMING
1,600
[ "data structures", "greedy", "implementation" ]
null
null
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples.
The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.
Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.
[ "-++-\n", "+-\n", "++\n", "-\n" ]
[ "Yes\n", "No\n", "Yes\n", "No\n" ]
The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
1,000
[ { "input": "-++-", "output": "Yes" }, { "input": "+-", "output": "No" }, { "input": "++", "output": "Yes" }, { "input": "-", "output": "No" }, { "input": "+-+-", "output": "No" }, { "input": "-+-", "output": "No" }, { "input": "-++-+--+", ...
1,586,874,392
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
24
1,000
307,200
lista = input() while '++' in lista or '--' in lista: lista = lista.replace('++', '') lista = lista.replace('--', '') if len(lista) > 0: print('No') else: print('Yes')
Title: Alternating Current Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input Specification: The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Specification: Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Demo Input: ['-++-\n', '+-\n', '++\n', '-\n'] Demo Output: ['Yes\n', 'No\n', 'Yes\n', 'No\n'] Note: The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
```python lista = input() while '++' in lista or '--' in lista: lista = lista.replace('++', '') lista = lista.replace('--', '') if len(lista) > 0: print('No') else: print('Yes') ```
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 minimum sum of money she will have to spend to make *n* rides?
The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket.
Print a single integer — the minimum sum in rubles that Ann will need to spend.
[ "6 2 1 2\n", "5 2 2 3\n" ]
[ "6\n", "8\n" ]
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets.
500
[ { "input": "6 2 1 2", "output": "6" }, { "input": "5 2 2 3", "output": "8" }, { "input": "10 3 5 1", "output": "4" }, { "input": "1000 1 1000 1000", "output": "1000000" }, { "input": "1000 3 1000 1000", "output": "334000" }, { "input": "1 1 1 1", "...
1,690,906,334
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
n,m,a,b=map(int,input().split()) v=[] if n%m==0: v+=[(n//m)*b] if n%m!=0: v+=[(n//m)*b+(n%m)*a] v+=[n*a] print(min(v))
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* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimum sum of money she will have to spend to make *n* rides? Input Specification: 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. Output Specification: Print a single integer — the minimum sum in rubles that Ann will need to spend. Demo Input: ['6 2 1 2\n', '5 2 2 3\n'] Demo Output: ['6\n', '8\n'] Note: 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.
```python n,m,a,b=map(int,input().split()) v=[] if n%m==0: v+=[(n//m)*b] if n%m!=0: v+=[(n//m)*b+(n%m)*a] v+=[n*a] print(min(v)) ```
0
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink.
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39...
1,695,132,606
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
60
0
n=int(input()) a,b,c=map(int,input().split()) count= (a+b+c)/n print(count)
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink. Input Specification: The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. Output Specification: Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. Demo Input: ['3\n50 50 100\n', '4\n0 25 50 75\n'] Demo Output: ['66.666666666667\n', '37.500000000000\n'] Note: Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
```python n=int(input()) a,b,c=map(int,input().split()) count= (a+b+c)/n print(count) ```
-1
767
A
Snacktower
PROGRAMMING
1,100
[ "data structures", "implementation" ]
null
null
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top. Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower. However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it. Write a program that models the behavior of Ankh-Morpork residents.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks. The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*.
Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
[ "3\n3 1 2\n", "5\n4 5 1 2 3\n" ]
[ "3\n \n2 1", "5 4\n \n \n3 2 1\n" ]
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
500
[ { "input": "3\n3 1 2", "output": "3 \n\n2 1 " }, { "input": "5\n4 5 1 2 3", "output": "5 4 \n\n\n3 2 1 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n1 2", "output": "2 1 " }, { "input": "10\n5 1 6 2 8 3 4 10 9 7", "output": "10 \n9 8 \n7 6 5 4 3 2 1...
1,611,581,420
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
num_of_snacks = int(input()) snacks_size = [map(int, input().split(" "))] # num_of_snacks = 5 # snacks_size = [4, 5, 1, 2, 3] last_snack = num_of_snacks sorted_list_leng = 0 for i_day in range(num_of_snacks): if snacks_size[i_day] != last_snack: print() else: base_snacks = list( range(snacks_size[sorted_list_leng], snacks_size[i_day]+1)) sorted_list = sorted(base_snacks, reverse=True) sorted_list_leng = len(sorted_list) last_snack = sorted_list[-1] - 1 print(*sorted_list)
Title: Snacktower Time Limit: None seconds Memory Limit: None megabytes Problem Description: According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top. Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower. However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it. Write a program that models the behavior of Ankh-Morpork residents. Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks. The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. Output Specification: Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. Demo Input: ['3\n3 1 2\n', '5\n4 5 1 2 3\n'] Demo Output: ['3\n\xa0\n2 1', '5 4\n\xa0\n\xa0\n3 2 1\n'] Note: In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
```python num_of_snacks = int(input()) snacks_size = [map(int, input().split(" "))] # num_of_snacks = 5 # snacks_size = [4, 5, 1, 2, 3] last_snack = num_of_snacks sorted_list_leng = 0 for i_day in range(num_of_snacks): if snacks_size[i_day] != last_snack: print() else: base_snacks = list( range(snacks_size[sorted_list_leng], snacks_size[i_day]+1)) sorted_list = sorted(base_snacks, reverse=True) sorted_list_leng = len(sorted_list) last_snack = sorted_list[-1] - 1 print(*sorted_list) ```
-1
535
A
Tavas and Nafas
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type.
The first and only line of input contains an integer *s* (0<=≤<=*s*<=≤<=99), Tavas's score.
In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces.
[ "6\n", "99\n", "20\n" ]
[ "six\n", "ninety-nine\n", "twenty\n" ]
You can find all you need to know about English numerals in [http://en.wikipedia.org/wiki/English_numerals](https://en.wikipedia.org/wiki/English_numerals) .
500
[ { "input": "6", "output": "six" }, { "input": "99", "output": "ninety-nine" }, { "input": "20", "output": "twenty" }, { "input": "10", "output": "ten" }, { "input": "15", "output": "fifteen" }, { "input": "27", "output": "twenty-seven" }, { ...
1,627,849,693
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
#include<iostream> #include<string> using namespace std; int main() { string s, out = ""; cin >> s; string num1[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; string num2[] = {"", "", "twen", "thir", "for", "fif", "six", "seven", "eight", "nine"}; if(s.length() == 1) cout << num1[stoi(s)]; else { if(s[0] != '1') cout << num2[s[0] - '0'] << "ty" << (s[1] - '0' != 0 ? "-" + num1[s[1] - '0'] : ""); else { if(s == "10") cout << "ten"; else if(s == "11") cout << "eleven"; else if(s == "12") cout << "twelve"; else if(s == "13") cout << "thirteen"; else if(s == "14") cout << "fourteen"; else if(s == "15") cout << "fifteen"; else cout << num1[s[1] - '0'] << "teen"; } } }
Title: Tavas and Nafas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input Specification: The first and only line of input contains an integer *s* (0<=≤<=*s*<=≤<=99), Tavas's score. Output Specification: In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Demo Input: ['6\n', '99\n', '20\n'] Demo Output: ['six\n', 'ninety-nine\n', 'twenty\n'] Note: You can find all you need to know about English numerals in [http://en.wikipedia.org/wiki/English_numerals](https://en.wikipedia.org/wiki/English_numerals) .
```python #include<iostream> #include<string> using namespace std; int main() { string s, out = ""; cin >> s; string num1[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; string num2[] = {"", "", "twen", "thir", "for", "fif", "six", "seven", "eight", "nine"}; if(s.length() == 1) cout << num1[stoi(s)]; else { if(s[0] != '1') cout << num2[s[0] - '0'] << "ty" << (s[1] - '0' != 0 ? "-" + num1[s[1] - '0'] : ""); else { if(s == "10") cout << "ten"; else if(s == "11") cout << "eleven"; else if(s == "12") cout << "twelve"; else if(s == "13") cout << "thirteen"; else if(s == "14") cout << "fourteen"; else if(s == "15") cout << "fifteen"; else cout << num1[s[1] - '0'] << "teen"; } } } ```
-1
276
B
Little Girl and Game
PROGRAMMING
1,300
[ "games", "greedy" ]
null
null
The Little Girl loves problems on games very much. Here's one of them. Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules: - The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.
The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters.
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
[ "aba\n", "abca\n" ]
[ "First\n", "Second\n" ]
none
1,000
[ { "input": "aba", "output": "First" }, { "input": "abca", "output": "Second" }, { "input": "aabb", "output": "First" }, { "input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo", "output": "Second" }, { "input": "gevqgtaorjixsxnbcoybr", "output": "First" }, { "i...
1,692,192,291
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
a=input() if a!=a[::-1]: print("Second") else: if len(a)%2==1: print("First") else: print("Second")
Title: Little Girl and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Girl loves problems on games very much. Here's one of them. Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules: - The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second. Input Specification: The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters. Output Specification: In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes. Demo Input: ['aba\n', 'abca\n'] Demo Output: ['First\n', 'Second\n'] Note: none
```python a=input() if a!=a[::-1]: print("Second") else: if len(a)%2==1: print("First") else: print("Second") ```
0
17
A
Noldbach problem
PROGRAMMING
1,000
[ "brute force", "math", "number theory" ]
A. Noldbach problem
2
64
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least *k* prime numbers from 2 to *n* inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1. Two prime numbers are called neighboring if there are no other prime numbers between them. You are to help Nick, and find out if he is right or wrong.
The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000).
Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO.
[ "27 2\n", "45 7\n" ]
[ "YES", "NO" ]
In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.
0
[ { "input": "27 2", "output": "YES" }, { "input": "45 7", "output": "NO" }, { "input": "2 0", "output": "YES" }, { "input": "15 1", "output": "YES" }, { "input": "17 1", "output": "YES" }, { "input": "34 5", "output": "NO" }, { "input": "37 ...
1,609,234,775
2,147,483,647
PyPy 3
OK
TESTS
35
312
1,638,400
def nik(rud,panda): temp = [] c = 0 for i in range(2,rud+1): if all(i%j!=0 for j in temp): temp.append(i) for i in range(len(temp)-1): if 1+temp[i]+temp[i+1] in temp: c += 1 print("YES")if (c >= panda) else print("NO") rud,panda=map(int,input().strip().split()) nik(rud,panda)
Title: Noldbach problem Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least *k* prime numbers from 2 to *n* inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1. Two prime numbers are called neighboring if there are no other prime numbers between them. You are to help Nick, and find out if he is right or wrong. Input Specification: The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000). Output Specification: Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO. Demo Input: ['27 2\n', '45 7\n'] Demo Output: ['YES', 'NO'] Note: In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.
```python def nik(rud,panda): temp = [] c = 0 for i in range(2,rud+1): if all(i%j!=0 for j in temp): temp.append(i) for i in range(len(temp)-1): if 1+temp[i]+temp[i+1] in temp: c += 1 print("YES")if (c >= panda) else print("NO") rud,panda=map(int,input().strip().split()) nik(rud,panda) ```
3.909793
0
none
none
none
0
[ "none" ]
null
null
After the Search Ultimate program that searched for strings in a text failed, Igor K. got to think: "Why on Earth does my program work so slowly?" As he double-checked his code, he said: "My code contains no errors, yet I know how we will improve Search Ultimate!" and took a large book from the shelves. The book read "Azembler. Principally New Approach". Having carefully thumbed through the book, Igor K. realised that, as it turns out, you can multiply the numbers dozens of times faster. "Search Ultimate will be faster than it has ever been!" — the fellow shouted happily and set to work. Let us now clarify what Igor's idea was. The thing is that the code that was generated by a compiler was far from perfect. Standard multiplying does work slower than with the trick the book mentioned. The Azembler language operates with 26 registers (eax, ebx, ..., ezx) and two commands: - [*x*] — returns the value located in the address *x*. For example, [eax] returns the value that was located in the address, equal to the value in the register eax. - lea *x*, *y* — assigns to the register *x*, indicated as the first operand, the second operand's address. Thus, for example, the "lea ebx, [eax]" command will write in the ebx register the content of the eax register: first the [eax] operation will be fulfilled, the result of it will be some value that lies in the address written in eax. But we do not need the value — the next operation will be lea, that will take the [eax] address, i.e., the value in the eax register, and will write it in ebx. On the first thought the second operation seems meaningless, but as it turns out, it is acceptable to write the operation as lea ecx, [eax + ebx], lea ecx, [k*eax] or even lea ecx, [ebx + k*eax], where k = 1, 2, 4 or 8. As a result, the register ecx will be equal to the numbers eax + ebx, k*eax and ebx + k*eax correspondingly. However, such operation is fulfilled many times, dozens of times faster that the usual multiplying of numbers. And using several such operations, one can very quickly multiply some number by some other one. Of course, instead of eax, ebx and ecx you are allowed to use any registers. For example, let the eax register contain some number that we should multiply by 41. It takes us 2 lines: lea ebx, [eax + 4*eax] // now ebx = 5*eax lea eax, [eax + 8*ebx] // now eax = eax + 8*ebx = 41*eax Igor K. got interested in the following question: what is the minimum number of lea operations needed to multiply by the given number *n* and how to do it? Your task is to help him. Consider that at the initial moment of time eax contains a number that Igor K. was about to multiply by *n*, and the registers from ebx to ezx contain number 0. At the final moment of time the result can be located in any register.
The input data contain the only integer *n* (1<=≤<=*n*<=≤<=255), which Igor K. is about to multiply.
On the first line print number *p*, which represents the minimum number of lea operations, needed to do that. Then print the program consisting of *p* commands, performing the operations. It is guaranteed that such program exists for any *n* from 1 to 255. Use precisely the following format of commands (here *k* is equal to 1, 2, 4 or 8, and *x*, *y* and *z* are any, even coinciding registers): lea x, [y] lea x, [y + z] lea x, [k*y] lea x, [y + k*z] Please note that extra spaces at the end of a command are unacceptable.
[ "41\n", "2\n", "4\n" ]
[ "2\nlea ebx, [eax + 4*eax]\nlea ecx, [eax + 8*ebx]\n", "1\nlea ebx, [eax + eax]\n", "1\nlea ebx, [4*eax]\n" ]
none
0
[]
1,603,466,695
6,295
PyPy 3
WRONG_ANSWER
TESTS
3
280
1,228,800
import sys from array import array # noqa: F401 from itertools import product def input(): return sys.stdin.buffer.readline().decode('utf-8') n = int(input()) if n == 1: print(0) exit() inf = 10**9 dp = [inf] * (n + 1) dp[1] = 0 prev = [[-1, -1, -1, -1] for _ in range(n + 1)] def ok(): path = [] used_num = {n} stack = [n] while stack: z = stack.pop() if z == 1: continue x, mx, y, my = prev[z] path.append([x, mx, y, my, z]) if x not in used_num: used_num.add(x) stack.append(x) if y != -1 and y not in used_num: used_num.add(y) stack.append(y) register_name = {x: f'e{chr(97+i)}x' for i, x in enumerate(sorted(used_num))} ans = [] used = [0] * len(path) for ub in sorted(used_num): for i, (x, mx, y, my, z) in enumerate(path): if not used[i] and max(x, y, z) <= ub: if y == -1: ans.append(f'lea {register_name[z]}, [{str(mx)+"*" if mx > 1 else ""}{register_name[x]}]') else: ans.append(f'lea {register_name[z]}, [{str(mx)+"*" if mx > 1 else ""}{register_name[x]} + {str(my)+"*" if my > 1 else ""}{register_name[y]}]') used[i] = 1 print(len(ans)) print('\n'.join(ans)) exit() while True: next_dp = dp[:] for x in range(1, n): if dp[x] == inf: continue for m in (2, 4, 8): if x * m <= n and next_dp[x * m] > dp[x] + 1: next_dp[x * m] = dp[x] + 1 prev[x * m] = [x, m, -1, -1] for y in range(1, n): if dp[y] == inf: continue for mx, my in product((1, 2, 4, 8), repeat=2): if x * mx + y * my <= n and next_dp[x * mx + y * my] > dp[x] + dp[y] + 1: next_dp[x * mx + y * my] = dp[x] + dp[y] + 1 prev[x * mx + y * my] = [x, mx, y, my] dp = next_dp if dp[n] != inf: ok()
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: After the Search Ultimate program that searched for strings in a text failed, Igor K. got to think: "Why on Earth does my program work so slowly?" As he double-checked his code, he said: "My code contains no errors, yet I know how we will improve Search Ultimate!" and took a large book from the shelves. The book read "Azembler. Principally New Approach". Having carefully thumbed through the book, Igor K. realised that, as it turns out, you can multiply the numbers dozens of times faster. "Search Ultimate will be faster than it has ever been!" — the fellow shouted happily and set to work. Let us now clarify what Igor's idea was. The thing is that the code that was generated by a compiler was far from perfect. Standard multiplying does work slower than with the trick the book mentioned. The Azembler language operates with 26 registers (eax, ebx, ..., ezx) and two commands: - [*x*] — returns the value located in the address *x*. For example, [eax] returns the value that was located in the address, equal to the value in the register eax. - lea *x*, *y* — assigns to the register *x*, indicated as the first operand, the second operand's address. Thus, for example, the "lea ebx, [eax]" command will write in the ebx register the content of the eax register: first the [eax] operation will be fulfilled, the result of it will be some value that lies in the address written in eax. But we do not need the value — the next operation will be lea, that will take the [eax] address, i.e., the value in the eax register, and will write it in ebx. On the first thought the second operation seems meaningless, but as it turns out, it is acceptable to write the operation as lea ecx, [eax + ebx], lea ecx, [k*eax] or even lea ecx, [ebx + k*eax], where k = 1, 2, 4 or 8. As a result, the register ecx will be equal to the numbers eax + ebx, k*eax and ebx + k*eax correspondingly. However, such operation is fulfilled many times, dozens of times faster that the usual multiplying of numbers. And using several such operations, one can very quickly multiply some number by some other one. Of course, instead of eax, ebx and ecx you are allowed to use any registers. For example, let the eax register contain some number that we should multiply by 41. It takes us 2 lines: lea ebx, [eax + 4*eax] // now ebx = 5*eax lea eax, [eax + 8*ebx] // now eax = eax + 8*ebx = 41*eax Igor K. got interested in the following question: what is the minimum number of lea operations needed to multiply by the given number *n* and how to do it? Your task is to help him. Consider that at the initial moment of time eax contains a number that Igor K. was about to multiply by *n*, and the registers from ebx to ezx contain number 0. At the final moment of time the result can be located in any register. Input Specification: The input data contain the only integer *n* (1<=≤<=*n*<=≤<=255), which Igor K. is about to multiply. Output Specification: On the first line print number *p*, which represents the minimum number of lea operations, needed to do that. Then print the program consisting of *p* commands, performing the operations. It is guaranteed that such program exists for any *n* from 1 to 255. Use precisely the following format of commands (here *k* is equal to 1, 2, 4 or 8, and *x*, *y* and *z* are any, even coinciding registers): lea x, [y] lea x, [y + z] lea x, [k*y] lea x, [y + k*z] Please note that extra spaces at the end of a command are unacceptable. Demo Input: ['41\n', '2\n', '4\n'] Demo Output: ['2\nlea ebx, [eax + 4*eax]\nlea ecx, [eax + 8*ebx]\n', '1\nlea ebx, [eax + eax]\n', '1\nlea ebx, [4*eax]\n'] Note: none
```python import sys from array import array # noqa: F401 from itertools import product def input(): return sys.stdin.buffer.readline().decode('utf-8') n = int(input()) if n == 1: print(0) exit() inf = 10**9 dp = [inf] * (n + 1) dp[1] = 0 prev = [[-1, -1, -1, -1] for _ in range(n + 1)] def ok(): path = [] used_num = {n} stack = [n] while stack: z = stack.pop() if z == 1: continue x, mx, y, my = prev[z] path.append([x, mx, y, my, z]) if x not in used_num: used_num.add(x) stack.append(x) if y != -1 and y not in used_num: used_num.add(y) stack.append(y) register_name = {x: f'e{chr(97+i)}x' for i, x in enumerate(sorted(used_num))} ans = [] used = [0] * len(path) for ub in sorted(used_num): for i, (x, mx, y, my, z) in enumerate(path): if not used[i] and max(x, y, z) <= ub: if y == -1: ans.append(f'lea {register_name[z]}, [{str(mx)+"*" if mx > 1 else ""}{register_name[x]}]') else: ans.append(f'lea {register_name[z]}, [{str(mx)+"*" if mx > 1 else ""}{register_name[x]} + {str(my)+"*" if my > 1 else ""}{register_name[y]}]') used[i] = 1 print(len(ans)) print('\n'.join(ans)) exit() while True: next_dp = dp[:] for x in range(1, n): if dp[x] == inf: continue for m in (2, 4, 8): if x * m <= n and next_dp[x * m] > dp[x] + 1: next_dp[x * m] = dp[x] + 1 prev[x * m] = [x, m, -1, -1] for y in range(1, n): if dp[y] == inf: continue for mx, my in product((1, 2, 4, 8), repeat=2): if x * mx + y * my <= n and next_dp[x * mx + y * my] > dp[x] + dp[y] + 1: next_dp[x * mx + y * my] = dp[x] + dp[y] + 1 prev[x * mx + y * my] = [x, mx, y, my] dp = next_dp if dp[n] != inf: ok() ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,553,501,529
2,147,483,647
Python 3
OK
TESTS
30
218
0
k = 0 x = input() for i in range(len(x)): if ord(x[i]) >= 65 and ord(x[i]) < 97: k = k + 1 if k > int(len(x)/2): r = x.upper() else: r = x.lower() print(r)
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python k = 0 x = input() for i in range(len(x)): if ord(x[i]) >= 65 and ord(x[i]) < 97: k = k + 1 if k > int(len(x)/2): r = x.upper() else: r = x.lower() print(r) ```
3.9455
712
A
Memory and Crow
PROGRAMMING
800
[ "implementation", "math" ]
null
null
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure: - The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3.... Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it?
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row. The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number.
Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type.
[ "5\n6 -4 8 -2 3\n", "5\n3 -2 -1 5 6\n" ]
[ "2 4 6 1 3 \n", "1 -3 4 11 6 \n" ]
In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and  - 4 = 4 - 6 + 1 - 3. In the second sample test, the sequence 1,  - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.
500
[ { "input": "5\n6 -4 8 -2 3", "output": "2 4 6 1 3 " }, { "input": "5\n3 -2 -1 5 6", "output": "1 -3 4 11 6 " }, { "input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10", "output": "11 530 469 -86 -86 -127 -87 -11 22 10 " }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "0 0...
1,473,661,081
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> == RESTART: C:/Users/Andy/AppData/Local/Programs/Python/Python35/Zadachi.py == 5 6 -4 8 -2 3 2 4 6 1 >>> == RESTART: C:/Users/Andy/AppData/Local/Programs/Python/Python35/Zadachi.py == 5 6 -4 8 -2 3 2 4 6 1 3 >>> == RESTART: C:/Users/Andy/AppData/Local/Programs/Python/Python35/Zadachi.py == 5 3 -2 -1 5 6 1 -3 4 11 6 >>>
Title: Memory and Crow Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure: - The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3.... Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it? Input Specification: The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row. The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. Output Specification: Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. Demo Input: ['5\n6 -4 8 -2 3\n', '5\n3 -2 -1 5 6\n'] Demo Output: ['2 4 6 1 3 \n', '1 -3 4 11 6 \n'] Note: In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and  - 4 = 4 - 6 + 1 - 3. In the second sample test, the sequence 1,  - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.
```python Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> == RESTART: C:/Users/Andy/AppData/Local/Programs/Python/Python35/Zadachi.py == 5 6 -4 8 -2 3 2 4 6 1 >>> == RESTART: C:/Users/Andy/AppData/Local/Programs/Python/Python35/Zadachi.py == 5 6 -4 8 -2 3 2 4 6 1 3 >>> == RESTART: C:/Users/Andy/AppData/Local/Programs/Python/Python35/Zadachi.py == 5 3 -2 -1 5 6 1 -3 4 11 6 >>> ```
-1
902
A
Visiting a Friend
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point *m* on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport. Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds. Determine if Pig can visit the friend using teleports only, or he should use his car.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house. The next *n* lines contain information about teleports. The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit. It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*).
Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "3 5\n0 2\n2 4\n3 5\n", "3 7\n0 4\n2 5\n6 7\n" ]
[ "YES\n", "NO\n" ]
The first example is shown on the picture below: Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives. The second example is shown on the picture below: You can see that there is no path from Pig's house to his friend's house that uses only teleports.
500
[ { "input": "3 5\n0 2\n2 4\n3 5", "output": "YES" }, { "input": "3 7\n0 4\n2 5\n6 7", "output": "NO" }, { "input": "1 1\n0 0", "output": "NO" }, { "input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7...
1,534,473,923
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
108
0
"""Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point m on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport. Formally, a teleport located at point x with limit y can move Pig from point x to any point within the segment [x; y], including the bounds. Determine if Pig can visit the friend using teleports only, or he should use his car. Input The first line contains two integers n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of teleports and the location of the friend's house. The next n lines contain information about teleports. The i-th of these lines contains two integers ai and bi (0 ≤ ai ≤ bi ≤ m), where ai is the location of the i-th teleport, and bi is its limit. It is guaranteed that ai ≥ ai - 1 for every i (2 ≤ i ≤ n). Output Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).""" a=[int(x) for x in input().split()] l=[i for i in range(a[0])] l[0]=[int(x) for x in input().split()] if l[0][0]!=0: print('NO') else: for i in range(1,a[0]): l[i]=[int(x) for x in input().split()] if l[i][0]>sum(l[i-1]): print('NO') break else: if i==(a[0]-1): if sum(l[i])>=l[0][1]: print('YES') else: print('NO')
Title: Visiting a Friend Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point *m* on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport. Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds. Determine if Pig can visit the friend using teleports only, or he should use his car. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house. The next *n* lines contain information about teleports. The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit. It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*). Output Specification: Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower). Demo Input: ['3 5\n0 2\n2 4\n3 5\n', '3 7\n0 4\n2 5\n6 7\n'] Demo Output: ['YES\n', 'NO\n'] Note: The first example is shown on the picture below: Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives. The second example is shown on the picture below: You can see that there is no path from Pig's house to his friend's house that uses only teleports.
```python """Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point m on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport. Formally, a teleport located at point x with limit y can move Pig from point x to any point within the segment [x; y], including the bounds. Determine if Pig can visit the friend using teleports only, or he should use his car. Input The first line contains two integers n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of teleports and the location of the friend's house. The next n lines contain information about teleports. The i-th of these lines contains two integers ai and bi (0 ≤ ai ≤ bi ≤ m), where ai is the location of the i-th teleport, and bi is its limit. It is guaranteed that ai ≥ ai - 1 for every i (2 ≤ i ≤ n). Output Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).""" a=[int(x) for x in input().split()] l=[i for i in range(a[0])] l[0]=[int(x) for x in input().split()] if l[0][0]!=0: print('NO') else: for i in range(1,a[0]): l[i]=[int(x) for x in input().split()] if l[i][0]>sum(l[i-1]): print('NO') break else: if i==(a[0]-1): if sum(l[i])>=l[0][1]: print('YES') else: print('NO') ```
0
43
C
Lucky Tickets
PROGRAMMING
1,300
[ "greedy" ]
C. Lucky Tickets
2
256
Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every ticket exactly in two, but he didn’t think it was enough and Leonid also threw part of the pieces away. Having seen this, Vasya got terrified but still tried to restore the collection. He chose several piece pairs and glued each pair together so that each pair formed a lucky ticket. The rest of the pieces Vasya threw away reluctantly. Thus, after the gluing of the 2*t* pieces he ended up with *t* tickets, each of which was lucky. When Leonid tore the tickets in two pieces, one piece contained the first several letters of his number and the second piece contained the rest. Vasya can glue every pair of pieces in any way he likes, but it is important that he gets a lucky ticket in the end. For example, pieces 123 and 99 can be glued in two ways: 12399 and 99123. What maximum number of tickets could Vasya get after that?
The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of pieces. The second line contains *n* space-separated numbers *a**i* (1<=≤<=*a**i*<=≤<=108) — the numbers on the pieces. Vasya can only glue the pieces in pairs. Even if the number of a piece is already lucky, Vasya should glue the piece with some other one for it to count as lucky. Vasya does not have to use all the pieces. The numbers on the pieces an on the resulting tickets may coincide.
Print the single number — the maximum number of lucky tickets that will be able to be restored. Don't forget that every lucky ticket is made of exactly two pieces glued together.
[ "3\n123 123 99\n", "6\n1 1 1 23 10 3\n" ]
[ "1\n", "1\n" ]
none
1,500
[ { "input": "3\n123 123 99", "output": "1" }, { "input": "6\n1 1 1 23 10 3", "output": "1" }, { "input": "3\n43440907 58238452 82582355", "output": "1" }, { "input": "4\n31450303 81222872 67526764 17516401", "output": "1" }, { "input": "5\n83280 20492640 21552119 7...
1,660,080,056
2,147,483,647
Python 3
OK
TESTS
21
92
716,800
input() tickets = [int(i) for i in input().split()] tickets1 = [] tickets2 = [] tickets3 = [] for k in tickets: if k % 3 == 0: tickets3.append(k) elif k % 3 == 1: tickets1.append(k) else: tickets2.append(k) print(min(len(tickets1), len(tickets2)) + int(len(tickets3) / 2))
Title: Lucky Tickets Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every ticket exactly in two, but he didn’t think it was enough and Leonid also threw part of the pieces away. Having seen this, Vasya got terrified but still tried to restore the collection. He chose several piece pairs and glued each pair together so that each pair formed a lucky ticket. The rest of the pieces Vasya threw away reluctantly. Thus, after the gluing of the 2*t* pieces he ended up with *t* tickets, each of which was lucky. When Leonid tore the tickets in two pieces, one piece contained the first several letters of his number and the second piece contained the rest. Vasya can glue every pair of pieces in any way he likes, but it is important that he gets a lucky ticket in the end. For example, pieces 123 and 99 can be glued in two ways: 12399 and 99123. What maximum number of tickets could Vasya get after that? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of pieces. The second line contains *n* space-separated numbers *a**i* (1<=≤<=*a**i*<=≤<=108) — the numbers on the pieces. Vasya can only glue the pieces in pairs. Even if the number of a piece is already lucky, Vasya should glue the piece with some other one for it to count as lucky. Vasya does not have to use all the pieces. The numbers on the pieces an on the resulting tickets may coincide. Output Specification: Print the single number — the maximum number of lucky tickets that will be able to be restored. Don't forget that every lucky ticket is made of exactly two pieces glued together. Demo Input: ['3\n123 123 99\n', '6\n1 1 1 23 10 3\n'] Demo Output: ['1\n', '1\n'] Note: none
```python input() tickets = [int(i) for i in input().split()] tickets1 = [] tickets2 = [] tickets3 = [] for k in tickets: if k % 3 == 0: tickets3.append(k) elif k % 3 == 1: tickets1.append(k) else: tickets2.append(k) print(min(len(tickets1), len(tickets2)) + int(len(tickets3) / 2)) ```
3.975665
610
A
Pasha and Stick
PROGRAMMING
1,000
[ "combinatorics", "math" ]
null
null
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick.
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
[ "6\n", "20\n" ]
[ "1\n", "4\n" ]
There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
500
[ { "input": "6", "output": "1" }, { "input": "20", "output": "4" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "2000000000", "output": "4...
1,586,093,986
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
1,000
0
n = int(input())//2 i = 1 count = 0 while i < n-i: count += 1 i += 1 print(count)
Title: Pasha and Stick Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way. Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. Output Specification: The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. Demo Input: ['6\n', '20\n'] Demo Output: ['1\n', '4\n'] Note: There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
```python n = int(input())//2 i = 1 count = 0 while i < n-i: count += 1 i += 1 print(count) ```
0
0
none
none
none
0
[ "none" ]
null
null
The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph *G*. It is required to find a subset of vertices *C* of the maximum size such that any two of them are connected by an edge in graph *G*. Sounds simple, doesn't it? Nobody yet knows an algorithm that finds a solution to this problem in polynomial time of the size of the graph. However, as with many other NP-complete problems, the clique problem is easier if you consider a specific type of a graph. Consider *n* distinct points on a line. Let the *i*-th point have the coordinate *x**i* and weight *w**i*. Let's form graph *G*, whose vertices are these points and edges connect exactly the pairs of points (*i*,<=*j*), such that the distance between them is not less than the sum of their weights, or more formally: |*x**i*<=-<=*x**j*|<=≥<=*w**i*<=+<=*w**j*. Find the size of the maximum clique in such graph.
The first line contains the integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of points. Each of the next *n* lines contains two numbers *x**i*, *w**i* (0<=≤<=*x**i*<=≤<=109,<=1<=≤<=*w**i*<=≤<=109) — the coordinate and the weight of a point. All *x**i* are different.
Print a single number — the number of vertexes in the maximum clique of the given graph.
[ "4\n2 3\n3 1\n6 1\n0 2\n" ]
[ "3\n" ]
If you happen to know how to solve this problem without using the specific properties of the graph formulated in the problem statement, then you are able to get a prize of one million dollars! The picture for the sample test.
0
[ { "input": "4\n2 3\n3 1\n6 1\n0 2", "output": "3" }, { "input": "1\n42 23", "output": "1" }, { "input": "2\n1 5\n2 6", "output": "1" }, { "input": "2\n1 5\n12 6", "output": "2" }, { "input": "1\n0 1", "output": "1" }, { "input": "1\n1000000000 10000000...
1,566,434,569
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n = int(input()) XW = [] for i in range(n): XW.append(list(map(int, input().split())) XW = sorted(XW, key=lambda x: x[0], reversed = True) count = 0 for i in range(n): for j in range(i+1, n): if XW[i][0] >= XI[j][0]+XW[i][1]+XW[j][1]: count += 1 print(count)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph *G*. It is required to find a subset of vertices *C* of the maximum size such that any two of them are connected by an edge in graph *G*. Sounds simple, doesn't it? Nobody yet knows an algorithm that finds a solution to this problem in polynomial time of the size of the graph. However, as with many other NP-complete problems, the clique problem is easier if you consider a specific type of a graph. Consider *n* distinct points on a line. Let the *i*-th point have the coordinate *x**i* and weight *w**i*. Let's form graph *G*, whose vertices are these points and edges connect exactly the pairs of points (*i*,<=*j*), such that the distance between them is not less than the sum of their weights, or more formally: |*x**i*<=-<=*x**j*|<=≥<=*w**i*<=+<=*w**j*. Find the size of the maximum clique in such graph. Input Specification: The first line contains the integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of points. Each of the next *n* lines contains two numbers *x**i*, *w**i* (0<=≤<=*x**i*<=≤<=109,<=1<=≤<=*w**i*<=≤<=109) — the coordinate and the weight of a point. All *x**i* are different. Output Specification: Print a single number — the number of vertexes in the maximum clique of the given graph. Demo Input: ['4\n2 3\n3 1\n6 1\n0 2\n'] Demo Output: ['3\n'] Note: If you happen to know how to solve this problem without using the specific properties of the graph formulated in the problem statement, then you are able to get a prize of one million dollars! The picture for the sample test.
```python n = int(input()) XW = [] for i in range(n): XW.append(list(map(int, input().split())) XW = sorted(XW, key=lambda x: x[0], reversed = True) count = 0 for i in range(n): for j in range(i+1, n): if XW[i][0] >= XI[j][0]+XW[i][1]+XW[j][1]: count += 1 print(count) ```
-1