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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,693,050,788 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 124 | 0 | n = int(input())
nums = list(map(int, input().split()))
evens = [i for i in nums if i % 2 == 0]
odds = [i for i in nums if i % 2 == 1]
print(nums.index(evens[0] if len(evens) == 1 else odds[0]) + 1)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
nums = list(map(int, input().split()))
evens = [i for i in nums if i % 2 == 0]
odds = [i for i in nums if i % 2 == 1]
print(nums.index(evens[0] if len(evens) == 1 else odds[0]) + 1)
``` | 3.969 |
559 | B | Equivalent Strings | PROGRAMMING | 1,700 | [
"divide and conquer",
"hashing",
"sortings",
"strings"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 1,000 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,625,852,719 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 61 | 409,600 | from string import ascii_lowercase as alphabet
def check(obj):
char = obj[:1]
return alphabet.index(char)
def equal(a, b):
if a == b:
return True
elif len(a) % 2 == 0 and len(b) % 2 == 0:
leng = int(len(a)/2)
piece_a1 = a[:leng]
piece_a2 = a[leng:]
... | Title: Equivalent Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split str... | ```python
from string import ascii_lowercase as alphabet
def check(obj):
char = obj[:1]
return alphabet.index(char)
def equal(a, b):
if a == b:
return True
elif len(a) % 2 == 0 and len(b) % 2 == 0:
leng = int(len(a)/2)
piece_a1 = a[:leng]
piece_a2 = a[le... | 0 | |
399 | A | Pages | PROGRAMMING | 0 | [
"implementation"
] | null | null | User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and wh... | The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*) | Print the proper navigation. Follow the format of the output from the test samples. | [
"17 5 2\n",
"6 5 2\n",
"6 1 2\n",
"6 2 2\n",
"9 6 3\n",
"10 6 3\n",
"8 5 4\n"
] | [
"<< 3 4 (5) 6 7 >> ",
"<< 3 4 (5) 6 ",
"(1) 2 3 >> ",
"1 (2) 3 4 >>",
"<< 3 4 5 (6) 7 8 9",
"<< 3 4 5 (6) 7 8 9 >>",
"1 2 3 4 (5) 6 7 8 "
] | none | 500 | [
{
"input": "17 5 2",
"output": "<< 3 4 (5) 6 7 >> "
},
{
"input": "6 5 2",
"output": "<< 3 4 (5) 6 "
},
{
"input": "6 1 2",
"output": "(1) 2 3 >> "
},
{
"input": "6 2 2",
"output": "1 (2) 3 4 >> "
},
{
"input": "9 6 3",
"output": "<< 3 4 5 (6) 7 8 9 "
},
{... | 1,553,789,670 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 108 | 0 | if __name__ == '__main__':
[n, p, k] = [int(x) for x in input().split()]
navigation = []
if (p - k) > 1:
navigation.append('<<')
navigation += [str(x) for x in range(max(p - k, 1), p)]
navigation.append('(%i)' % p)
navigation += [str(x) for x in range(p + 1, min(p + k + 1, n + 1))]
... | Title: Pages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will lo... | ```python
if __name__ == '__main__':
[n, p, k] = [int(x) for x in input().split()]
navigation = []
if (p - k) > 1:
navigation.append('<<')
navigation += [str(x) for x in range(max(p - k, 1), p)]
navigation.append('(%i)' % p)
navigation += [str(x) for x in range(p + 1, min(p + k + 1, n ... | 3 | |
952 | E | Cheese Board | PROGRAMMING | 2,000 | [] | null | null | Not to be confused with [chessboard](https://en.wikipedia.org/wiki/Chessboard). | The first line of input contains a single integer *N* (1<=≤<=*N*<=≤<=100) — the number of cheeses you have.
The next *N* lines describe the cheeses you have. Each line contains two space-separated strings: the name of the cheese and its type. The name is a string of lowercase English letters between 1 and 10 character... | Output a single number. | [
"9\nbrie soft\ncamembert soft\nfeta soft\ngoat soft\nmuenster soft\nasiago hard\ncheddar hard\ngouda hard\nswiss hard\n",
"6\nparmesan hard\nemmental hard\nedam hard\ncolby hard\ngruyere hard\nasiago hard\n"
] | [
"3\n",
"4\n"
] | none | 0 | [
{
"input": "9\nbrie soft\ncamembert soft\nfeta soft\ngoat soft\nmuenster soft\nasiago hard\ncheddar hard\ngouda hard\nswiss hard",
"output": "3"
},
{
"input": "6\nparmesan hard\nemmental hard\nedam hard\ncolby hard\ngruyere hard\nasiago hard",
"output": "4"
},
{
"input": "9\ngorgonzola s... | 1,554,094,655 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 140 | 0 | n=int(input())
ans=0
for i in range(0,n):
a,b=input().split()
if b=='hard':
ans+=1
print(ans) | Title: Cheese Board
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Not to be confused with [chessboard](https://en.wikipedia.org/wiki/Chessboard).
Input Specification:
The first line of input contains a single integer *N* (1<=≤<=*N*<=≤<=100) — the number of cheeses you have.
The next *N... | ```python
n=int(input())
ans=0
for i in range(0,n):
a,b=input().split()
if b=='hard':
ans+=1
print(ans)
``` | 0 | |
651 | B | Beautiful Paintings | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy ... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of painting.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where *a**i* means the beauty of the *i*-th painting. | Print one integer — the maximum possible number of neighbouring pairs, such that *a**i*<=+<=1<=><=*a**i*, after the optimal rearrangement. | [
"5\n20 30 10 50 40\n",
"4\n200 100 100 200\n"
] | [
"4\n",
"2\n"
] | In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | 1,000 | [
{
"input": "5\n20 30 10 50 40",
"output": "4"
},
{
"input": "4\n200 100 100 200",
"output": "2"
},
{
"input": "10\n2 2 2 2 2 2 2 2 2 2",
"output": "0"
},
{
"input": "1\n1000",
"output": "0"
},
{
"input": "2\n444 333",
"output": "1"
},
{
"input": "100\n... | 1,648,823,655 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 93 | 1,740,800 | from collections import Counter
n = int(input())
a = sorted([int(i) for i in input().split()])
cnt = Counter(a)
res = []
for i in range(max(cnt.values())):
for key in cnt :
if cnt[key] != 0 : res.append(key); cnt[key] -= 1
ans = 0
for i in range(1, n) :
if res[i] > res[i-1] : ans... | Title: Beautiful Paintings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to a... | ```python
from collections import Counter
n = int(input())
a = sorted([int(i) for i in input().split()])
cnt = Counter(a)
res = []
for i in range(max(cnt.values())):
for key in cnt :
if cnt[key] != 0 : res.append(key); cnt[key] -= 1
ans = 0
for i in range(1, n) :
if res[i] > res[... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane ar... | The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. | Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. | [
"4 3 9\n",
"4 3 24\n",
"2 4 4\n"
] | [
"2 2 L\n",
"4 3 R\n",
"1 2 R\n"
] | The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.
In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his pla... | 0 | [
{
"input": "4 3 9",
"output": "2 2 L"
},
{
"input": "4 3 24",
"output": "4 3 R"
},
{
"input": "2 4 4",
"output": "1 2 R"
},
{
"input": "3 10 24",
"output": "2 2 R"
},
{
"input": "10 3 59",
"output": "10 3 L"
},
{
"input": "10000 10000 160845880",
"... | 1,482,657,101 | 401 | Python 3 | OK | TESTS | 46 | 109 | 6,246,400 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def main():
n,l,t = list(map(int, input().split()))
a = (t+1)//2
s = 'L' if t%2==1 else 'R'
return ' '.join(map(str, [(a-1)//l+1, (a-1)%l+1, s]))
print... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desk... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def main():
n,l,t = list(map(int, input().split()))
a = (t+1)//2
s = 'L' if t%2==1 else 'R'
return ' '.join(map(str, [(a-1)//l+1, (a-1)%l+1, s])... | 3 | |
51 | A | Cheaterius's Problem | PROGRAMMING | 1,300 | [
"implementation"
] | A. Cheaterius's Problem | 2 | 256 | Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000), where *n* is the number of amulets. Then the amulet's descriptions are contained. Every description occupies two lines and contains two numbers (from 1 to 6) in each line. Between every pair of amulets the line "**" is located. | Print the required number of piles. | [
"4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13\n",
"4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53\n"
] | [
"1\n",
"2\n"
] | none | 500 | [
{
"input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13",
"output": "1"
},
{
"input": "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53",
"output": "2"
},
{
"input": "4\n56\n61\n**\n31\n31\n**\n33\n11\n**\n11\n33",
"output": "2"
},
{
"input": "4\n36\n44\n**\n32\n46\n**\n66\n41... | 1,656,150,769 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | n=int(input())
d=set()
for i in range(n):
s=input()+input()[::-1]
if i<n-1:input()
if all(s not in x for x in d):d.add(2*s)
print(len(d)) | Title: Cheaterius's Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive... | ```python
n=int(input())
d=set()
for i in range(n):
s=input()+input()[::-1]
if i<n-1:input()
if all(s not in x for x in d):d.add(2*s)
print(len(d))
``` | 3.977 |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,670,555,082 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 124 | 2,867,200 | x = int(input())
sx = 0
sy = 0
sz = 0
while x > 0:
x, y, z = (int(input()) for _ in range(3))
sx += x
sy += y
sz += z
x -=1
if (sx == 0) and (sy == 0) and (sz == 0):
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
x = int(input())
sx = 0
sy = 0
sz = 0
while x > 0:
x, y, z = (int(input()) for _ in range(3))
sx += x
sy += y
sz += z
x -=1
if (sx == 0) and (sy == 0) and (sz == 0):
print("YES")
else:
print("NO")
``` | -1 |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,604,878,930 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 280 | 0 | import sys
s = sys.stdin.read().strip()
d = sum(i.islower() or -1 for i in s)
print(d < 0 and s.upper() or s.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
import sys
s = sys.stdin.read().strip()
d = sum(i.islower() or -1 for i in s)
print(d < 0 and s.upper() or s.lower())
``` | 3.93 |
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 ... | 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 ... | 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,558,701,069 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 20 | 2,000 | 409,600 | n = int(input())
s = input()
key_list = []
k = 0
for i in range(0, 2*n-2, 2):
if s[i] != s[i+1].lower():
key_list.append(s[i])
if s[i+1].lower() in key_list:
key_list.remove(s[i+1].lower())
else:
k += 1
print(k)
| 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... | ```python
n = int(input())
s = input()
key_list = []
k = 0
for i in range(0, 2*n-2, 2):
if s[i] != s[i+1].lower():
key_list.append(s[i])
if s[i+1].lower() in key_list:
key_list.remove(s[i+1].lower())
else:
k += 1
print(k)
``` | 0 | |
205 | A | Little Elephant and Rozdil | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider t... | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | [
"2\n7 4\n",
"7\n7 4 47 100 4 9 12\n"
] | [
"2\n",
"Still Rozdil\n"
] | In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling t... | 500 | [
{
"input": "2\n7 4",
"output": "2"
},
{
"input": "7\n7 4 47 100 4 9 12",
"output": "Still Rozdil"
},
{
"input": "1\n47",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "Still Rozdil"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "7"
},
{
... | 1,623,928,363 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 218 | 8,192,000 | n=int(input())
a=list(map(int,input().split()))
m=min(a)
print("Still Rozdil" if a.count(m)>1 else a.index(m)+1) | Title: Little Elephant and Rozdil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elepha... | ```python
n=int(input())
a=list(map(int,input().split()))
m=min(a)
print("Still Rozdil" if a.count(m)>1 else a.index(m)+1)
``` | 3 | |
886 | B | Vlad and Cafes | PROGRAMMING | 1,000 | [] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes... | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ... | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in... | 1,000 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000... | 1,557,508,214 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 187 | 1,024,000 | n=int(input())
x=[]
if n==1 and l[0]==0:
print(0)
exit()
if len(set(l))==1 and l[0]==0:
print(0)
exit()
l=list(map(int,input().split()))
for i in range(n):
if l[i] not in x:
x.append(l[i])
else:
break
print(len(x))
| Title: Vlad and Cafes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research... | ```python
n=int(input())
x=[]
if n==1 and l[0]==0:
print(0)
exit()
if len(set(l))==1 and l[0]==0:
print(0)
exit()
l=list(map(int,input().split()))
for i in range(n):
if l[i] not in x:
x.append(l[i])
else:
break
print(len(x))
``` | -1 | |
617 | C | Watering Flowers | PROGRAMMING | 1,600 | [
"implementation"
] | null | null | A flowerbed has many flowers and two fountains.
You can adjust the water pressure and set any values *r*1(*r*1<=≥<=0) and *r*2(*r*2<=≥<=0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such *r*1 and *r*2 that all the flowers are watered, that is, fo... | The first line of the input contains integers *n*, *x*1, *y*1, *x*2, *y*2 (1<=≤<=*n*<=≤<=2000, <=-<=107<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=107) — the number of flowers, the coordinates of the first and the second fountain.
Next follow *n* lines. The *i*-th of these lines contains integers *x**i* and *y**i* (<=-<=107<=≤... | Print the minimum possible value *r*12<=+<=*r*22. Note, that in this problem optimal answer is always integer. | [
"2 -1 0 5 3\n0 2\n5 2\n",
"4 0 0 5 0\n9 4\n8 3\n-1 0\n1 4\n"
] | [
"6\n",
"33\n"
] | The first sample is (*r*<sub class="lower-index">1</sub><sup class="upper-index">2</sup> = 5, *r*<sub class="lower-index">2</sub><sup class="upper-index">2</sup> = 1): <img class="tex-graphics" src="https://espresso.codeforces.com/15e780f508832a19b14698dd8eb54b4c0dd131bf.png" style="max-width: 100.0%;max-height: 100.0%... | 1,250 | [
{
"input": "2 -1 0 5 3\n0 2\n5 2",
"output": "6"
},
{
"input": "4 0 0 5 0\n9 4\n8 3\n-1 0\n1 4",
"output": "33"
},
{
"input": "5 -6 -4 0 10\n-7 6\n-9 7\n-5 -1\n-2 1\n-8 10",
"output": "100"
},
{
"input": "10 -68 10 87 22\n30 89\n82 -97\n-52 25\n76 -22\n-20 95\n21 25\n2 -3\n45... | 1,698,952,193 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 124 | 2,457,600 | import sys
input=sys.stdin.readline
n,x1,y1,x2,y2=map(int,input().split())
l=[]
for _ in range(n):
x,y=map(int,input().split())
l.append([(x-x1)**2+(y-y1)**2,(x-x2)**2+(y-y2)**2])
l.sort(reverse=True)
s=10**18
q=0
for u,v in l:
s=min(s,u+q)
q=max(q,v)
print(min(s,q)) | Title: Watering Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A flowerbed has many flowers and two fountains.
You can adjust the water pressure and set any values *r*1(*r*1<=≥<=0) and *r*2(*r*2<=≥<=0), giving the distances at which the water is spread from the first and second f... | ```python
import sys
input=sys.stdin.readline
n,x1,y1,x2,y2=map(int,input().split())
l=[]
for _ in range(n):
x,y=map(int,input().split())
l.append([(x-x1)**2+(y-y1)**2,(x-x2)**2+(y-y2)**2])
l.sort(reverse=True)
s=10**18
q=0
for u,v in l:
s=min(s,u+q)
q=max(q,v)
print(min(s,q))
``` | 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 ... | 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,594,795,285 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 30,515,200 | def fib(n):
if n<=1:
return 1
return fib(n-1)+fib(n-2)
n=int(input())
a=[]
for i in range(1,n+1):
a.append(fib(i))
for i in range(1,n+1):
if i in a:
print('O',end='')
else:
print('o',end='')
| Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should o... | ```python
def fib(n):
if n<=1:
return 1
return fib(n-1)+fib(n-2)
n=int(input())
a=[]
for i in range(1,n+1):
a.append(fib(i))
for i in range(1,n+1):
if i in a:
print('O',end='')
else:
print('o',end='')
``` | 0 | |
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*... | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
}... | 1,595,439,627 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 218 | 6,963,200 | a = input()
b = input()
c = int(a) + int(b)
na = ""
nb = ""
nc = ""
for i in a:
if i != "0":
na += i
for i in b:
if i != "0":
nb += i
for i in str(c):
if i!="0":
nc += i
if str(int(na)+int(nb)) == nc:
print("YES")
else:
print("NO")
| Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu... | ```python
a = input()
b = input()
c = int(a) + int(b)
na = ""
nb = ""
nc = ""
for i in a:
if i != "0":
na += i
for i in b:
if i != "0":
nb += i
for i in str(c):
if i!="0":
nc += i
if str(int(na)+int(nb)) == nc:
print("YES")
else:
print("NO")
... | 3.93253 |
766 | B | Mahmoud and a Triangle | PROGRAMMING | 1,000 | [
"constructive algorithms",
"geometry",
"greedy",
"math",
"number theory",
"sortings"
] | null | null | Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments... | The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has. | In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise. | [
"5\n1 5 3 2 4\n",
"3\n4 1 2\n"
] | [
"YES\n",
"NO\n"
] | For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle. | 1,000 | [
{
"input": "5\n1 5 3 2 4",
"output": "YES"
},
{
"input": "3\n4 1 2",
"output": "NO"
},
{
"input": "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576",
"output": "NO"
},... | 1,698,207,918 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | ii = lambda: int(input())
il = lambda: map(int, input().split())
def f(l, n):
v = sum(l[-2:])
while n:
t = l.pop()
v -= t
if v+l[-2]>=t:
return "YES"
else:
v += l[-2]
n -= 1
return "NO"
n = ii()
l = sorted(il())
print(f(l, n-2)) | Title: Mahmoud and a Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he ca... | ```python
ii = lambda: int(input())
il = lambda: map(int, input().split())
def f(l, n):
v = sum(l[-2:])
while n:
t = l.pop()
v -= t
if v+l[-2]>=t:
return "YES"
else:
v += l[-2]
n -= 1
return "NO"
n = ii()
l = sorted(il())
print(f(l, n-2))
``` | 0 | |
899 | A | Splitting in Teams | PROGRAMMING | 800 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of tea... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*. | Print the maximum number of teams of three people the coach can form. | [
"4\n1 1 2 1\n",
"2\n2 2\n",
"7\n2 2 2 1 1 1 1\n",
"3\n1 1 1\n"
] | [
"1\n",
"0\n",
"3\n",
"1\n"
] | In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) an... | 500 | [
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "0"
},
{
"input": "7\n2 2 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 2 1",
"output": "1"
}... | 1,513,576,500 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 78 | 6,348,800 | from queue import PriorityQueue
n = int(input())
a = list(map(int, input().strip().split(' ')))
que = PriorityQueue()
for x in a:
que.put(x)
cnt = 0
while que.qsize() >= 3:
x = []
for _ in range(3):
x.append(que.get())
cnt += x[0]
for _ in range(1, 3):
if x[_] - x[0] != 0:
... | Title: Splitting in Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The co... | ```python
from queue import PriorityQueue
n = int(input())
a = list(map(int, input().strip().split(' ')))
que = PriorityQueue()
for x in a:
que.put(x)
cnt = 0
while que.qsize() >= 3:
x = []
for _ in range(3):
x.append(que.get())
cnt += x[0]
for _ in range(1, 3):
if x[_] - x[0] !=... | 0 | |
724 | A | Checking the Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong t... | The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". | Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes). | [
"monday\ntuesday\n",
"sunday\nsunday\n",
"saturday\ntuesday\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday. | 500 | [
{
"input": "monday\ntuesday",
"output": "NO"
},
{
"input": "sunday\nsunday",
"output": "YES"
},
{
"input": "saturday\ntuesday",
"output": "YES"
},
{
"input": "tuesday\nthursday",
"output": "YES"
},
{
"input": "friday\nwednesday",
"output": "NO"
},
{
"i... | 1,478,072,076 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | date = {"monday":1,"tuesday":2,"wednesday":3,"thursday":4,"friday":5,"saturday":6,"sunday":7}
while(1):
d1, d2 = date[input()], date[input()]
if d1 <= d2:d = d2-d1
elif d1 > d2 and d1 >= 5:d = d2-d1+7
else:d=7
if d == 0 or d == 2 or d == 3:print("YES")
else:print("NO")
... | Title: Checking the Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the fir... | ```python
date = {"monday":1,"tuesday":2,"wednesday":3,"thursday":4,"friday":5,"saturday":6,"sunday":7}
while(1):
d1, d2 = date[input()], date[input()]
if d1 <= d2:d = d2-d1
elif d1 > d2 and d1 >= 5:d = d2-d1+7
else:d=7
if d == 0 or d == 2 or d == 3:print("YES")
else:print("NO")
... | -1 | |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
... | 1,673,115,945 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 46 | 0 | x=input()
ans=''
for i in range(len(x)):
if i==0 and 4<int(x[i])<9 or i!=0 and int(x[i])>4:
ans+=str(9-int(x[i]))
else:
ans+=x[i]
print(ans) | Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform... | ```python
x=input()
ans=''
for i in range(len(x)):
if i==0 and 4<int(x[i])<9 or i!=0 and int(x[i])>4:
ans+=str(9-int(x[i]))
else:
ans+=x[i]
print(ans)
``` | 3 | |
825 | A | Binary Protocol | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in ord... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*.
The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts... | Print the decoded number. | [
"3\n111\n",
"9\n110011101\n"
] | [
"3\n",
"2031\n"
] | none | 0 | [
{
"input": "3\n111",
"output": "3"
},
{
"input": "9\n110011101",
"output": "2031"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "3\n100",
"output": "100"
},
{
"input": "5\n10001",
"output": "1001"
},
{
"input": "14\n11001100011000",
"output": "... | 1,500,219,442 | 1,942 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mx 2005
#define PI 3.14159265358979323846
#define E 2.71828182845905
#define MOD 1000000007
#define EPS 1e-7
#define x first
#define y second
#define INF 10000000000000
#define REP(i,a,b) for (int i = a; i < b; i++)
using namespace s... | Title: Binary Protocol
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' charact... | ```python
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mx 2005
#define PI 3.14159265358979323846
#define E 2.71828182845905
#define MOD 1000000007
#define EPS 1e-7
#define x first
#define y second
#define INF 10000000000000
#define REP(i,a,b) for (int i = a; i < b; i++)
using n... | -1 | |
756 | B | Travel Card | PROGRAMMING | 1,600 | [
"binary search",
"dp"
] | null | null | A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare.
The fare is constructed in the following manner. There are three types of tickets:
1. a tick... | The first line of input contains integer number *n* (1<=≤<=*n*<=≤<=105) — the number of trips made by passenger.
Each of the following *n* lines contains the time of trip *t**i* (0<=≤<=*t**i*<=≤<=109), measured in minutes from the time of starting the system. All *t**i* are different, given in ascending order, i. e. *... | Output *n* integers. For each trip, print the sum the passenger is charged after it. | [
"3\n10\n20\n30\n",
"10\n13\n45\n46\n60\n103\n115\n126\n150\n256\n516\n"
] | [
"20\n20\n10\n",
"20\n20\n10\n0\n20\n0\n0\n20\n20\n10\n"
] | In the first example, the system works as follows: for the first and second trips it is cheaper to pay for two one-trip tickets, so each time 20 rubles is charged, after the third trip the system understands that it would be cheaper to buy a ticket for 90 minutes. This ticket costs 50 rubles, and the passenger had alre... | 1,000 | [
{
"input": "3\n10\n20\n30",
"output": "20\n20\n10"
},
{
"input": "10\n13\n45\n46\n60\n103\n115\n126\n150\n256\n516",
"output": "20\n20\n10\n0\n20\n0\n0\n20\n20\n10"
},
{
"input": "7\n100\n138\n279\n308\n396\n412\n821",
"output": "20\n20\n20\n20\n20\n20\n0"
},
{
"input": "8\n0... | 1,601,661,115 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 904 | 13,107,200 | n = int(input())
dp = [0]
t = [0]
i,j = 1,1
for _ in range(n):
x = int(input())
t.append(x)
while x-t[i]>89:
i+=1
while x-t[j]>1439:
j+=1
try:
y = min(dp[-1]+20, dp[i-1]+50, dp[j-1]+120)
dp.append(y)
except:
print(i,j)
ans = []
for i in ... | Title: Travel Card
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare.... | ```python
n = int(input())
dp = [0]
t = [0]
i,j = 1,1
for _ in range(n):
x = int(input())
t.append(x)
while x-t[i]>89:
i+=1
while x-t[j]>1439:
j+=1
try:
y = min(dp[-1]+20, dp[i-1]+50, dp[j-1]+120)
dp.append(y)
except:
print(i,j)
ans = []
... | 3 | |
296 | A | Yaroslav and Permutations | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | 500 | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 53... | 1,669,379,839 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 154 | 0 | n=int(input())
nums=list(map(int,input().split()))
hmap={}
for item in nums:
hmap[item]=1+hmap.get(item,0)
if max(hmap.values())<n:
print("YES")
else:
if n!=1:
print("NO")
else:
print("YES") | Title: Yaroslav and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would... | ```python
n=int(input())
nums=list(map(int,input().split()))
hmap={}
for item in nums:
hmap[item]=1+hmap.get(item,0)
if max(hmap.values())<n:
print("YES")
else:
if n!=1:
print("NO")
else:
print("YES")
``` | 0 | |
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 b... | 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 aft... | 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,584,659,207 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 108 | 307,200 | n = int(input())
i = list(map(int, input().split()))
tp = []
l = list(range(1,(n+1)))
min = 0
for x in i:
if len(tp) > 0:
for y in range(len(tp)):
if x > tp[y]:
tp.insert(y, x)
break
else:
tp.append(x)
if x == l[-1]:
print(*tp)
... | 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 sh... | ```python
n = int(input())
i = list(map(int, input().split()))
tp = []
l = list(range(1,(n+1)))
min = 0
for x in i:
if len(tp) > 0:
for y in range(len(tp)):
if x > tp[y]:
tp.insert(y, x)
break
else:
tp.append(x)
if x == l[-1]:
print(*tp... | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,624,385,963 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | input = input() # the input of the cf
# input = "hlelo"
repeating = {}
for char in input:
if(repeating.get(char) == None):
repeating[char] = 0
else:
value = repeating[char] +1
repeating[char] = value
output = ""
for keys in repeating.keys():
output = output + keys
# print... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
input = input() # the input of the cf
# input = "hlelo"
repeating = {}
for char in input:
if(repeating.get(char) == None):
repeating[char] = 0
else:
value = repeating[char] +1
repeating[char] = value
output = ""
for keys in repeating.keys():
output = output + key... | 0 |
779 | A | Pupils Redistribution | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consists of exactly *n* students. An academic performance of each student is known — integer value between 1 and ... | The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=100) — number of students in both groups.
The second line contains sequence of integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=5), where *a**i* is academic performance of the *i*-th student of the group *A*.
The third line contains se... | Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained. | [
"4\n5 4 4 4\n5 5 4 5\n",
"6\n1 1 1 1 1 1\n5 5 5 5 5 5\n",
"1\n5\n3\n",
"9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1\n"
] | [
"1\n",
"3\n",
"-1\n",
"4\n"
] | none | 500 | [
{
"input": "4\n5 4 4 4\n5 5 4 5",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1\n5 5 5 5 5 5",
"output": "3"
},
{
"input": "1\n5\n3",
"output": "-1"
},
{
"input": "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1",
"output": "4"
},
{
"input": "1\n1\n2",
"output": "-1"
... | 1,545,328,932 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | def pupils(lst1, lst2):
count = 0
for i in range(len(lst1)):
t = abs(lst1[i] - lst2[i])
if t % 2 == 1:
return -1
count += t // 2
return count // 2
n = int(input())
a = [int(j) for j in input().split()]
b = [int(z) for z in input().split()]
print(pupils(a, b... | Title: Pupils Redistribution
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consis... | ```python
def pupils(lst1, lst2):
count = 0
for i in range(len(lst1)):
t = abs(lst1[i] - lst2[i])
if t % 2 == 1:
return -1
count += t // 2
return count // 2
n = int(input())
a = [int(j) for j in input().split()]
b = [int(z) for z in input().split()]
print(p... | 0 | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,684,328,292 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 124 | 0 | def f(a):
if a<2: return False
k = 0
for i in range(2, a // 2+1):
if (a % i == 0):
k = k+1
if (k <= 0): return True
return False
x, y=map(int, input().split())
c=0
if f(x) and f(y):
for i in range(x+1, y):
if f(i): c+=1
if c==0: print("YES")
el... | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
def f(a):
if a<2: return False
k = 0
for i in range(2, a // 2+1):
if (a % i == 0):
k = k+1
if (k <= 0): return True
return False
x, y=map(int, input().split())
c=0
if f(x) and f(y):
for i in range(x+1, y):
if f(i): c+=1
if c==0: print("YES... | 3.969 |
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first positi... | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4... | 1,524,931,215 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 1,497 | 7,475,200 | n = int(input())
arr = list(map(int, input().split()))
answer = []
for i in range(n):
counter = 0
for j in range(n):
if (j != i):
if (arr[i] < arr[j]):
counter += 1
answer.append(counter + 1)
print(*answer) | Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the star... | ```python
n = int(input())
arr = list(map(int, input().split()))
answer = []
for i in range(n):
counter = 0
for j in range(n):
if (j != i):
if (arr[i] < arr[j]):
counter += 1
answer.append(counter + 1)
print(*answer)
``` | 3 | |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportio... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ... | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39... | 1,683,607,250 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | x=int(input())
s=list(map(int,input().split()))
lis=[]
for i in range(x):
lis.append(s[i]/100)
print((sum(lis)/x)*100)
| Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*... | ```python
x=int(input())
s=list(map(int,input().split()))
lis=[]
for i in range(x):
lis.append(s[i]/100)
print((sum(lis)/x)*100)
``` | 3 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,589,811,841 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 280 | 20,172,800 | a,b=map(int,input().split())
list=[" ","0/1","1/6","1/3","1/2","2/3","5/6","1/1"]
d=max(a,b)
print(list[d]) | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
a,b=map(int,input().split())
list=[" ","0/1","1/6","1/3","1/2","2/3","5/6","1/1"]
d=max(a,b)
print(list[d])
``` | 0 |
26 | B | Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"greedy"
] | B. Regular Bracket Sequence | 5 | 256 | A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
One day Johnny got bracket sequence. He decided to remove some... | Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. | Output the maximum possible length of a regular bracket sequence. | [
"(()))(\n",
"((()())\n"
] | [
"4\n",
"6\n"
] | none | 1,000 | [
{
"input": "(()))(",
"output": "4"
},
{
"input": "((()())",
"output": "6"
},
{
"input": "(",
"output": "0"
},
{
"input": ")",
"output": "0"
},
{
"input": ")(()(",
"output": "2"
},
{
"input": "))))))(",
"output": "0"
},
{
"input": "()()(()((... | 1,633,018,158 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 842 | 9,932,800 | s = input()
x = len(s)
c = 0
for i in range(x):
if(s[i]=='('):
c+=1
elif(s[i]==')'):
c-=1
if(c<0):
x-=1
c = 0
print(x-c)
| Title: Regular Bracket Sequence
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regula... | ```python
s = input()
x = len(s)
c = 0
for i in range(x):
if(s[i]=='('):
c+=1
elif(s[i]==')'):
c-=1
if(c<0):
x-=1
c = 0
print(x-c)
``` | 3.897299 |
298 | B | Sail | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will ... | The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the... | If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | [
"5 0 0 1 1\nSESNW\n",
"10 5 3 3 6\nNENSWESNEE\n"
] | [
"4\n",
"-1\n"
] | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | 500 | [
{
"input": "5 0 0 1 1\nSESNW",
"output": "4"
},
{
"input": "10 5 3 3 6\nNENSWESNEE",
"output": "-1"
},
{
"input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS",
"output": "13"
},
{
"input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSS... | 1,686,495,625 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 15 | 124 | 1,638,400 | n,sx,sy,ex,ey=list(map(int,input().split()))
r=input()
a,b=sx-ex,sy-ey
flag1,flag2,flag3,flag4=0,0,0,0
if a==0: flag1=1
if b==0:flag2=1
if a>0:flag3=1
if b>0 :flag4=1
i=0
if flag1 and flag2:
print(0)
elif flag1 and flag4:
while i<n and b!=0:
if r[i]=="S":
b-=1
i+=1
... | Title: Sail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assu... | ```python
n,sx,sy,ex,ey=list(map(int,input().split()))
r=input()
a,b=sx-ex,sy-ey
flag1,flag2,flag3,flag4=0,0,0,0
if a==0: flag1=1
if b==0:flag2=1
if a>0:flag3=1
if b>0 :flag4=1
i=0
if flag1 and flag2:
print(0)
elif flag1 and flag4:
while i<n and b!=0:
if r[i]=="S":
b-=1
... | 0 | |
559 | A | Gerald's Hexagon | PROGRAMMING | 1,600 | [
"brute force",
"geometry",
"math"
] | null | null | Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.
He pain... | The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides ex... | Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split. | [
"1 1 1 1 1 1\n",
"1 2 1 2 1 2\n"
] | [
"6\n",
"13\n"
] | This is what Gerald's hexagon looks like in the first sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/>
And that's what it looks like in the second sample:
<img class="tex-graphics" src="https://espress... | 500 | [
{
"input": "1 1 1 1 1 1",
"output": "6"
},
{
"input": "1 2 1 2 1 2",
"output": "13"
},
{
"input": "2 4 5 3 3 6",
"output": "83"
},
{
"input": "45 19 48 18 46 21",
"output": "6099"
},
{
"input": "66 6 65 6 66 5",
"output": "5832"
},
{
"input": "7 5 4 8 ... | 1,680,261,981 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a = list(map(int, input().split())
print((a[0]+a[1]+a[5])**2 - a[1]**2 - a[5]**2 - a[3]**2) | Title: Gerald's Hexagon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer numbe... | ```python
a = list(map(int, input().split())
print((a[0]+a[1]+a[5])**2 - a[1]**2 - a[5]**2 - a[3]**2)
``` | -1 | |
592 | A | PawnChess | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed... | The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'.
It's guaranteed that there will not be white pawns on the first row neither black pawns on the ... | Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board. | [
"........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n",
"..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n"
] | [
"A\n",
"B\n"
] | In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner. | 500 | [
{
"input": ".BB.B.B.\nB..B..B.\n.B.BB...\nBB.....B\nBBB....B\nB..BB...\nBB.B...B\n....WWW.",
"output": "B"
},
{
"input": "B.B.BB.B\nW.WWW.WW\n.WWWWW.W\nW.BB.WBW\n.W..BBWB\nBB.WWBBB\n.W.W.WWB\nWWW..WW.",
"output": "A"
},
{
"input": "BB..BB..\nBW.W.W.B\n..B.....\n.....BB.\n.B..B..B\n......... | 1,499,197,423 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 62 | 5,529,600 | # Description of the problem can be found at http://codeforces.com/problemset/problem/592/A
l_w = [9] * 8
l_b = [9] * 8
for y in range(8):
i = 0
for c in input():
if c == "W":
if l_b[i] == 9 and l_w[i] == 9:
l_w[i] = y
l_b[i] = 10
elif c == "B":
... | Title: PawnChess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of ... | ```python
# Description of the problem can be found at http://codeforces.com/problemset/problem/592/A
l_w = [9] * 8
l_b = [9] * 8
for y in range(8):
i = 0
for c in input():
if c == "W":
if l_b[i] == 9 and l_w[i] == 9:
l_w[i] = y
l_b[i] = 10
elif c == "B"... | 3 | |
1,004 | C | Sonya and Robots | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya wi... | The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row. | Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet. | [
"5\n1 5 4 1 3\n",
"7\n1 2 1 1 1 3 2\n"
] | [
"9\n",
"7\n"
] | In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$).
In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$). | 1,500 | [
{
"input": "5\n1 5 4 1 3",
"output": "9"
},
{
"input": "7\n1 2 1 1 1 3 2",
"output": "7"
},
{
"input": "10\n2 2 4 4 3 1 1 2 3 2",
"output": "14"
},
{
"input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4",
"output": "20"
},
{
"input": "1\n1",
"output": "0"
}
] | 1,531,328,483 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 7,065,600 | from collections import Counter
n = int(input())
arr = [int(x) for x in input().split()]
count = 0
c = Counter(arr)
possible = len(c)
for i in range(n-1):
val = arr[i]
c[val]-=1
if(c[val]==0):
possible-=1
if(val not in arr[0:i]):
count+=possible
print(count) | Title: Sonya and Robots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot ... | ```python
from collections import Counter
n = int(input())
arr = [int(x) for x in input().split()]
count = 0
c = Counter(arr)
possible = len(c)
for i in range(n-1):
val = arr[i]
c[val]-=1
if(c[val]==0):
possible-=1
if(val not in arr[0:i]):
count+=possible
print(count)
``` | 0 | |
460 | A | Vasya and Socks | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la... | The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. | Print a single integer — the answer to the problem. | [
"2 2\n",
"9 3\n"
] | [
"3\n",
"13\n"
] | In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on... | 500 | [
{
"input": "2 2",
"output": "3"
},
{
"input": "9 3",
"output": "13"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "1 99",
"output": "1"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "10 2",
"outp... | 1,650,389,712 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = int(input())
m = int(input())
k = 0
day = 0
while n > 0:
n -= 1
day += 1
if day % m == 0:
n += 1
print(day)
| Title: Vasya and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th... | ```python
n = int(input())
m = int(input())
k = 0
day = 0
while n > 0:
n -= 1
day += 1
if day % m == 0:
n += 1
print(day)
``` | -1 | |
352 | A | Jeff and Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | [
"4\n5 0 5 0\n",
"11\n5 5 5 5 5 5 5 5 0 5 5\n"
] | [
"0\n",
"5555555550\n"
] | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | 500 | [
{
"input": "4\n5 0 5 0",
"output": "0"
},
{
"input": "11\n5 5 5 5 5 5 5 5 0 5 5",
"output": "5555555550"
},
{
"input": "7\n5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "11\n5 0 5 ... | 1,696,952,662 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | input()
n = list(map(int, input().split()))
number_of_zeros = n.count(0)
number_of_fives = n.count(5)
l = len(n)
if number_of_zeros == l:
print(0)
elif number_of_fives % 9 == 0 and number_of_zeros > 0:
print('5' * (number_of_fives) + "0" * number_of_zeros)
else:
print(-1)
| Title: Jeff and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make fr... | ```python
input()
n = list(map(int, input().split()))
number_of_zeros = n.count(0)
number_of_fives = n.count(5)
l = len(n)
if number_of_zeros == l:
print(0)
elif number_of_fives % 9 == 0 and number_of_zeros > 0:
print('5' * (number_of_fives) + "0" * number_of_zeros)
else:
print(-1)
``` | 0 | |
271 | D | Good Substrings | PROGRAMMING | 1,800 | [
"data structures",
"strings"
] | null | null | You've got string *s*, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring *s*[*l*...*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) of string *s*<=<==<=<=*s*1*s*2...*s*|*s*| (where |*s*| is the length of string *s*) is string <=*s**l**s**l*<=+<=1...*s**r*.
The substring *s*[*l... | The first line of the input is the non-empty string *s*, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the *i*-th character of this string equals "1", then the *i*-th Eng... | Print a single integer — the number of distinct good substrings of string *s*. | [
"ababab\n01000000000000000000000000\n1\n",
"acbacbacaa\n00000000000000000000000000\n2\n"
] | [
"5\n",
"8\n"
] | In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb". | 2,000 | [
{
"input": "ababab\n01000000000000000000000000\n1",
"output": "5"
},
{
"input": "acbacbacaa\n00000000000000000000000000\n2",
"output": "8"
},
{
"input": "a\n00000000000000000000000000\n0",
"output": "0"
},
{
"input": "aaaa\n00000000000000000000000000\n0",
"output": "0"
... | 1,689,592,335 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | print("_RANDOM_GUESS_1689592335.051668")# 1689592335.0516853 | Title: Good Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got string *s*, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring *s*[*l*...*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) of string *s*<=<==<=<=*s*1*s*2...*s*|*s*| (wh... | ```python
print("_RANDOM_GUESS_1689592335.051668")# 1689592335.0516853
``` | 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 ite... | 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,697,906,688 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 307,200 | from collections import defaultdict
def solve():
n, k = map(int, input().split())
str = input()
counts = defaultdict(int)
for i in range(n):
counts[str[i]] += 1
for i in range(n):
if k == 0:
break
max_count = max(counts.values())
for c, v in counts.items():
... | 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... | ```python
from collections import defaultdict
def solve():
n, k = map(int, input().split())
str = input()
counts = defaultdict(int)
for i in range(n):
counts[str[i]] += 1
for i in range(n):
if k == 0:
break
max_count = max(counts.values())
for c, v in counts.it... | 0 | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,692,184,237 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | l1=list(input())
l1.pop()
i=-1
while(True):
if(l1[i]==" "):
l1.pop()
else:
break
l2=['a','e','i','o','u','y','A','E','I','O','U']
if(l1[-1] in l2):
print("YES")
else:
print("NO") | Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
l1=list(input())
l1.pop()
i=-1
while(True):
if(l1[i]==" "):
l1.pop()
else:
break
l2=['a','e','i','o','u','y','A','E','I','O','U']
if(l1[-1] in l2):
print("YES")
else:
print("NO")
``` | 0 |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,613,179,563 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 77 | 0 | def solve(n):
if n ==1 :
return 1
arr = [[1]*n]
for i in range(1,n):
row = [1]
for col in range(1,n):
row.append(row[col-1]+arr[i-1][col])
if i == n-1:
return row[-1]
arr.append(row)
def main():
print(solve(int(input())))
main()
| Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
def solve(n):
if n ==1 :
return 1
arr = [[1]*n]
for i in range(1,n):
row = [1]
for col in range(1,n):
row.append(row[col-1]+arr[i-1][col])
if i == n-1:
return row[-1]
arr.append(row)
def main():
print(solve(int(input())))
main()
``` | 3 | |
156 | C | Cipher | PROGRAMMING | 2,000 | [
"combinatorics",
"dp"
] | null | null | Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything.
At last, after some thought, he thought of somethin... | The input data contains several tests. The first line contains the only integer *t* (1<=≤<=*t*<=≤<=104) — the number of tests.
Next *t* lines contain the words, one per line. Each word consists of lowercase Latin letters and has length from 1 to 100, inclusive. Lengths of words can differ. | For each word you should print the number of different other words that coincide with it in their meaning — not from the words listed in the input data, but from all possible words. As the sought number can be very large, print its value modulo 1000000007 (109<=+<=7). | [
"1\nab\n",
"1\naaaaaaaaaaa\n",
"2\nya\nklmbfxzb\n"
] | [
"1\n",
"0\n",
"24\n320092793\n"
] | Some explanations about the operation:
- Note that for each letter, we can clearly define the letter that follows it. Letter "b" alphabetically follows letter "a", letter "c" follows letter "b", ..., "z" follows letter "y". - Preceding letters are defined in the similar manner: letter "y" precedes letter "z", ..., "... | 1,500 | [
{
"input": "1\nab",
"output": "1"
},
{
"input": "1\naaaaaaaaaaa",
"output": "0"
},
{
"input": "2\nya\nklmbfxzb",
"output": "24\n320092793"
},
{
"input": "1\na",
"output": "0"
},
{
"input": "1\nz",
"output": "0"
},
{
"input": "1\naaaaaaaaaaaaaaaaaaaaaaa... | 1,647,882,454 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 748 | 11,059,200 | MOD = int(1e9 + 7)
dp = [[0 for j in range(2501)] for i in range(101)]
dp[0][0] = 1
for i in range(100):
for j in range(i * 25 + 1):
for k in range(26):
dp[i + 1][j + k] = (dp[i + 1][j + k] + dp[i][j]) % MOD
for tc in range(int(input())):
S = input()
s = sum([ ord(c) - ord('a') for c in S ])
print((d... | Title: Cipher
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence... | ```python
MOD = int(1e9 + 7)
dp = [[0 for j in range(2501)] for i in range(101)]
dp[0][0] = 1
for i in range(100):
for j in range(i * 25 + 1):
for k in range(26):
dp[i + 1][j + k] = (dp[i + 1][j + k] + dp[i][j]) % MOD
for tc in range(int(input())):
S = input()
s = sum([ ord(c) - ord('a') for c in S ])
... | 3 | |
765 | B | Code obfuscation | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"strings"
] | null | null | Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.
To obfuscate the code, Kostya first looks at the first variable name used in his program and rep... | In the only line of input there is a string *S* of lowercase English letters (1<=≤<=|*S*|<=≤<=500) — the identifiers of a program with removed whitespace characters. | If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO". | [
"abacaba\n",
"jinotega\n"
] | [
"YES\n",
"NO\n"
] | In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program:
- replace all occurences of number with a, the result would be "a string a character a string a",- replace all occurences of string with b, the result... | 1,000 | [
{
"input": "abacaba",
"output": "YES"
},
{
"input": "jinotega",
"output": "NO"
},
{
"input": "aaaaaaaaaaa",
"output": "YES"
},
{
"input": "aba",
"output": "YES"
},
{
"input": "bab",
"output": "NO"
},
{
"input": "a",
"output": "YES"
},
{
"in... | 1,679,997,358 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | s=input()
st=sorted(set(s),key=s.index)
for i in range(len(st)):
if st[i]!=chr(97+i):exit(print('NO'))
print('YES')
| Title: Code obfuscation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming cont... | ```python
s=input()
st=sorted(set(s),key=s.index)
for i in range(len(st)):
if st[i]!=chr(97+i):exit(print('NO'))
print('YES')
``` | 3 | |
385 | C | Bear and Prime Numbers | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"implementation",
"math",
"number theory"
] | null | null | Recently, the bear started studying data structures and faced the following problem.
You are given a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* of length *n* and *m* queries, each of them is characterized by two integers *l**i*,<=*r**i*. Let's introduce *f*(*p*) to represent the number of such indexes *k*, that *... | The first line contains integer *n* (1<=≤<=*n*<=≤<=106). The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (2<=≤<=*x**i*<=≤<=107). The numbers are not necessarily distinct.
The third line contains integer *m* (1<=≤<=*m*<=≤<=50000). Each of the following *m* lines contains a pair of space-separated integ... | Print *m* integers — the answers to the queries on the order the queries appear in the input. | [
"6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4\n",
"7\n2 3 5 7 11 4 8\n2\n8 10\n2 123\n"
] | [
"9\n7\n0\n",
"0\n7\n"
] | Consider the first sample. Overall, the first sample has 3 queries.
1. The first query *l* = 2, *r* = 11 comes. You need to count *f*(2) + *f*(3) + *f*(5) + *f*(7) + *f*(11) = 2 + 1 + 4 + 2 + 0 = 9. 1. The second query comes *l* = 3, *r* = 12. You need to count *f*(3) + *f*(5) + *f*(7) + *f*(11) = 1 + 4 + 2 + 0 = 7.... | 1,500 | [
{
"input": "6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4",
"output": "9\n7\n0"
},
{
"input": "7\n2 3 5 7 11 4 8\n2\n8 10\n2 123",
"output": "0\n7"
},
{
"input": "9\n50 50 50 50 50 50 50 50 50\n7\n20 20\n8 13\n13 13\n6 14\n3 5\n15 17\n341 1792",
"output": "0\n0\n0\n0\n9\n0\n0"
},
{
"... | 1,628,174,953 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 115,097,600 | from collections import Counter
n=int(input())
a=[int(x) for x in input().split()]
cnta=Counter(a)
def SieveOfEratosthenes_beta(limit,score,cnta):
isPrime = [True]*(limit+1)
isPrime[0] = isPrime[1] = False
for i in range(2, limit+1):
if not isPrime[i]:continue
for j in range(i, li... | Title: Bear and Prime Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, the bear started studying data structures and faced the following problem.
You are given a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* of length *n* and *m* queries, each of them is characterized b... | ```python
from collections import Counter
n=int(input())
a=[int(x) for x in input().split()]
cnta=Counter(a)
def SieveOfEratosthenes_beta(limit,score,cnta):
isPrime = [True]*(limit+1)
isPrime[0] = isPrime[1] = False
for i in range(2, limit+1):
if not isPrime[i]:continue
for j in r... | 0 | |
876 | A | Trip For Meal | PROGRAMMING | 900 | [
"math"
] | null | null | Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's ... | First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits.
Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses.
Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses.
Fourth line contains an integer *c* ... | Output one number — minimum distance in meters Winnie must go through to have a meal *n* times. | [
"3\n2\n3\n1\n",
"1\n2\n3\n5\n"
] | [
"3\n",
"0\n"
] | In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.
In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all. | 500 | [
{
"input": "3\n2\n3\n1",
"output": "3"
},
{
"input": "1\n2\n3\n5",
"output": "0"
},
{
"input": "10\n1\n8\n3",
"output": "9"
},
{
"input": "7\n10\n5\n6",
"output": "30"
},
{
"input": "9\n9\n7\n5",
"output": "42"
},
{
"input": "9\n37\n85\n76",
"outpu... | 1,508,849,966 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 4,608,000 | n=int(input())
a=int(input())
b=int(input())
c=int(input())
K=[a,b]
C=[a,c]
O=[b,c]
s=0
A=K
if n == 1:
print(0)
elif n>1:
while n-1>0:
if A==K:
if A[0]>A[1]:
s+=A[1]
A=O
else:
s+= A[0]
A=C
... | Title: Trip For Meal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair... | ```python
n=int(input())
a=int(input())
b=int(input())
c=int(input())
K=[a,b]
C=[a,c]
O=[b,c]
s=0
A=K
if n == 1:
print(0)
elif n>1:
while n-1>0:
if A==K:
if A[0]>A[1]:
s+=A[1]
A=O
else:
s+= A[0]
... | 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 h... | 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... | 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,620,496,626 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 122 | 6,656,000 | my_file = open("input.txt", "r")
outputFile = open("output.txt", "w")
n = int(my_file.readline())
a=list(map(int,my_file.readline().split()))
a.sort()
maxValue = a[n-1]
for i in range(0,n):
if 2*a[i] >= maxValue:
outputFile.write(str(i))
break
| 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... | ```python
my_file = open("input.txt", "r")
outputFile = open("output.txt", "w")
n = int(my_file.readline())
a=list(map(int,my_file.readline().split()))
a.sort()
maxValue = a[n-1]
for i in range(0,n):
if 2*a[i] >= maxValue:
outputFile.write(str(i))
break
``` | 0 | |
779 | B | Weird Rounding | PROGRAMMING | 1,100 | [
"brute force",
"greedy"
] | null | null | Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For example, if *k*<==<=3, in the number 30020 it is enough to delete a single digit (2). In this case, t... | The only line of the input contains two integer numbers *n* and *k* (0<=≤<=*n*<=≤<=2<=000<=000<=000, 1<=≤<=*k*<=≤<=9).
It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. | Print *w* — the required minimal number of digits to erase. After removing the appropriate *w* digits from the number *n*, the result should have a value that is divisible by 10*k*. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). | [
"30020 3\n",
"100 9\n",
"10203049 2\n"
] | [
"1\n",
"2\n",
"3\n"
] | In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. | 1,000 | [
{
"input": "30020 3",
"output": "1"
},
{
"input": "100 9",
"output": "2"
},
{
"input": "10203049 2",
"output": "3"
},
{
"input": "0 1",
"output": "0"
},
{
"input": "0 9",
"output": "0"
},
{
"input": "100 2",
"output": "0"
},
{
"input": "102... | 1,648,464,668 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n, k = map(int, input().split())
if n < 10**k:
print(len(str(n))-1)
elif n == 10**k:
print("0")
else:
a = 0
for j in range(1, len(str(n))):
p = str(n)
if p[j] != "0":
a += 1
elif p[j] == "0":
continue
print(a)
| Title: Weird Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For e... | ```python
n, k = map(int, input().split())
if n < 10**k:
print(len(str(n))-1)
elif n == 10**k:
print("0")
else:
a = 0
for j in range(1, len(str(n))):
p = str(n)
if p[j] != "0":
a += 1
elif p[j] == "0":
continue
print(a)
``` | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,530,895,088 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 108 | 0 | # -*- coding: utf-8 -*-
"""
Created on Fri Jul 6 23:09:31 2018
@author: Duy SoCiu
"""
n=input()
try:
h=n.index('h')
e=n[h:].index('e')+h
l=n[e:].index('l')+e
o=n[l:].index('o')+l
except:
print('NO')
#print(h,e,l,o)
if n.count('l',e,o)>1:
print('YES')
else:
print('NO')
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 6 23:09:31 2018
@author: Duy SoCiu
"""
n=input()
try:
h=n.index('h')
e=n[h:].index('e')+h
l=n[e:].index('l')+e
o=n[l:].index('o')+l
except:
print('NO')
#print(h,e,l,o)
if n.count('l',e,o)>1:
print('YES')
else:
pri... | -1 |
298 | B | Sail | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will ... | The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the... | If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | [
"5 0 0 1 1\nSESNW\n",
"10 5 3 3 6\nNENSWESNEE\n"
] | [
"4\n",
"-1\n"
] | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | 500 | [
{
"input": "5 0 0 1 1\nSESNW",
"output": "4"
},
{
"input": "10 5 3 3 6\nNENSWESNEE",
"output": "-1"
},
{
"input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS",
"output": "13"
},
{
"input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSS... | 1,599,752,791 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 310 | 0 | n,a,b,c,d=map(int,input().split())
s=input()
for i in range(n):
if s[i]=='N' and c>a:a+=1
elif s[i]=='S'and a>c:a-=1
elif s[i]=='E'and b<d:b+=1
elif s[i]=='W'and b>d:b-=1
if a==c and b==d:
print(i+1)
break
else:
print(-1) | Title: Sail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assu... | ```python
n,a,b,c,d=map(int,input().split())
s=input()
for i in range(n):
if s[i]=='N' and c>a:a+=1
elif s[i]=='S'and a>c:a-=1
elif s[i]=='E'and b<d:b+=1
elif s[i]=='W'and b>d:b-=1
if a==c and b==d:
print(i+1)
break
else:
print(-1)
``` | 0 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,621,606,954 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | d1,d2,d3 = mapa(int,input().split())
print(min(d1+d2+d3 , 2*(min(d1+d2,d2+d3,d3+d1)))) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
d1,d2,d3 = mapa(int,input().split())
print(min(d1+d2+d3 , 2*(min(d1+d2,d2+d3,d3+d1))))
``` | -1 | |
934 | B | A Prosperous Lot | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount ... | The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops. | Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018. | [
"2\n",
"6\n"
] | [
"462",
"8080"
] | none | 1,000 | [
{
"input": "2",
"output": "8"
},
{
"input": "6",
"output": "888"
},
{
"input": "3",
"output": "86"
},
{
"input": "4",
"output": "88"
},
{
"input": "5",
"output": "886"
},
{
"input": "1000000",
"output": "-1"
},
{
"input": "1",
"output":... | 1,522,016,548 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 93 | 7,065,600 | """
Brandt Smith, Lemuel Gorion and Peter Haddad
codeforces.com
Problem 115B
"""
import sys
k = int(input())
if k > 36:
print(-1)
sys.exit()
if k == 0:
print(1)
sys.exit()
if k == 1:
print(0)
sys.exit()
for i in range(0, k // 2):
print(8, end = '')
if k % 2:
print(0)
| Title: A Prosperous Lot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to a... | ```python
"""
Brandt Smith, Lemuel Gorion and Peter Haddad
codeforces.com
Problem 115B
"""
import sys
k = int(input())
if k > 36:
print(-1)
sys.exit()
if k == 0:
print(1)
sys.exit()
if k == 1:
print(0)
sys.exit()
for i in range(0, k // 2):
print(8, end = '')
if k % 2:
print(0)
... | 0 | |
225 | B | Well-known Numbers | PROGRAMMING | 1,600 | [
"binary search",
"greedy",
"number theory"
] | null | null | Numbers *k*-bonacci (*k* is integer, *k*<=><=1) are a generalization of Fibonacci numbers and are determined as follows:
- *F*(*k*,<=*n*)<==<=0, for integer *n*, 1<=≤<=*n*<=<<=*k*; - *F*(*k*,<=*k*)<==<=1; - *F*(*k*,<=*n*)<==<=*F*(*k*,<=*n*<=-<=1)<=+<=*F*(*k*,<=*n*<=-<=2)<=+<=...<=+<=*F*(*k*,<=*n*<=-<=*k*), fo... | The first line contains two integers *s* and *k* (1<=≤<=*s*,<=*k*<=≤<=109; *k*<=><=1). | In the first line print an integer *m* (*m*<=≥<=2) that shows how many numbers are in the found representation. In the second line print *m* distinct integers *a*1,<=*a*2,<=...,<=*a**m*. Each printed integer should be a *k*-bonacci number. The sum of printed integers must equal *s*.
It is guaranteed that the answer ex... | [
"5 2\n",
"21 5\n"
] | [
"3\n0 2 3\n",
"3\n4 1 16\n"
] | none | 1,000 | [
{
"input": "5 2",
"output": "3\n0 2 3"
},
{
"input": "21 5",
"output": "3\n4 1 16"
},
{
"input": "1 1000",
"output": "2\n1 0 "
},
{
"input": "1000000000 1000000000",
"output": "14\n536870912 268435456 134217728 33554432 16777216 8388608 1048576 524288 131072 32768 16384 2... | 1,642,943,589 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 |
def bin_search(m,a):
l = 0
h = len(a)-1
while(l<=h):
mid = (h+l)//2
if(a[mid] == m):
return a[mid]
elif(a[mid] < m):
l = mid + 1
else:
h = mid - 1
return a[l-1]
s = input().split()
(m,k) = (int(i) for i in s)
if(k<=32):
a = [0 for i in range(k-1)]
a.append(1)
... | Title: Well-known Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Numbers *k*-bonacci (*k* is integer, *k*<=><=1) are a generalization of Fibonacci numbers and are determined as follows:
- *F*(*k*,<=*n*)<==<=0, for integer *n*, 1<=≤<=*n*<=<<=*k*; - *F*(*k*,<=*k*)<==<=1; - ... | ```python
def bin_search(m,a):
l = 0
h = len(a)-1
while(l<=h):
mid = (h+l)//2
if(a[mid] == m):
return a[mid]
elif(a[mid] < m):
l = mid + 1
else:
h = mid - 1
return a[l-1]
s = input().split()
(m,k) = (int(i) for i in s)
if(k<=32):
a = [0 for i in range(k-1)]
a.a... | 0 | |
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 p... | 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,655,624,376 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | take = input()
dt = {}
for i in take:
if(i in dt):
dt[i] += 1
else:
dt[i] = 1
odd = 0
for i in dt:
if(i%2 == 1):
odd += 1
if(odd == 0):
print("First")
elif(odd == 1):
print("First")
elif(odd%2==0):
print("Second")
els... | 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... | ```python
take = input()
dt = {}
for i in take:
if(i in dt):
dt[i] += 1
else:
dt[i] = 1
odd = 0
for i in dt:
if(i%2 == 1):
odd += 1
if(odd == 0):
print("First")
elif(odd == 1):
print("First")
elif(odd%2==0):
print("Second")
... | -1 | |
291 | A | Spyke Talks | PROGRAMMING | 800 | [
"*special",
"implementation",
"sortings"
] | null | null | Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the number of secretaries in Polycarpus's corporation. The next line contains *n* space-separated integers: *id*1,<=*id*2,<=...,<=*id**n* (0<=≤<=*id**i*<=≤<=109). Number *id**i* equals the number of the call session of the *i*-th secretary, if the secretary is t... | Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. | [
"6\n0 1 7 1 7 10\n",
"3\n1 1 1\n",
"1\n0\n"
] | [
"2\n",
"-1\n",
"0\n"
] | In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5.
In the second test sample the described situation is impossible as conferences aren't allowed. | 500 | [
{
"input": "6\n0 1 7 1 7 10",
"output": "2"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "5\n2 2 1 1 3",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "10\n4 21 3 21 21 1 1 2 2 3",
"ou... | 1,652,792,455 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 154 | 17,715,200 | n = int(input())
a = [int(x) for x in input().split()]
m = {}
for e in a:
if e not in m:
m[e] = 1
else:
m[e] += 1
pairs = 0
for e in m:
if m[e] == 2:
pairs += 1
elif m[e] > 2:
print(-1)
break
else:
print(pairs) | Title: Spyke Talks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each othe... | ```python
n = int(input())
a = [int(x) for x in input().split()]
m = {}
for e in a:
if e not in m:
m[e] = 1
else:
m[e] += 1
pairs = 0
for e in m:
if m[e] == 2:
pairs += 1
elif m[e] > 2:
print(-1)
break
else:
print(pairs)
``` | 0 | |
78 | A | Haiku | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Haiku | 2 | 256 | Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll... | The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailin... | Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). | [
"on codeforces \nbeta round is running\n a rustling of keys \n",
"how many gallons\nof edo s rain did you drink\n cuckoo\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "on codeforces \nbeta round is running\n a rustling of keys ",
"output": "YES"
},
{
"input": "how many gallons\nof edo s rain did you drink\n cuckoo",
"output": "NO"
},
{
"input": " hatsu shigure\n saru mo komino wo\nhoshige nari",
... | 1,632,616,663 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 216 | 21,401,600 | dem, a, b, c = 0, input(), input(), input()
for x in a:
if x in ['u', 'e', 'o', 'a', 'i']: dem += 1
if dem != 5: print("NO")
else:
for x in b:
if x in ['u', 'e', 'o', 'a', 'i']: dem += 1
if dem != 12: print("NO")
else:
for x in c:
if x in ['u', 'e', 'o', 'a', 'i']: ... | Title: Haiku
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase... | ```python
dem, a, b, c = 0, input(), input(), input()
for x in a:
if x in ['u', 'e', 'o', 'a', 'i']: dem += 1
if dem != 5: print("NO")
else:
for x in b:
if x in ['u', 'e', 'o', 'a', 'i']: dem += 1
if dem != 12: print("NO")
else:
for x in c:
if x in ['u', 'e', 'o', '... | 3.906136 |
0 | none | none | none | 0 | [
"none"
] | null | null | Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland — Uzhlyandia.
It is widely known that Uzhlyandia has *n* cities connected with *m* bidirectional roads. Also, there are no two roads in the country that connect the same pair of cities, but roads starting and en... | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=106) — the number of cities and roads in Uzhlyandia, respectively.
Each of the next *m* lines contains two integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*) that mean that there is road between cities *u* and *v*.
It is guaranteed that no road will be gi... | Print out the only integer — the number of good paths in Uzhlyandia. | [
"5 4\n1 2\n1 3\n1 4\n1 5\n",
"5 3\n1 2\n2 3\n4 5\n",
"2 2\n1 1\n1 2\n"
] | [
"6",
"0",
"1"
] | In first sample test case the good paths are:
- 2 → 1 → 3 → 1 → 4 → 1 → 5, - 2 → 1 → 3 → 1 → 5 → 1 → 4, - 2 → 1 → 4 → 1 → 5 → 1 → 3, - 3 → 1 → 2 → 1 → 4 → 1 → 5, - 3 → 1 → 2 → 1 → 5 → 1 → 4, - 4 → 1 → 2 → 1 → 3 → 1 → 5.
There are good paths that are same with displayed above, because the sets of roads they pas... | 0 | [] | 1,491,250,334 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 5,632,000 | from collections import deque
ip = lambda : map(int, input().split())
def connected(g):
f = [False for _ in range(len(g))]
f[0] = True
q = deque([0])
while q:
u = q.popleft()
for v in g[u]:
if not f[v]:
f[v] = True
q.append(v)
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland — Uzhlyandia.
It is widely known that Uzhlyandia has *n* cities connected with *m* bidirectional roads. Also, there are n... | ```python
from collections import deque
ip = lambda : map(int, input().split())
def connected(g):
f = [False for _ in range(len(g))]
f[0] = True
q = deque([0])
while q:
u = q.popleft()
for v in g[u]:
if not f[v]:
f[v] = True
q.appe... | 0 | |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,630,472,816 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 92 | 6,963,200 | n,m = map(int,input().split())
count = 0
sount = 0
Dount = 0
for i in range(1,7):
G = abs(n-i)
H = abs(m-i)
if G<H:
count = count + 1
elif H<G:
sount = sount + 1
else :
Dount = Dount + 1
if n>m or m>n:
print(count,Dount,sount)
else:
print(count,Dount... | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
n,m = map(int,input().split())
count = 0
sount = 0
Dount = 0
for i in range(1,7):
G = abs(n-i)
H = abs(m-i)
if G<H:
count = count + 1
elif H<G:
sount = sount + 1
else :
Dount = Dount + 1
if n>m or m>n:
print(count,Dount,sount)
else:
print(c... | 3 | |
365 | B | The Fibonacci Segment | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | You have array *a*1,<=*a*2,<=...,<=*a**n*. Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) is good if *a**i*<==<=*a**i*<=-<=1<=+<=*a**i*<=-<=2, for all *i* (*l*<=+<=2<=≤<=*i*<=≤<=*r*).
Let's define *len*([*l*,<=*r*])<==<=*r*<=-<=*l*<=+<=1, *len*([*l*,<=*r*]) is the length of the segment [*l*,<=*r*]. Segment [*l*1,<=*r... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | Print the length of the longest good segment in array *a*. | [
"10\n1 2 3 5 8 13 21 34 55 89\n",
"5\n1 1 1 1 1\n"
] | [
"10\n",
"2\n"
] | none | 1,000 | [
{
"input": "10\n1 2 3 5 8 13 21 34 55 89",
"output": "10"
},
{
"input": "5\n1 1 1 1 1",
"output": "2"
},
{
"input": "1\n1000",
"output": "1"
},
{
"input": "51\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output"... | 1,658,153,125 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n=int(input())
l=list(map(int,input().split()))[:n]
c=0
for i in range(2,len(l)):
if l[i]==l[i-1]+l[i-2]:c+=1
print(c+2) | Title: The Fibonacci Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have array *a*1,<=*a*2,<=...,<=*a**n*. Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) is good if *a**i*<==<=*a**i*<=-<=1<=+<=*a**i*<=-<=2, for all *i* (*l*<=+<=2<=≤<=*i*<=≤<=*r*).
Let's define *len*([*l*,<=*... | ```python
n=int(input())
l=list(map(int,input().split()))[:n]
c=0
for i in range(2,len(l)):
if l[i]==l[i-1]+l[i-2]:c+=1
print(c+2)
``` | 0 | |
911 | B | Two Cakes | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set ... | The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | 0 | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"inp... | 1,616,426,967 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | '''
Online Python Compiler.
Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.
'''
n,a,b=map(int,input().split())
mnn=-1
for i in range(1,n):
k=n-i
p=a//i
q=b//k
mn=min(p... | Title: Two Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Iv... | ```python
'''
Online Python Compiler.
Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.
'''
n,a,b=map(int,input().split())
mnn=-1
for i in range(1,n):
k=n-i
p=a//i
q=b//k
... | 0 | |
841 | B | Godsend | PROGRAMMING | 1,100 | [
"games",
"math"
] | null | null | Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts... | First line of input data contains single integer *n* (1<=≤<=*n*<=≤<=106) — length of the array.
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes). | [
"4\n1 3 2 3\n",
"2\n2 2\n"
] | [
"First\n",
"Second\n"
] | In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose. | 1,000 | [
{
"input": "4\n1 3 2 3",
"output": "First"
},
{
"input": "2\n2 2",
"output": "Second"
},
{
"input": "4\n2 4 6 8",
"output": "Second"
},
{
"input": "5\n1 1 1 1 1",
"output": "First"
},
{
"input": "4\n720074544 345031254 849487632 80870826",
"output": "Second"
... | 1,503,780,222 | 2,147,483,647 | Python 3 | OK | TESTS | 88 | 561 | 78,540,800 | def main():
n = int(input())
L = [int(x) for x in input().split()]
print(solver(L))
def solver(L):
for x in L:
if x % 2 == 1:
return 'First'
return 'Second'
main()
#print(solver([2, 2]))
| Title: Godsend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero l... | ```python
def main():
n = int(input())
L = [int(x) for x in input().split()]
print(solver(L))
def solver(L):
for x in L:
if x % 2 == 1:
return 'First'
return 'Second'
main()
#print(solver([2, 2]))
``` | 3 | |
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains... | The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
... | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "... | 1,653,761,379 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | r, c = map(int, input().split())
row = []
colum = []
for i in range(r):
s = input()
for j in range(c):
if(s[j] == 'S'):
row.append(i)
colum.append(j)
ro = len(set(row))
co = len(set(colum))
x = r - ro
y = c - co
ans = x*4 + y*3 - x*y
print(ans) | Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each ti... | ```python
r, c = map(int, input().split())
row = []
colum = []
for i in range(r):
s = input()
for j in range(c):
if(s[j] == 'S'):
row.append(i)
colum.append(j)
ro = len(set(row))
co = len(set(colum))
x = r - ro
y = c - co
ans = x*4 + y*3 - x*y
print(ans)
``` | 0 | |
816 | B | Karen and Coffee | PROGRAMMING | 1,400 | [
"binary search",
"data structures",
"implementation"
] | null | null | To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows *n* coffee ... | The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next *n* lines describe ... | For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive. | [
"3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n",
"2 1 1\n1 1\n200000 200000\n90 100\n"
] | [
"3\n3\n0\n4\n",
"0\n"
] | In the first test case, Karen knows 3 recipes.
1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperatur... | 1,000 | [
{
"input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100",
"output": "3\n3\n0\n4"
},
{
"input": "2 1 1\n1 1\n200000 200000\n90 100",
"output": "0"
},
{
"input": "1 1 1\n1 1\n1 1",
"output": "1"
},
{
"input": "1 1 1\n200000 200000\n200000 200000",
"output": "1"
... | 1,691,533,878 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n,k,q = map(int,input().split(" "))
ran = []
mini = float('inf')
maxi = float('-inf')
for i in range(n):
a, b = map(int,input().split(" "))
mini = min(min(a,b),mini)
maxi = max(max(a,b),maxi)
#criando o range
intervalos = []
for i in range(mini,maxi+2):
intervalos.append(i)
print(i... | Title: Karen and Coffee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading seve... | ```python
n,k,q = map(int,input().split(" "))
ran = []
mini = float('inf')
maxi = float('-inf')
for i in range(n):
a, b = map(int,input().split(" "))
mini = min(min(a,b),mini)
maxi = max(max(a,b),maxi)
#criando o range
intervalos = []
for i in range(mini,maxi+2):
intervalos.append(i)
... | 0 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,576,347,542 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 216 | 0 | n = int(input())
nsdic = {}
max1 = 0
for i in range(n):
name, score = input().split()
score = int(score)
if name in nsdic:
nsdic[name] += score
else:
nsdic[name] = score
if nsdic[name] > max1:
max1 = nsdic[name]
winner1 = name;
winner2 = list(nsdic.keys()... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
n = int(input())
nsdic = {}
max1 = 0
for i in range(n):
name, score = input().split()
score = int(score)
if name in nsdic:
nsdic[name] += score
else:
nsdic[name] = score
if nsdic[name] > max1:
max1 = nsdic[name]
winner1 = name;
winner2 = list(ns... | 0 |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,657,878,516 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 92 | 614,400 | # A. Bachgold Problem
n = int(input())
if n % 2 == 0:
d = int(n / 2)
print(d)
print(str("2 ") * d)
else:
d = n - 3
print(int((d / 2) + 1))
print(str("2 ") * int((d /2)) ,"3")
| Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
... | ```python
# A. Bachgold Problem
n = int(input())
if n % 2 == 0:
d = int(n / 2)
print(d)
print(str("2 ") * d)
else:
d = n - 3
print(int((d / 2) + 1))
print(str("2 ") * int((d /2)) ,"3")
``` | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,692,723,703 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 31 | 0 | n, m, a = map(int, input().split())
# Calculate the number of flagstones needed for width and length
flagstones_width = (n + a - 1) // a # Ceiling division to account for remainder
flagstones_length = (m + a - 1) // a
# Calculate the total number of flagstones needed
total_flagstones = flagstones_width * flag... | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n, m, a = map(int, input().split())
# Calculate the number of flagstones needed for width and length
flagstones_width = (n + a - 1) // a # Ceiling division to account for remainder
flagstones_length = (m + a - 1) // a
# Calculate the total number of flagstones needed
total_flagstones = flagstones_wi... | 3.9845 |
804 | A | Find Amir | PROGRAMMING | 1,000 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* an... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of schools. | Print single integer: the minimum cost of tickets needed to visit all schools. | [
"2\n",
"10\n"
] | [
"0\n",
"4\n"
] | In the first example we can buy a ticket between the schools that costs <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c67d72010e0498bfd065a6a38fdeaec90358507b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "2",
"output": "0"
},
{
"input": "10",
"output": "4"
},
{
"input": "43670",
"output": "21834"
},
{
"input": "4217",
"output": "2108"
},
{
"input": "17879",
"output": "8939"
},
{
"input": "31809",
"output": "15904"
},
{
"input": "... | 1,493,991,412 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 62 | 0 | n = input()
n = int(n)
if (n % 2) != 0:
print (n // 2)
else:
print ((n // 2) -1) | Title: Find Amir
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel b... | ```python
n = input()
n = int(n)
if (n % 2) != 0:
print (n // 2)
else:
print ((n // 2) -1)
``` | 3 | |
967 | B | Watering System | PROGRAMMING | 1,000 | [
"math",
"sortings"
] | null | null | Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After... | The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$)... | Print a single integer — the number of holes Arkady should block. | [
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] | [
"1\n",
"0\n",
"4\n"
] | In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not les... | 1,000 | [
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 ... | 1,527,164,769 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 77 | 0 | n,A,B = list(map(int,input().split(' ')))
sq = list(map(int,input().split(' ')))
if A*sq[0]/sum(sq) >= B:
print(0)
else:
s = list()
s.append(sq[0])
s.extend(sorted(s[1:]))
lev = 1
pra = n-1
while abs(lev-pra) >= 1:
s8 = sum(s[:(lev+pra)//2+1])
## print(lev,pra)
if abs(lev-pra) ==... | Title: Watering System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the fi... | ```python
n,A,B = list(map(int,input().split(' ')))
sq = list(map(int,input().split(' ')))
if A*sq[0]/sum(sq) >= B:
print(0)
else:
s = list()
s.append(sq[0])
s.extend(sorted(s[1:]))
lev = 1
pra = n-1
while abs(lev-pra) >= 1:
s8 = sum(s[:(lev+pra)//2+1])
## print(lev,pra)
if abs(l... | 0 | |
192 | B | Walking in the Rain | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of *n* tiles that are lain in a row and are numbered from 1 to *n* from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number *n*. During the walk it is allowed to move... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the boulevard's length in tiles.
The second line contains *n* space-separated integers *a**i* — the number of days after which the *i*-th tile gets destroyed (1<=≤<=*a**i*<=≤<=103). | Print a single number — the sought number of days. | [
"4\n10 3 5 10\n",
"5\n10 2 8 3 5\n"
] | [
"5\n",
"5\n"
] | In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed ... | 1,000 | [
{
"input": "4\n10 3 5 10",
"output": "5"
},
{
"input": "5\n10 2 8 3 5",
"output": "5"
},
{
"input": "10\n10 3 1 6 7 1 3 3 8 1",
"output": "1"
},
{
"input": "10\n26 72 10 52 2 5 61 2 39 64",
"output": "5"
},
{
"input": "100\n8 2 1 2 8 3 5 8 5 1 9 3 4 1 5 6 4 2 9 10... | 1,696,788,816 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 85 | 124 | 1,740,800 | n = int(input())
a = list(map(int, input().split()))
res = 0
while True:
if a[0] == 0 or a[-1] == 0:
print(res)
break
j = 0
while j < n:
if j == n - 1:
break
if j + 2 < n and a[j + 2] > 0:
j += 2
elif j + 1 < n and a[... | Title: Walking in the Rain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of *n* tiles that are lain in a row and are numbered from 1 to *n* from right to left. The opposition should start ... | ```python
n = int(input())
a = list(map(int, input().split()))
res = 0
while True:
if a[0] == 0 or a[-1] == 0:
print(res)
break
j = 0
while j < n:
if j == n - 1:
break
if j + 2 < n and a[j + 2] > 0:
j += 2
elif j + 1 ... | 3 | |
659 | A | Round House | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th... | The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. | Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n"
] | [
"3\n",
"4\n",
"3\n"
] | The first example is illustrated by the picture in the statements. | 500 | [
{
"input": "6 2 -5",
"output": "3"
},
{
"input": "5 1 3",
"output": "4"
},
{
"input": "3 2 7",
"output": "3"
},
{
"input": "1 1 0",
"output": "1"
},
{
"input": "1 1 -1",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 ... | 1,559,093,710 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 108 | 0 | n=int(input())
a=int(input())
b=int(input())
print((a+(b%n))%n) | Title: Round House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in e... | ```python
n=int(input())
a=int(input())
b=int(input())
print((a+(b%n))%n)
``` | -1 | |
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the mini... | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th ... | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697... | 1,687,216,770 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def minimabacteria(x):
bacteria_contador= 1
dias = 0
while bacteria_contador<x:
bacteria_contador*=2
dias += 1
return dias
x=int(input())
min_bacterias_contador= minimabacteria(x)
print(min_bacterias_contador)
| Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split... | ```python
def minimabacteria(x):
bacteria_contador= 1
dias = 0
while bacteria_contador<x:
bacteria_contador*=2
dias += 1
return dias
x=int(input())
min_bacterias_contador= minimabacteria(x)
print(min_bacterias_contador)
``` | 0 | |
584 | B | Kolya and Tanya | PROGRAMMING | 1,500 | [
"combinatorics"
] | null | null | Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle.
More formally, there are 3*n* gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the ... | A single line contains number *n* (1<=≤<=*n*<=≤<=105) — the number of the gnomes divided by three. | Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109<=+<=7. | [
"1\n",
"2\n"
] | [
"20",
"680"
] | 20 ways for *n* = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <img class="tex-graphics" src="https://espresso.codeforces.com/64df38b85ccb482cf88d02dc52e348e33313f9da.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "1",
"output": "20"
},
{
"input": "2",
"output": "680"
},
{
"input": "3",
"output": "19340"
},
{
"input": "4",
"output": "529040"
},
{
"input": "5",
"output": "14332100"
},
{
"input": "7",
"output": "459529590"
},
{
"input": "10"... | 1,677,467,333 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 46 | 0 | # LUOGU_RID: 103165456
n, m = int(input()), 1000000007
print((pow(27, n, m) - pow(7, n, m)) % m) | Title: Kolya and Tanya
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle.
More formally, there are 3*n* gnomes sitting in a ... | ```python
# LUOGU_RID: 103165456
n, m = int(input()), 1000000007
print((pow(27, n, m) - pow(7, n, m)) % m)
``` | 3 | |
796 | A | Buying A House | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house ... | The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=... | Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy. | [
"5 1 20\n0 27 32 21 19\n",
"7 3 50\n62 0 0 0 99 33 22\n",
"10 5 100\n1 0 1 0 0 0 0 0 1 1\n"
] | [
"40",
"30",
"20"
] | In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters.
In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 a... | 500 | [
{
"input": "5 1 20\n0 27 32 21 19",
"output": "40"
},
{
"input": "7 3 50\n62 0 0 0 99 33 22",
"output": "30"
},
{
"input": "10 5 100\n1 0 1 0 0 0 0 0 1 1",
"output": "20"
},
{
"input": "5 3 1\n1 1 0 0 1",
"output": "10"
},
{
"input": "5 5 5\n1 0 5 6 0",
"outpu... | 1,494,236,260 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 62 | 0 | n, m, k = map(int, input().split())
ls = list(map(int, input().split()))
ans = []
m = m-1
for x in range(len(ls)):
if ls[x] != 0 and ls[x]<k:
ans = ans + [(abs(m-x))]
print (10*(min(ans))) | Title: Buying A House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight li... | ```python
n, m, k = map(int, input().split())
ls = list(map(int, input().split()))
ans = []
m = m-1
for x in range(len(ls)):
if ls[x] != 0 and ls[x]<k:
ans = ans + [(abs(m-x))]
print (10*(min(ans)))
``` | -1 | |
928 | A | Login Verification | PROGRAMMING | 1,200 | [
"*special",
"strings"
] | null | null | When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds ... | The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins.
The next *n* lines describe the exi... | Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes). | [
"1_wat\n2\n2_wat\nwat_1\n",
"000\n3\n00\nooA\noOo\n",
"_i_\n3\n__i_\n_1_\nI\n",
"La0\n3\n2a0\nLa1\n1a0\n",
"abc\n1\naBc\n",
"0Lil\n2\nLIL0\n0Ril\n"
] | [
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"Yes\n"
] | In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one. | 500 | [
{
"input": "1_wat\n2\n2_wat\nwat_1",
"output": "Yes"
},
{
"input": "000\n3\n00\nooA\noOo",
"output": "No"
},
{
"input": "_i_\n3\n__i_\n_1_\nI",
"output": "No"
},
{
"input": "La0\n3\n2a0\nLa1\n1a0",
"output": "No"
},
{
"input": "abc\n1\naBc",
"output": "No"
}... | 1,519,487,710 | 1,210 | Python 3 | OK | TESTS | 73 | 77 | 5,632,000 | def unify_login(login):
login = login.lower()
login = login.replace('0', 'o')
login = login.replace('l', '1')
login = login.replace('i', '1')
return login
s = unify_login(input())
n = int(input())
logins = set()
for i in range(n):
logins.add(unify_login(input()))
if s in logins:
print('... | Title: Login Verification
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercas... | ```python
def unify_login(login):
login = login.lower()
login = login.replace('0', 'o')
login = login.replace('l', '1')
login = login.replace('i', '1')
return login
s = unify_login(input())
n = int(input())
logins = set()
for i in range(n):
logins.add(unify_login(input()))
if s in logins:
... | 3 | |
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* ... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182... | 1,597,069,516 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 218 | 6,963,200 | from sys import stdin
def dfs(visited, l, i):
visited[i]= True
for j in range(n):
if not visited[j]:
if l[j][0]==l[i][0] or l[j][1]==l[i][1]:
dfs(visited,l,j)
n = int(stdin.readline().rstrip())
l = list()
for _ in range(n):
a, b = map(int, stdin.readli... | Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha... | ```python
from sys import stdin
def dfs(visited, l, i):
visited[i]= True
for j in range(n):
if not visited[j]:
if l[j][0]==l[i][0] or l[j][1]==l[i][1]:
dfs(visited,l,j)
n = int(stdin.readline().rstrip())
l = list()
for _ in range(n):
a, b = map(int, st... | 3 | |
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"ou... | 1,613,801,132 | 2,147,483,647 | PyPy 3 | OK | TESTS | 96 | 1,356 | 3,276,800 | def div(x):
i=1;ans=[]
while i*i<=n:
if x%i==0 and i!=x//i:ans.append(i);ans.append(x//i)
elif x%i==0:ans.append(i)
i+=1
return ans
n,k=map(int,input().split())
ans=div(n)
if len(ans)<k:print(-1)
else:ans=sorted(ans);print(ans[k-1])
| Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specificatio... | ```python
def div(x):
i=1;ans=[]
while i*i<=n:
if x%i==0 and i!=x//i:ans.append(i);ans.append(x//i)
elif x%i==0:ans.append(i)
i+=1
return ans
n,k=map(int,input().split())
ans=div(n)
if len(ans)<k:print(-1)
else:ans=sorted(ans);print(ans[k-1])
``` | 3 | |
913 | A | Modular Exponentiation | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108).
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108). | Output a single integer — the value of . | [
"4\n42\n",
"1\n58\n",
"98765432\n23456789\n"
] | [
"10\n",
"0\n",
"23456789\n"
] | In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10.
In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0. | 500 | [
{
"input": "4\n42",
"output": "10"
},
{
"input": "1\n58",
"output": "0"
},
{
"input": "98765432\n23456789",
"output": "23456789"
},
{
"input": "8\n88127381",
"output": "149"
},
{
"input": "32\n92831989",
"output": "92831989"
},
{
"input": "92831989\n25... | 1,628,020,496 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 109 | 33,177,600 | n=int(input())
m=int(input())
x=pow(m,1,2**n)
print(x) | Title: Modular Exponentiation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" prob... | ```python
n=int(input())
m=int(input())
x=pow(m,1,2**n)
print(x)
``` | 3 | |
967 | B | Watering System | PROGRAMMING | 1,000 | [
"math",
"sortings"
] | null | null | Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After... | The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$)... | Print a single integer — the number of holes Arkady should block. | [
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] | [
"1\n",
"0\n",
"4\n"
] | In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not les... | 1,000 | [
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 ... | 1,525,349,248 | 1,348 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 77 | 21,401,600 | import sys
read=lambda:map(int,sys.stdin.buffer.readline().split())
n,A,B=read()
v=list(read())
f=v[0]
s=sum(v)
v.pop(0)
v.sort()
for i in range(n):
if f*A>=B*s: print(i);break
s-=v[i] | Title: Watering System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the fi... | ```python
import sys
read=lambda:map(int,sys.stdin.buffer.readline().split())
n,A,B=read()
v=list(read())
f=v[0]
s=sum(v)
v.pop(0)
v.sort()
for i in range(n):
if f*A>=B*s: print(i);break
s-=v[i]
``` | 0 | |
230 | B | T-primes | PROGRAMMING | 1,300 | [
"binary search",
"implementation",
"math",
"number theory"
] | null | null | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. | The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout st... | Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. | [
"3\n4 5 6\n"
] | [
"YES\nNO\nNO\n"
] | The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | 500 | [
{
"input": "3\n4 5 6",
"output": "YES\nNO\nNO"
},
{
"input": "2\n48 49",
"output": "NO\nYES"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "1\n36",
"output": "NO"
},
{
"input": "1\n999966000289",
"... | 1,698,683,339 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 436 | 12,083,200 | def sieve_of_eratosthenes(limit):
sieve = [True] * (limit + 1)
sieve[0] = sieve[1] = False
for i in range(2, int(limit**0.5) + 1):
if sieve[i]:
for j in range(i * i, limit + 1, i):
sieve[j] = False
return [i for i in range(limit + 1) if sieve[i]]
def is_t_pr... | Title: T-primes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an ar... | ```python
def sieve_of_eratosthenes(limit):
sieve = [True] * (limit + 1)
sieve[0] = sieve[1] = False
for i in range(2, int(limit**0.5) + 1):
if sieve[i]:
for j in range(i * i, limit + 1, i):
sieve[j] = False
return [i for i in range(limit + 1) if sieve[i]]
d... | 0 | |
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat... | The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one ... | Print one integer number — the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5... | 1,522,376,648 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 93 | 7,065,600 | #http://codeforces.com/problemset/problem/915/A
numBuckets, garLen = map(int, input().split())
buckets = list(map(int,input().split()))
biggest = 0
for x in buckets:
if(garLen%x == 0 and x > biggest):
biggest = x
else:
pass
print(int(garLen/biggest)) | Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each ... | ```python
#http://codeforces.com/problemset/problem/915/A
numBuckets, garLen = map(int, input().split())
buckets = list(map(int,input().split()))
biggest = 0
for x in buckets:
if(garLen%x == 0 and x > biggest):
biggest = x
else:
pass
print(int(garLen/biggest))
``` | 3 | |
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and c... | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",... | 1,663,850,195 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 156 | 2,457,600 | a = set([i*(i+1)//2 for i in range(1,50000)])
n = int(input())
print("YES" if any(n-t in a for t in a) else "NO") | Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent... | ```python
a = set([i*(i+1)//2 for i in range(1,50000)])
n = int(input())
print("YES" if any(n-t in a for t in a) else "NO")
``` | 3 | |
989 | B | A Tide of Riverscape | PROGRAMMING | 1,200 | [
"constructive algorithms",
"strings"
] | null | null | "Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks a... | The first line contains two space-separated integers $n$ and $p$ ($1 \leq p \leq n \leq 2000$) — the length of the given string and the supposed period, respectively.
The second line contains a string $s$ of $n$ characters — Mino's records. $s$ only contains characters '0', '1' and '.', and contains at least one '.' c... | Output one line — if it's possible that $p$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)). | [
"10 7\n1.0.1.0.1.\n",
"10 6\n1.0.1.1000\n",
"10 9\n1........1\n"
] | [
"1000100010\n",
"1001101000\n",
"No\n"
] | In the first example, $7$ is not a period of the resulting string because the $1$-st and $8$-th characters of it are different.
In the second example, $6$ is not a period of the resulting string because the $4$-th and $10$-th characters of it are different.
In the third example, $9$ is always a period because the onl... | 1,000 | [
{
"input": "10 7\n1.0.1.0.1.",
"output": "1000100010"
},
{
"input": "10 6\n1.0.1.1000",
"output": "1001101000"
},
{
"input": "10 9\n1........1",
"output": "No"
},
{
"input": "1 1\n.",
"output": "No"
},
{
"input": "5 1\n0...1",
"output": "00001"
},
{
"i... | 1,557,318,872 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 93 | 0 | n,p=map(int,input().split())
s=list(input())
made_no_p=0
for i in range(n//2):
if s[i]=='?':
if i+p<n :
if s[i+p]=='?':
s[i]='1'
s[i+p]='0'
made_no_p=1
elif s[i+p]=='0':
s[i]='1'
made_no_p=1... | Title: A Tide of Riverscape
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its... | ```python
n,p=map(int,input().split())
s=list(input())
made_no_p=0
for i in range(n//2):
if s[i]=='?':
if i+p<n :
if s[i+p]=='?':
s[i]='1'
s[i+p]='0'
made_no_p=1
elif s[i+p]=='0':
s[i]='1'
m... | 0 | |
740 | B | Alyona and flowers | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | null | null | Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative.
Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choos... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of flowers and the number of subarrays suggested by the mother.
The second line contains the flowers moods — *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≤<=*a**i*<=≤<=100).
The next *m* lines contain the description of the ... | Print single integer — the maximum possible value added to the Alyona's happiness. | [
"5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n",
"4 3\n1 2 3 4\n1 3\n2 4\n1 1\n",
"2 2\n-1 -2\n1 1\n1 2\n"
] | [
"7\n",
"16\n",
"0\n"
] | The first example is the situation described in the statements.
In the second example Alyona should choose all subarrays.
The third example has answer 0 because Alyona can choose none of the subarrays. | 1,000 | [
{
"input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4",
"output": "7"
},
{
"input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1",
"output": "16"
},
{
"input": "2 2\n-1 -2\n1 1\n1 2",
"output": "0"
},
{
"input": "5 6\n1 1 1 -1 0\n2 4\n1 3\n4 5\n1 5\n1 4\n4 5",
"output": "8"
},
{
"inpu... | 1,479,921,043 | 2,143 | Python 3 | OK | TESTS | 53 | 93 | 0 | n, m = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0
for i in range(m):
s, e = map(int, input().split())
t = sum(a[s-1:e])
if t > 0:
ans += t
print(ans)
| Title: Alyona and flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative.
Let's define a subarra... | ```python
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0
for i in range(m):
s, e = map(int, input().split())
t = sum(a[s-1:e])
if t > 0:
ans += t
print(ans)
``` | 3 | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,694,079,944 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | # Input the total number of levels
n = int(input())
# Input levels Little X can pass
p, *x_levels = map(int, input().split())
# Input levels Little Y can pass
q, *y_levels = map(int, input().split())
# Create a set of levels that Little X can pass
x_set = set(x_levels)
# Create a set of levels that Litt... | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
# Input the total number of levels
n = int(input())
# Input levels Little X can pass
p, *x_levels = map(int, input().split())
# Input levels Little Y can pass
q, *y_levels = map(int, input().split())
# Create a set of levels that Little X can pass
x_set = set(x_levels)
# Create a set of levels... | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,652,422,159 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 62 | 0 | hello = ["h", "e", "l", "l", "o"]
test = input()
index = -1
for letter in hello:
try:
index = test.index(letter, index + 1)
except ValueError:
print("NO")
exit(0)
print("YES") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
hello = ["h", "e", "l", "l", "o"]
test = input()
index = -1
for letter in hello:
try:
index = test.index(letter, index + 1)
except ValueError:
print("NO")
exit(0)
print("YES")
``` | 3.969 |
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. It... | 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,694,067,982 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 92 | 0 | n = int(input())
tnum = input()
counter = 0
for i in range(len(tnum)):
if tnum[i] == '7' or tnum[i] == '4':
continue
else:
counter +=1
if counter == 0:
s1 = 0
s2 = 0
for i in range(n//2):
s1 += int(tnum[i])
for i in range(n//2,n):
s2 += int(tnum[i])
... | 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.
... | ```python
n = int(input())
tnum = input()
counter = 0
for i in range(len(tnum)):
if tnum[i] == '7' or tnum[i] == '4':
continue
else:
counter +=1
if counter == 0:
s1 = 0
s2 = 0
for i in range(n//2):
s1 += int(tnum[i])
for i in range(n//2,n):
s2 += int... | 3 | |
892 | B | Wrath | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=<<=*i* and *... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — the number of guilty people.
Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=≤<=*L**i*<=≤<=109), where *L**i* is the length of the *i*-th person's claw. | Print one integer — the total number of alive people after the bell rings. | [
"4\n0 1 0 10\n",
"2\n0 0\n",
"10\n1 1 3 0 0 0 2 1 0 3\n"
] | [
"1\n",
"2\n",
"3\n"
] | In first sample the last person kills everyone in front of him. | 1,000 | [
{
"input": "4\n0 1 0 10",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "10\n1 1 3 0 0 0 2 1 0 3",
"output": "3"
},
{
"input": "10\n0 0 2 0 0 3 3 2 2 0",
"output": "2"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "5\n0 0 0 1 0"... | 1,512,862,507 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 84,889,600 | n = int(input())
p = [int(i) for i in input().split()][::-1]
a = {}
for i in range(n-1):
if p[i] > 0:
for j in range(i+1, min(n, i+1+p[i])):
a[j] = 1
print(n - len(a.keys())) | Title: Wrath
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same ... | ```python
n = int(input())
p = [int(i) for i in input().split()][::-1]
a = {}
for i in range(n-1):
if p[i] > 0:
for j in range(i+1, min(n, i+1+p[i])):
a[j] = 1
print(n - len(a.keys()))
``` | 0 | |
439 | B | Devu, the Dumb Guy | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is *x* hours. In other ... | The first line will contain two space separated integers *n*, *x* (1<=≤<=*n*,<=*x*<=≤<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105). | Output a single integer representing the answer to the problem. | [
"2 3\n4 1\n",
"4 2\n5 1 2 1\n",
"3 3\n1 1 1\n"
] | [
"11\n",
"10\n",
"6\n"
] | Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 ... | 1,000 | [
{
"input": "2 3\n4 1",
"output": "11"
},
{
"input": "4 2\n5 1 2 1",
"output": "10"
},
{
"input": "3 3\n1 1 1",
"output": "6"
},
{
"input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3",
"output": "65"
},
{
"input": "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3... | 1,524,197,719 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 187 | 14,438,400 | n, x = map(int, input().split())
c = sorted(map(int, input().split()))
p = x
result = 0
for ci in c:
result += p * ci
if p > 1:
p -= 1
print(result) | Title: Devu, the Dumb Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject co... | ```python
n, x = map(int, input().split())
c = sorted(map(int, input().split()))
p = x
result = 0
for ci in c:
result += p * ci
if p > 1:
p -= 1
print(result)
``` | 3 | |
554 | A | Kyoya and Photobooks | PROGRAMMING | 900 | [
"brute force",
"math",
"strings"
] | null | null | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters. | Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. | [
"a\n",
"hi\n"
] | [
"51\n",
"76\n"
] | In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | 250 | [
{
"input": "a",
"output": "51"
},
{
"input": "hi",
"output": "76"
},
{
"input": "y",
"output": "51"
},
{
"input": "kgan",
"output": "126"
},
{
"input": "zoabkyuvus",
"output": "276"
},
{
"input": "spyemhyznjieyhhbk",
"output": "451"
},
{
"i... | 1,606,794,189 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 139 | 0 | s=input()
print(26*(len(s)+1)-len(s)) | Title: Kyoya and Photobooks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos b... | ```python
s=input()
print(26*(len(s)+1)-len(s))
``` | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,689,597,564 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a=0
x=int(input())
while(x!=0):
c=input()
if(c=="X++" or c=="++X")
a+=1
elif(c=="X--" or c=="--X")
a-=1
print(a) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
a=0
x=int(input())
while(x!=0):
c=input()
if(c=="X++" or c=="++X")
a+=1
elif(c=="X--" or c=="--X")
a-=1
print(a)
``` | -1 |
400 | A | Inna and Choose Options | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"... | The first line of the input contains integer *t* (1<=≤<=*t*<=≤<=100). This value shows the number of sets of test data in the input. Next follows the description of each of the *t* tests on a separate line.
The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The ... | For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair *a*,<=*b*. Next, print on this line the pairs in the format *a*x*b*. Print the pairs in the order of increasing first parameter (*a*). Separate the pairs in the line b... | [
"4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO\n"
] | [
"3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0\n"
] | none | 500 | [
{
"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO",
"output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0"
},
{
"input": "2\nOOOOOOOOOOOO\nXXXXXXXXXXXX",
"output": "0\n6 1x12 2x6 3x4 4x3 6x2 12x1"
},
{
"input": "13\nXXXXXXXXXXXX\nXXXXXXXXXXXX\n... | 1,557,757,538 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 140 | 0 | def is_possible(request, a):
b = 12 // a
for i in range(b):
if 'O' not in [request[i + j * b] for j in range(a)]:
return True
return False
def solve(request):
possible_ways = [1, 2, 3, 4, 6, 12]
count_ways = 0
ways = []
for i in possible_ways:
if is_possible... | Title: Inna and Choose Options
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game.... | ```python
def is_possible(request, a):
b = 12 // a
for i in range(b):
if 'O' not in [request[i + j * b] for j in range(a)]:
return True
return False
def solve(request):
possible_ways = [1, 2, 3, 4, 6, 12]
count_ways = 0
ways = []
for i in possible_ways:
if i... | 3 | |
315 | A | Sereja and Bottles | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. | In a single line print a single integer — the answer to the problem. | [
"4\n1 1\n2 2\n3 3\n4 4\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] | [
"4\n",
"0\n"
] | none | 500 | [
{
"input": "4\n1 1\n2 2\n3 3\n4 4",
"output": "4"
},
{
"input": "4\n1 2\n2 3\n3 4\n4 1",
"output": "0"
},
{
"input": "3\n2 828\n4 392\n4 903",
"output": "3"
},
{
"input": "4\n2 3\n1 772\n3 870\n3 668",
"output": "2"
},
{
"input": "5\n1 4\n6 6\n4 3\n3 4\n4 758",
... | 1,657,033,881 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 560 | 5,529,600 | import math
import bisect
from typing import Set
def input_list_int():
return list(map(int, input().split()))
n = int(input())
p = {}
for i in range(n):
a, b = input_list_int()
if a in p.keys():
p[a].append(b)
else:
p[a] = [b]
opened = set()
for key, values in p.ite... | Title: Sereja and Bottles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th... | ```python
import math
import bisect
from typing import Set
def input_list_int():
return list(map(int, input().split()))
n = int(input())
p = {}
for i in range(n):
a, b = input_list_int()
if a in p.keys():
p[a].append(b)
else:
p[a] = [b]
opened = set()
for key, value... | 0 | |
591 | A | Wizards' Duel | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and... | The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ... | Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer ... | [
"100\n50\n50\n",
"199\n60\n40\n"
] | [
"50\n",
"119.4\n"
] | In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | 500 | [
{
"input": "100\n50\n50",
"output": "50"
},
{
"input": "199\n60\n40",
"output": "119.4"
},
{
"input": "1\n1\n1",
"output": "0.5"
},
{
"input": "1\n1\n500",
"output": "0.001996007984"
},
{
"input": "1\n500\n1",
"output": "0.998003992"
},
{
"input": "1\n... | 1,501,729,216 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 77 | 4,608,000 | n = int(input())
p = int(input())
q = int(input())
print(n/(p+q)*p) | Title: Wizards' Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en... | ```python
n = int(input())
p = int(input())
q = int(input())
print(n/(p+q)*p)
``` | 3 | |
858 | D | Polycarp's phone book | PROGRAMMING | 1,600 | [
"data structures",
"implementation",
"sortings"
] | null | null | There are *n* phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct.
There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for w... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=70000) — the total number of phone contacts in Polycarp's contacts.
The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. | Print exactly *n* lines: the *i*-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the *i*-th number from the contacts. If there are several such sequences, print any of them. | [
"3\n123456789\n100000000\n100123456\n",
"4\n123456789\n193456789\n134567819\n934567891\n"
] | [
"9\n000\n01\n",
"2\n193\n81\n91\n"
] | none | 2,000 | [
{
"input": "3\n123456789\n100000000\n100123456",
"output": "9\n000\n01"
},
{
"input": "4\n123456789\n193456789\n134567819\n934567891",
"output": "2\n193\n81\n91"
},
{
"input": "1\n167038488",
"output": "4"
},
{
"input": "5\n115830748\n403459907\n556271610\n430358099\n41396141... | 1,588,244,130 | 2,147,483,647 | PyPy 3 | OK | TESTS | 53 | 2,839 | 85,708,800 | n=int(input())
a=[]
d={}
for _ in range(n):
s=input()
g=set()
for i in range(len(s)):
for k in range(i,len(s)):
st=s[i:k+1]
if st in g:
continue
else:
g.add(st)
if st in d:
d[st]+=1
... | Title: Polycarp's phone book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct.
There is the latest version of Berdroid OS ... | ```python
n=int(input())
a=[]
d={}
for _ in range(n):
s=input()
g=set()
for i in range(len(s)):
for k in range(i,len(s)):
st=s[i:k+1]
if st in g:
continue
else:
g.add(st)
if st in d:
d[st]... | 3 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,659,706,035 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 156 | 0 |
t = input()
str1 = ""
i=0
while True:
try:
if t[i]=='.':
str1 +='0'
else:
if(t[i+1]=='.'):
str1+='1'
i = i+1
else:
str1+='2'
i = i+1
i+=1
except:
break
print(str... | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
t = input()
str1 = ""
i=0
while True:
try:
if t[i]=='.':
str1 +='0'
else:
if(t[i+1]=='.'):
str1+='1'
i = i+1
else:
str1+='2'
i = i+1
i+=1
except:
break
... | 3.961 |
250 | A | Paper Work | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know that the main information in a day report is value *a**i*, the company's profit on the *i*-th day. ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), *n* is the number of days. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=100), where *a**i* means the company profit on the *i*-th day. It is possible that the company has no days with the negative *a**i*. | Print an integer *k* — the required minimum number of folders. In the second line print a sequence of integers *b*1, *b*2, ..., *b**k*, where *b**j* is the number of day reports in the *j*-th folder.
If there are multiple ways to sort the reports into *k* days, print any of them. | [
"11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\n",
"5\n0 -1 100 -1 0\n"
] | [
"3\n5 3 3 ",
"1\n5 "
] | Here goes a way to sort the reports from the first sample into three folders:
In the second sample you can put all five reports in one folder. | 500 | [
{
"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6",
"output": "3\n5 3 3 "
},
{
"input": "5\n0 -1 100 -1 0",
"output": "1\n5 "
},
{
"input": "1\n0",
"output": "1\n1 "
},
{
"input": "1\n-1",
"output": "1\n1 "
},
{
"input": "2\n0 0",
"output": "1\n2 "
},
{
"inp... | 1,591,726,709 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 218 | 0 |
a = int(input())
t = list(map(int,input().split()))
p=0
for k in range(a):
if t[k]<0:
p+=1
b = p//2
s =a-p
if p%2==0:
f=[2]*b
else:
f=[2]*b+[1]
for y in range(len(f)):
if s>0:
if y!=len(f)-1:
f[y]+=1
s-=1
else:
... | Title: Paper Work
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know tha... | ```python
a = int(input())
t = list(map(int,input().split()))
p=0
for k in range(a):
if t[k]<0:
p+=1
b = p//2
s =a-p
if p%2==0:
f=[2]*b
else:
f=[2]*b+[1]
for y in range(len(f)):
if s>0:
if y!=len(f)-1:
f[y]+=1
s-=1
els... | 0 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,664,952,572 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | x=[60, 90, 108, 120, 128, 135, 140, 144, 147, 150, 152, 154, 156, 157, 158, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179]
for i in range(int(input())):
if int(input()) in x: print('YES')
else: print('NO') | Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can... | ```python
x=[60, 90, 108, 120, 128, 135, 140, 144, 147, 150, 152, 154, 156, 157, 158, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179]
for i in range(int(input())):
if int(input()) in x: print('YES')
else: print('NO')
``` | 0 | |
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 ... | 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 ... | 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,427,387,753 | 353 | PyPy 3 | OK | TESTS | 46 | 124 | 2,150,400 | n=int(input())
a=[0 for i in range(26)]
s=input().strip()
ans=0
for i in range(n-1):
a[ord(s[2*i])-97]+=1
if a[ord(s[2*i+1])-65]>0:
a[ord(s[2*i+1])-65]-=1
else:
ans+=1
print(ans) | 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... | ```python
n=int(input())
a=[0 for i in range(26)]
s=input().strip()
ans=0
for i in range(n-1):
a[ord(s[2*i])-97]+=1
if a[ord(s[2*i+1])-65]>0:
a[ord(s[2*i+1])-65]-=1
else:
ans+=1
print(ans)
``` | 3 | |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,689,313,056 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | strr = input()
k = True
for i in range(1, len(strr)):
if strr[i].islower():
k = False
if k == True:
s = ''
for i in range(len(strr)):
if strr[i].islower():
s += strr[i].upper()
else:
s += strr[i].lower()
print(s)
print(strr) | Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
strr = input()
k = True
for i in range(1, len(strr)):
if strr[i].islower():
k = False
if k == True:
s = ''
for i in range(len(strr)):
if strr[i].islower():
s += strr[i].upper()
else:
s += strr[i].lower()
print(s)
print(strr)
``` | 0 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,696,925,744 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | #2300015804
n=int(input())
ang=[int(x) for x in input().split()]
for i in range(n):
if 360%(180-ang[i])==0: print("YES")
else: print("NO") | Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can... | ```python
#2300015804
n=int(input())
ang=[int(x) for x in input().split()]
for i in range(n):
if 360%(180-ang[i])==0: print("YES")
else: print("NO")
``` | -1 | |
659 | A | Round House | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th... | The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. | Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n"
] | [
"3\n",
"4\n",
"3\n"
] | The first example is illustrated by the picture in the statements. | 500 | [
{
"input": "6 2 -5",
"output": "3"
},
{
"input": "5 1 3",
"output": "4"
},
{
"input": "3 2 7",
"output": "3"
},
{
"input": "1 1 0",
"output": "1"
},
{
"input": "1 1 -1",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 ... | 1,620,195,566 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 61 | 0 | n, a, b = map(int, input().split())
ans = a
if b >= 0:
ans += b
else:
k = b - 2*b
k -= ans
ans = k % n
if ans % n != 0:
print(ans % n)
else:
print(n)
| Title: Round House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in e... | ```python
n, a, b = map(int, input().split())
ans = a
if b >= 0:
ans += b
else:
k = b - 2*b
k -= ans
ans = k % n
if ans % n != 0:
print(ans % n)
else:
print(n)
``` | 0 | |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,691,416,158 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | # N,M = map(int,input().split())
# N = int(input())
# A = list(map(int,input().split()))
N = int(input())
res = 0
cur = 0
for _ in range(N):
a,b = map(int,input().split())
cur -= a
cur += b
res = max(res, cur)
print(res)
| Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
# N,M = map(int,input().split())
# N = int(input())
# A = list(map(int,input().split()))
N = int(input())
res = 0
cur = 0
for _ in range(N):
a,b = map(int,input().split())
cur -= a
cur += b
res = max(res, cur)
print(res)
``` | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.