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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
975 | B | Mancala | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.
Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next ... | The only line contains 14 integers $a_1, a_2, \ldots, a_{14}$ ($0 \leq a_i \leq 10^9$) — the number of stones in each hole.
It is guaranteed that for any $i$ ($1\leq i \leq 14$) $a_i$ is either zero or odd, and there is at least one stone in the board. | Output one integer, the maximum possible score after one move. | [
"0 1 1 0 0 0 0 0 0 7 0 0 0 0\n",
"5 1 1 1 1 0 0 0 0 0 0 0 0 0\n"
] | [
"4\n",
"8\n"
] | In the first test case the board after the move from the hole with $7$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $4$. | 1,000 | [
{
"input": "0 1 1 0 0 0 0 0 0 7 0 0 0 0",
"output": "4"
},
{
"input": "5 1 1 1 1 0 0 0 0 0 0 0 0 0",
"output": "8"
},
{
"input": "10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 1",
"output": "54294"
},
{
"input": "0 0 0 0 0 0 0 0 0 0 0 0 0 15",
... | 1,655,049,431 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 1,843,200 | arr = list(map(int, input().split()))
maxx = 0
idx = -1
n = len(arr)
for i in range(len(arr)):
if arr[i]>maxx:
maxx = arr[i]
idx = i
for i in range(idx+1, idx+maxx+1):
arr[i%n] += 1
ans = 0
for i in range(n):
if arr[i]%2==0:
ans+=arr[i]
print(ans) | Title: Mancala
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.
Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. ... | ```python
arr = list(map(int, input().split()))
maxx = 0
idx = -1
n = len(arr)
for i in range(len(arr)):
if arr[i]>maxx:
maxx = arr[i]
idx = i
for i in range(idx+1, idx+maxx+1):
arr[i%n] += 1
ans = 0
for i in range(n):
if arr[i]%2==0:
ans+=arr[i]
print(ans)
``` | 0 | |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
... | 1,608,442,097 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 1,526 | 0 | #code
def isprime(x):
if x==1:
return False
for i in range(2,x):
if x%i==0:
return False
return True
##print(isprime(10))
n=int(input())
c=0
for i in range(1,n+1):
count=0
for j in range(1,i):
if i%j==0:
if isprime(j):
... | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
#code
def isprime(x):
if x==1:
return False
for i in range(2,x):
if x%i==0:
return False
return True
##print(isprime(10))
n=int(input())
c=0
for i in range(1,n+1):
count=0
for j in range(1,i):
if i%j==0:
if isprime... | 3.6185 |
814 | B | An express train to reveries | PROGRAMMING | 1,300 | [
"constructive algorithms"
] | null | null | Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.
On that night, Sengoku constructed a permutation *p*1,<=*p*2,<=...,<=*p**n* of intege... | The first line of input contains a positive integer *n* (2<=≤<=*n*<=≤<=1<=000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of colours in the firs... | Output *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n*, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them.
Input guarantees that such permutation exists. | [
"5\n1 2 3 4 3\n1 2 5 4 5\n",
"5\n4 4 2 3 1\n5 4 5 3 1\n",
"4\n1 1 3 4\n1 4 3 4\n"
] | [
"1 2 5 4 3\n",
"5 4 2 3 1\n",
"1 2 3 4\n"
] | In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs.
In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints. | 1,000 | [
{
"input": "5\n1 2 3 4 3\n1 2 5 4 5",
"output": "1 2 5 4 3"
},
{
"input": "5\n4 4 2 3 1\n5 4 5 3 1",
"output": "5 4 2 3 1"
},
{
"input": "4\n1 1 3 4\n1 4 3 4",
"output": "1 2 3 4"
},
{
"input": "10\n1 2 3 4 7 6 7 8 9 10\n1 2 3 4 5 6 5 8 9 10",
"output": "1 2 3 4 5 6 7 8 9... | 1,496,847,562 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 62 | 307,200 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
contain = [1 for i in range(n)]
fail = []
res = []
for i, j in zip(a, b):
if i == j:
contain[i - 1] = 0
res.append(i)
else:
fail.append((i, j))
res.append(0)
falta = []
for i in range(n):
if contain[i] == 1:
falta.app... | Title: An express train to reveries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her... | ```python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
contain = [1 for i in range(n)]
fail = []
res = []
for i, j in zip(a, b):
if i == j:
contain[i - 1] = 0
res.append(i)
else:
fail.append((i, j))
res.append(0)
falta = []
for i in range(n):
if contain[i] == 1:
... | 3 | |
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i... | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 1,694,791,210 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 0 | n = int(input())
a = list(map(int, input().split()))
c = {}
for i in a:
if i in c:
c[i] += 1
else:
c[i] = 1
m = max(c.values())
print(m) | Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Po... | ```python
n = int(input())
a = list(map(int, input().split()))
c = {}
for i in a:
if i in c:
c[i] += 1
else:
c[i] = 1
m = max(c.values())
print(m)
``` | 3 | |
616 | B | Dinner with Emma | PROGRAMMING | 1,000 | [
"games",
"greedy"
] | null | null | Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The stree... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan.
Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue. | Print the only integer *a* — the cost of the dinner for Jack and Emma. | [
"3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n",
"3 3\n1 2 3\n2 3 1\n3 1 2\n"
] | [
"2\n",
"1\n"
] | In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the din... | 0 | [
{
"input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1",
"output": "2"
},
{
"input": "3 3\n1 2 3\n2 3 1\n3 1 2",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 10\n74 35 82 39 1 84 29 41 70 12",
"output": "1"
},
{
"input": "10 1\n44\n23\n65\n17\n48\n29\n... | 1,608,280,358 | 2,147,483,647 | PyPy 3 | OK | TESTS | 16 | 170 | 1,536,000 | n,m=map(int,input().split())
minim=-1
for _ in range(n):
k=list(map(int,input().split()))
if min(k)>minim:
minim=min(k)
print(minim)
| Title: Dinner with Emma
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and... | ```python
n,m=map(int,input().split())
minim=-1
for _ in range(n):
k=list(map(int,input().split()))
if min(k)>minim:
minim=min(k)
print(minim)
``` | 3 | |
334 | A | Candy Bags | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each b... | The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. | Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ... | [
"2\n"
] | [
"1 4\n2 3\n"
] | The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | 500 | [
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output"... | 1,561,108,547 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 248 | 614,400 | n, m = int(input()), []
for i in range(n):
m.append([0]*n)
if n % 2 == 0:
for j in range(n):
for i in range(n):
m[i][j] = n*j + ((n-i) if j % 2 == 1 else (i+1))
else:
px, py, v = 0, n//2, 1
while v <= n*n:
if m[px][py] != 0:
px = (px + 1)%n
m[px][py] = v
... | Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ... | ```python
n, m = int(input()), []
for i in range(n):
m.append([0]*n)
if n % 2 == 0:
for j in range(n):
for i in range(n):
m[i][j] = n*j + ((n-i) if j % 2 == 1 else (i+1))
else:
px, py, v = 0, n//2, 1
while v <= n*n:
if m[px][py] != 0:
px = (px + 1)%n
m[px... | 3 | |
959 | A | Mahmoud and Ehab and the even-odd game | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that:
- 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab'... | The only line contains an integer *n* (1<=≤<=*n*<=≤<=109), the number at the beginning of the game. | Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise. | [
"1\n",
"2\n"
] | [
"Ehab",
"Mahmoud"
] | In the first sample, Mahmoud can't choose any integer *a* initially because there is no positive even integer less than or equal to 1 so Ehab wins.
In the second sample, Mahmoud has to choose *a* = 2 and subtract it from *n*. It's Ehab's turn and *n* = 0. There is no positive odd integer less than or equal to 0 so Mah... | 500 | [
{
"input": "1",
"output": "Ehab"
},
{
"input": "2",
"output": "Mahmoud"
},
{
"input": "10000",
"output": "Mahmoud"
},
{
"input": "33333",
"output": "Ehab"
},
{
"input": "5",
"output": "Ehab"
},
{
"input": "1000000000",
"output": "Mahmoud"
},
{
... | 1,670,867,539 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | # https://codeforces.com/problemset/problem/959/A
# ehab first chosses n
n_ehab = int(input())
print ("Mahmoud") if n_ehab%2 ==0 else print("Ehab")
# a_mahmoud =# has to be even
# a_ehab = # has to be odd
| Title: Mahmoud and Ehab and the even-odd game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a*... | ```python
# https://codeforces.com/problemset/problem/959/A
# ehab first chosses n
n_ehab = int(input())
print ("Mahmoud") if n_ehab%2 ==0 else print("Ehab")
# a_mahmoud =# has to be even
# a_ehab = # has to be odd
``` | 3 | |
94 | B | Friends | PROGRAMMING | 1,300 | [
"graphs",
"implementation",
"math"
] | B. Friends | 1 | 256 | One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something.
The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people"
Igor just c... | The first line contains an integer *m* (0<=≤<=*m*<=≤<=10), which is the number of relations of acquaintances among the five friends of Igor's.
Each of the following *m* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=5;*a**i*<=≠<=*b**i*), where (*a**i*,<=*b**i*) is a pair of acquainted people.... | Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". | [
"4\n1 3\n2 3\n1 4\n5 3\n",
"5\n1 2\n2 3\n3 4\n4 5\n5 1\n"
] | [
"WIN\n",
"FAIL\n"
] | none | 1,000 | [
{
"input": "4\n1 3\n2 3\n1 4\n5 3",
"output": "WIN"
},
{
"input": "5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "FAIL"
},
{
"input": "1\n4 3",
"output": "WIN"
},
{
"input": "6\n1 3\n2 3\n1 2\n5 3\n4 2\n4 5",
"output": "WIN"
},
{
"input": "2\n1 3\n2 5",
"output": "WI... | 1,622,005,545 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 0 | l = []
for i in range(int(input())):
x, y = map(int, input().split())
if x not in l:
l.append(x)
if len(l) <= 3:
print('WIN')
else:
print('FAIL') | Title: Friends
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something.
The following statement caught his attention: "Among any six people there are ei... | ```python
l = []
for i in range(int(input())):
x, y = map(int, input().split())
if x not in l:
l.append(x)
if len(l) <= 3:
print('WIN')
else:
print('FAIL')
``` | 0 |
938 | A | Word Correction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction. | Output the word *s* after the correction. | [
"5\nweird\n",
"4\nword\n",
"5\naaeaa\n"
] | [
"werd\n",
"word\n",
"a\n"
] | Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <i... | 0 | [
{
"input": "5\nweird",
"output": "werd"
},
{
"input": "4\nword",
"output": "word"
},
{
"input": "5\naaeaa",
"output": "a"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw",
"output": "abbbbbocadabbbbb... | 1,550,587,507 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 109 | 0 | n=int(input())
ch=str(input())
l=list(ch)
#print(l)
for i in range(n-1):
if((l[i] in {'a','e','i','o','u','y'}) or (l[i] in {"."})):
if(l[i+1] in {'a','e','i','o','u','y'}):
l[i+1]="."
ch=""
for i in l:
if (i!="."):
ch=ch+i
print(ch)
| Title: Word Correction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird an... | ```python
n=int(input())
ch=str(input())
l=list(ch)
#print(l)
for i in range(n-1):
if((l[i] in {'a','e','i','o','u','y'}) or (l[i] in {"."})):
if(l[i+1] in {'a','e','i','o','u','y'}):
l[i+1]="."
ch=""
for i in l:
if (i!="."):
ch=ch+i
print(ch)
``` | 3 | |
975 | A | Aramic script | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$... | The first line contains one integer $n$ ($1 \leq n \leq 10^3$) — the number of words in the script.
The second line contains $n$ words $s_1, s_2, \ldots, s_n$ — the script itself. The length of each string does not exceed $10^3$.
It is guaranteed that all characters of the strings are small latin letters. | Output one integer — the number of different objects mentioned in the given ancient Aramic script. | [
"5\na aa aaa ab abb\n",
"3\namer arem mrea\n"
] | [
"2",
"1"
] | In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer". | 500 | [
{
"input": "5\na aa aaa ab abb",
"output": "2"
},
{
"input": "3\namer arem mrea",
"output": "1"
},
{
"input": "10\nbda bbb cda dca dda dcb bcd dcb ada ddd",
"output": "6"
},
{
"input": "2\nfhjlqs aceginpr",
"output": "2"
},
{
"input": "2\nbcdfghimn efghijlmo",
... | 1,667,893,897 | 97 | PyPy 3-64 | OK | TESTS | 30 | 124 | 7,475,200 | import sys
from math import factorial
input = sys.stdin.readline
#X,Y,Z = list(map(int,input().strip().split()))
n = input()
arr = list(map(str,input().strip().split()))
roots = []
for i in arr:
word = []
for j in i :
if j not in word:
word.append(j)
roots.append(word)
s... | Title: Aramic script
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the ... | ```python
import sys
from math import factorial
input = sys.stdin.readline
#X,Y,Z = list(map(int,input().strip().split()))
n = input()
arr = list(map(str,input().strip().split()))
roots = []
for i in arr:
word = []
for j in i :
if j not in word:
word.append(j)
roots.appen... | 3 | |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,687,259,682 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 92 | 0 | # -*- coding: utf-8 -*-
"""141A.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1YAcE_C3NXDvEY0NY_rHyte8StemSWBIK
"""
g= input()
h= input()
pile= input()
cn = g+h
sort_cn = sorted(cn)
sort_pile = sorted(pile)
if sort_cn== sort_pile:
print("YE... | Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
# -*- coding: utf-8 -*-
"""141A.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1YAcE_C3NXDvEY0NY_rHyte8StemSWBIK
"""
g= input()
h= input()
pile= input()
cn = g+h
sort_cn = sorted(cn)
sort_pile = sorted(pile)
if sort_cn== sort_pile:
... | 3 | |
222 | A | Shooshuns and Sequence | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current ... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found. | Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1. | [
"3 2\n3 1 1\n",
"3 1\n3 1 1\n"
] | [
"1\n",
"-1\n"
] | In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one.
In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1.... | 500 | [
{
"input": "3 2\n3 1 1",
"output": "1"
},
{
"input": "3 1\n3 1 1",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 1\n2 1",
"output": "-1"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
}... | 1,661,947,750 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 47 | 154 | 13,414,400 | ## Fast I/O
import io,os,sys
# Fast input. Use s = input().decode() for strings
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# Fast output
def print(*args, sep = ' ', end = '\n'):
string = sep.join(map(str, args))+end
sys.stdout.write(string)
def debug(*args, sep = ' ', end = '\n'):
stri... | Title: Shooshuns and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the cur... | ```python
## Fast I/O
import io,os,sys
# Fast input. Use s = input().decode() for strings
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# Fast output
def print(*args, sep = ' ', end = '\n'):
string = sep.join(map(str, args))+end
sys.stdout.write(string)
def debug(*args, sep = ' ', end = '\n')... | 3 | |
938 | A | Word Correction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction. | Output the word *s* after the correction. | [
"5\nweird\n",
"4\nword\n",
"5\naaeaa\n"
] | [
"werd\n",
"word\n",
"a\n"
] | Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <i... | 0 | [
{
"input": "5\nweird",
"output": "werd"
},
{
"input": "4\nword",
"output": "word"
},
{
"input": "5\naaeaa",
"output": "a"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw",
"output": "abbbbbocadabbbbb... | 1,522,828,247 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 6,963,200 | n=int(input())
ch=input()
l=["a","e","i","o","u"]
b=0
for c in ch:
if (c in l) and (b==0):
b=1
print(c)
elif not((c in l)):
b=0
print(c)
| Title: Word Correction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird an... | ```python
n=int(input())
ch=input()
l=["a","e","i","o","u"]
b=0
for c in ch:
if (c in l) and (b==0):
b=1
print(c)
elif not((c in l)):
b=0
print(c)
``` | 0 | |
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the numb... | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
... | 1,671,863,922 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 404 | 13,926,400 | n=int(input());l=[];l2=[];l3=[]
for i in range(n):
a,b=[int(x) for x in input().split()]
l.append([a,b]); l2.append(b);l3.append(a)
l=dict(l);l3.sort();l2.sort()
for i in range(n):
if l[l3[i]]!=l2[i]:
print("Happy Alex")
exit()
print("Poor Alex") | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the... | ```python
n=int(input());l=[];l2=[];l3=[]
for i in range(n):
a,b=[int(x) for x in input().split()]
l.append([a,b]); l2.append(b);l3.append(a)
l=dict(l);l3.sort();l2.sort()
for i in range(n):
if l[l3[i]]!=l2[i]:
print("Happy Alex")
exit()
print("Poor Alex")
``` | 3 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,695,285,711 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | x=int(input())
if 1<=x<=100 and x%2==0 :
print('yes')
else:
print('no') | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
x=int(input())
if 1<=x<=100 and x%2==0 :
print('yes')
else:
print('no')
``` | 0 |
577 | A | Multiplication Table | PROGRAMMING | 1,000 | [
"implementation",
"number theory"
] | null | null | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain num... | The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. | Print a single number: the number of times *x* occurs in the table. | [
"10 5\n",
"6 12\n",
"5 13\n"
] | [
"2\n",
"4\n",
"0\n"
] | A table for the second sample test is given below. The occurrences of number 12 are marked bold. | 500 | [
{
"input": "10 5",
"output": "2"
},
{
"input": "6 12",
"output": "4"
},
{
"input": "5 13",
"output": "0"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "1 10000000... | 1,695,973,130 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 46 | 0 | a,b=map(int,input().split())
c=0
for x in range(1,a+1):
if b%x==0 and b//x<=a:
c+=1
print(c) | Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
Y... | ```python
a,b=map(int,input().split())
c=0
for x in range(1,a+1):
if b%x==0 and b//x<=a:
c+=1
print(c)
``` | 3 | |
5 | C | Longest Regular Bracket Sequence | PROGRAMMING | 1,900 | [
"constructive algorithms",
"data structures",
"dp",
"greedy",
"sortings",
"strings"
] | C. Longest Regular Bracket Sequence | 2 | 256 | This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.... | The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106. | Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1". | [
")((())))(()())\n",
"))(\n"
] | [
"6 2\n",
"0 1\n"
] | none | 0 | [
{
"input": ")((())))(()())",
"output": "6 2"
},
{
"input": "))(",
"output": "0 1"
},
{
"input": "()(())()",
"output": "8 1"
},
{
"input": "((((()(((",
"output": "2 1"
},
{
"input": "))))()())))",
"output": "4 1"
},
{
"input": "(()())()(())()()())())()(... | 1,638,993,676 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | from collections import deque
s= deque()
nb1=0
nb2=0
c=0
for i in input():
if s and i==')' and (s[-1]=='('):
s.pop()
nb1+=1
nb2= True
else:
s.append(i)
if nb2: c+=1
nb2= False
if nb1==0:print(0,'',1)
else:print(nb1,c)
| Title: Longest Regular Bracket Sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical exp... | ```python
from collections import deque
s= deque()
nb1=0
nb2=0
c=0
for i in input():
if s and i==')' and (s[-1]=='('):
s.pop()
nb1+=1
nb2= True
else:
s.append(i)
if nb2: c+=1
nb2= False
if nb1==0:print(0,'',1)
else:print(nb1,c)
``` | 0 |
332 | A | Down the Hatch! | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!
Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. After they ran out of the first barrel of juice, they decided to pl... | The first line contains a single integer *n* (4<=≤<=*n*<=≤<=2000) — the number of participants in the game. The second line describes the actual game: the *i*-th character of this line equals 'a', if the participant who moved *i*-th pointed at the next person with his elbow, and 'b', if the participant pointed with a n... | Print a single integer — the number of glasses of juice Vasya could have drunk if he had played optimally well. | [
"4\nabbba\n",
"4\nabbab\n"
] | [
"1\n",
"0\n"
] | In both samples Vasya has got two turns — 1 and 5. In the first sample, Vasya could have drunk a glass of juice during the fifth turn if he had pointed at the next person with a nod. In this case, the sequence of moves would look like "abbbb". In the second sample Vasya wouldn't drink a single glass of juice as the mov... | 500 | [
{
"input": "4\nabbba",
"output": "1"
},
{
"input": "4\nabbab",
"output": "0"
},
{
"input": "4\naaa",
"output": "0"
},
{
"input": "4\naab",
"output": "0"
},
{
"input": "4\naabaabbba",
"output": "1"
},
{
"input": "6\naaaaaaaaaaaaaaaa",
"output": "2"
... | 1,658,073,224 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 124 | 0 | import sys
input = sys.stdin.readline
n = int(input())
s = input()[:-1]
c = 0
for i in range(len(s))[n::n]:
if s[i-1] == s[i-2] == s[i-3]:
c += 1
print(c) | Title: Down the Hatch!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!
Yesterday one student, Vasya and his mates made some barbecue and th... | ```python
import sys
input = sys.stdin.readline
n = int(input())
s = input()[:-1]
c = 0
for i in range(len(s))[n::n]:
if s[i-1] == s[i-2] == s[i-3]:
c += 1
print(c)
``` | 3 | |
94 | A | Restoring Password | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Restoring Password | 2 | 256 | Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had ... | The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. | Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. | [
"01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n",
"10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1... | [
"12345678\n",
"30234919\n"
] | none | 500 | [
{
"input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110",
"output": "12345678"
},
{
"input": "1010110111100100001010010001101010110111001011011... | 1,678,021,795 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 124 | 0 | password=input();nums=[];ans=''
for i in range(10):num=input();nums.append(num)
for i in range(0,80,10):ans+=str(nums.index(password[i:i+10]))
print(ans)
| Title: Restoring Password
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff a... | ```python
password=input();nums=[];ans=''
for i in range(10):num=input();nums.append(num)
for i in range(0,80,10):ans+=str(nums.index(password[i:i+10]))
print(ans)
``` | 3.969 |
735 | B | Urbanization | PROGRAMMING | 1,100 | [
"greedy",
"number theory",
"sortings"
] | null | null | Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* of them is equal to *a**i*. Authorities plan to build two cities, first for *n*1 people and second ... | The first line of the input contains three integers *n*, *n*1 and *n*2 (1<=≤<=*n*,<=*n*1,<=*n*2<=≤<=100<=000, *n*1<=+<=*n*2<=≤<=*n*) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line conta... | Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your ... | [
"2 1 1\n1 5\n",
"4 2 1\n1 4 2 3\n"
] | [
"6.00000000\n",
"6.50000000\n"
] | In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (*a*<sub class="lower-index">3</sub> + *a*<sub class=... | 1,000 | [
{
"input": "2 1 1\n1 5",
"output": "6.00000000"
},
{
"input": "4 2 1\n1 4 2 3",
"output": "6.50000000"
},
{
"input": "3 1 2\n1 2 3",
"output": "4.50000000"
},
{
"input": "10 4 6\n3 5 7 9 12 25 67 69 83 96",
"output": "88.91666667"
},
{
"input": "19 7 12\n1 2 4 8 1... | 1,596,738,661 | 6,781 | PyPy 3 | OK | TESTS | 37 | 202 | 30,720,000 | n,n1,n2=map(int ,input().split());
l=list(map(int,input().split()));
l.sort(reverse=True)
n1,n2=max(n1,n2),min(n1,n2);
s1=0
s2=0
for i in range(n2):
s1+=l[i]
for i in range(n2,n1+n2):
s2+=l[i]
print(s1/n2+s2/n1) | Title: Urbanization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* o... | ```python
n,n1,n2=map(int ,input().split());
l=list(map(int,input().split()));
l.sort(reverse=True)
n1,n2=max(n1,n2),min(n1,n2);
s1=0
s2=0
for i in range(n2):
s1+=l[i]
for i in range(n2,n1+n2):
s2+=l[i]
print(s1/n2+s2/n1)
``` | 3 | |
797 | D | Broken BST | PROGRAMMING | 2,100 | [
"data structures",
"dfs and similar"
] | null | null | Let *T* be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every vertex has an integer number written on it. Following algorithm is run on every value from the tree *T*:
1. S... | First line contains integer number *n* (1<=≤<=*n*<=≤<=105) — number of vertices in the tree.
Each of the next *n* lines contains 3 numbers *v*, *l*, *r* (0<=≤<=*v*<=≤<=109) — value on current vertex, index of the left child of the vertex and index of the right child of the vertex, respectively. If some child doesn't e... | Print number of times when search algorithm will fail. | [
"3\n15 -1 -1\n10 1 3\n5 -1 -1\n",
"8\n6 2 3\n3 4 5\n12 6 7\n1 -1 8\n4 -1 -1\n5 -1 -1\n14 -1 -1\n2 -1 -1\n"
] | [
"2\n",
"1\n"
] | In the example the root of the tree in vertex 2. Search of numbers 5 and 15 will return fail because on the first step algorithm will choose the subtree which doesn't contain numbers you are looking for. | 0 | [
{
"input": "3\n15 -1 -1\n10 1 3\n5 -1 -1",
"output": "2"
},
{
"input": "8\n6 2 3\n3 4 5\n12 6 7\n1 -1 8\n4 -1 -1\n5 -1 -1\n14 -1 -1\n2 -1 -1",
"output": "1"
},
{
"input": "1\n493041212 -1 -1",
"output": "0"
},
{
"input": "10\n921294733 5 9\n341281094 -1 -1\n35060484 10 -1\n36... | 1,675,146,125 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 28 | 888 | 31,232,000 | from collections import defaultdict
import sys
class Node:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
n = int(input())
m = defaultdict(list)
cnt = defaultdict(int)
for i in range(n):
val, left, right = list(map(int, input().split()))
... | Title: Broken BST
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let *T* be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every vertex has an i... | ```python
from collections import defaultdict
import sys
class Node:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
n = int(input())
m = defaultdict(list)
cnt = defaultdict(int)
for i in range(n):
val, left, right = list(map(int, input().split... | -1 | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,698,080,209 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n = int(input())
subjects = []
for _ in range(n):
s1, s2, s3 = map(int, input().split())
subjects.append((s1, s2, s3))
cannot_solve_alone = 0
for s1, s2, s3 in subjects:
if s1 == 0 and s2 == 1:
cannot_solve_alone += 1
can_solve = n - cannot_solve_alone
print(can_solve)
... | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
n = int(input())
subjects = []
for _ in range(n):
s1, s2, s3 = map(int, input().split())
subjects.append((s1, s2, s3))
cannot_solve_alone = 0
for s1, s2, s3 in subjects:
if s1 == 0 and s2 == 1:
cannot_solve_alone += 1
can_solve = n - cannot_solve_alone
print(can_solve)
... | 0 | |
886 | E | Maximum Element | PROGRAMMING | 2,400 | [
"combinatorics",
"dp",
"math"
] | null | null | One day Petya was solving a very interesting problem. But although he used many optimization techniques, his solution still got Time limit exceeded verdict. Petya conducted a thorough analysis of his program and found out that his function for finding maximum element in an array of *n* positive integers was too slow. D... | The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=106), separated by a space — the length of the permutations and the parameter *k*. | Output the answer to the problem modulo 109<=+<=7. | [
"5 2\n",
"5 3\n",
"6 3\n"
] | [
"22\n",
"6\n",
"84\n"
] | Permutations from second example:
[4, 1, 2, 3, 5], [4, 1, 3, 2, 5], [4, 2, 1, 3, 5], [4, 2, 3, 1, 5], [4, 3, 1, 2, 5], [4, 3, 2, 1, 5]. | 2,500 | [
{
"input": "5 2",
"output": "22"
},
{
"input": "5 3",
"output": "6"
},
{
"input": "6 3",
"output": "84"
},
{
"input": "5 10",
"output": "0"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "2 1",
"output": "0"
},
{
"input": "2 2",
"outp... | 1,626,303,337 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 108 | 15,052,800 | import math
n, k = map(int,input().split())
def mod(n):
return n%1000000007
def variacion(n, p):
s=1
for i in range(n-p+1,n+1):
s = mod(s*mod(i))
return s
factoriales=[0]*1000000
factoriales[0]=1
mask=[False]*1000000
mask[0]=True
ultimo_factorial=0
def factorial(n):
i... | Title: Maximum Element
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Petya was solving a very interesting problem. But although he used many optimization techniques, his solution still got Time limit exceeded verdict. Petya conducted a thorough analysis of his program and found o... | ```python
import math
n, k = map(int,input().split())
def mod(n):
return n%1000000007
def variacion(n, p):
s=1
for i in range(n-p+1,n+1):
s = mod(s*mod(i))
return s
factoriales=[0]*1000000
factoriales[0]=1
mask=[False]*1000000
mask[0]=True
ultimo_factorial=0
def factorial(... | 0 | |
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,670,853,546 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | x=int(input())
ans=0
while x>0:
if x%2==1:
ans+=1
x//=2
print(ans)
| 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
x=int(input())
ans=0
while x>0:
if x%2==1:
ans+=1
x//=2
print(ans)
``` | 3 | |
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,598,408,145 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 202 | 819,200 | from collections import defaultdict
n = int(input())
s = input()
count = 0
d = defaultdict(int)
for i in range(1,len(s),2):
if s[i].lower() == s[i-1]:
continue
elif s[i].lower() in d:
d[s[i].lower()]-=1
if d[s[i].lower()] == 0:
d.pop(s[i].lower())
continue... | 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
from collections import defaultdict
n = int(input())
s = input()
count = 0
d = defaultdict(int)
for i in range(1,len(s),2):
if s[i].lower() == s[i-1]:
continue
elif s[i].lower() in d:
d[s[i].lower()]-=1
if d[s[i].lower()] == 0:
d.pop(s[i].lower())
... | 0 | |
1,006 | C | Three Parts of the Array | PROGRAMMING | 1,200 | [
"binary search",
"data structures",
"two pointers"
] | null | null | You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possib... | The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$. | Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$). | [
"5\n1 3 1 1 4\n",
"5\n1 3 2 1 4\n",
"3\n4 1 2\n"
] | [
"5\n",
"4\n",
"0\n"
] | In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | 0 | [
{
"input": "5\n1 3 1 1 4",
"output": "5"
},
{
"input": "5\n1 3 2 1 4",
"output": "4"
},
{
"input": "3\n4 1 2",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "5\n1 3 5 4 5",
"output": ... | 1,629,191,633 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 343 | 24,678,400 | n = int(input())
a = list(map(int, input().split()))
s = [a[0]]
for i in range(1, n):
s.append(s[i-1]+a[i])
sa = s[n-1]
l = 0
r = n-1
res = 0
while r-l > 0:
if s[l] == sa - s[r-1]:
res = max(res, s[l])
l += 1
elif s[l] > sa - s[r-1]:
r -= 1
else:
l += 1
p... | Title: Three Parts of the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belo... | ```python
n = int(input())
a = list(map(int, input().split()))
s = [a[0]]
for i in range(1, n):
s.append(s[i-1]+a[i])
sa = s[n-1]
l = 0
r = n-1
res = 0
while r-l > 0:
if s[l] == sa - s[r-1]:
res = max(res, s[l])
l += 1
elif s[l] > sa - s[r-1]:
r -= 1
else:
... | 3 | |
358 | A | Dima and Continuous Line | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect th... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate. | In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes). | [
"4\n0 10 5 15\n",
"4\n0 15 5 10\n"
] | [
"yes\n",
"no\n"
] | The first test from the statement is on the picture to the left, the second test is on the picture to the right. | 500 | [
{
"input": "4\n0 10 5 15",
"output": "yes"
},
{
"input": "4\n0 15 5 10",
"output": "no"
},
{
"input": "5\n0 1000 2000 3000 1500",
"output": "yes"
},
{
"input": "5\n-724093 710736 -383722 -359011 439613",
"output": "no"
},
{
"input": "50\n384672 661179 -775591 -989... | 1,595,996,449 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 20,172,800 | inf = int(1e9+5)
n = int(input())
ar = list(map(int, input().split()))
up_lim = inf
low_lim = ar[0]
intersect = False
for i in range(n-1):
if ar[i+1]>ar[i] and ar[i+1]<=up_lim:
up_lim = ar[i+1]
elif ar[i+1]<ar[i] and ar[i+1]>=low_lim:
low_lim = ar[i+1]
else:
intersect = True
... | Title: Dima and Continuous Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher g... | ```python
inf = int(1e9+5)
n = int(input())
ar = list(map(int, input().split()))
up_lim = inf
low_lim = ar[0]
intersect = False
for i in range(n-1):
if ar[i+1]>ar[i] and ar[i+1]<=up_lim:
up_lim = ar[i+1]
elif ar[i+1]<ar[i] and ar[i+1]>=low_lim:
low_lim = ar[i+1]
else:
intersect = ... | 0 | |
343 | B | Alternating Current | PROGRAMMING | 1,600 | [
"data structures",
"greedy",
"implementation"
] | null | null | Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended u... | The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | [
"-++-\n",
"+-\n",
"++\n",
"-\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"No\n"
] | The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.
In the second testcase the "plus" wire makes one full rev... | 1,000 | [
{
"input": "-++-",
"output": "Yes"
},
{
"input": "+-",
"output": "No"
},
{
"input": "++",
"output": "Yes"
},
{
"input": "-",
"output": "No"
},
{
"input": "+-+-",
"output": "No"
},
{
"input": "-+-",
"output": "No"
},
{
"input": "-++-+--+",
... | 1,658,613,244 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | array = input()
j = len(array) - 1
i = 0
result = True
while len(array) > 0:
if len(array) % 2 != 0:
result = False
break
if array[j] != array[0]:
result = False
break
array = array[1: j]
j -= 2
if result:
print("Yes")
else:
print("No... | Title: Alternating Current
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it... | ```python
array = input()
j = len(array) - 1
i = 0
result = True
while len(array) > 0:
if len(array) % 2 != 0:
result = False
break
if array[j] != array[0]:
result = False
break
array = array[1: j]
j -= 2
if result:
print("Yes")
else:
... | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,645,158,899 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | n = int(input())
r1,r2,r3 = 0,0,0
for i in range(n):
a,b,c = map(int,input().split())
r1 += a
r2 += b
r3 += c
if(r1==0 and r2 == 0 and r3 == 0):
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
r1,r2,r3 = 0,0,0
for i in range(n):
a,b,c = map(int,input().split())
r1 += a
r2 += b
r3 += c
if(r1==0 and r2 == 0 and r3 == 0):
print("YES")
else:
print("NO")
``` | 3.977 |
451 | A | Game With Sticks | PROGRAMMING | 900 | [
"implementation"
] | null | null | After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.
In the grid show... | The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). | Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game. | [
"2 2\n",
"2 3\n",
"3 3\n"
] | [
"Malvika\n",
"Malvika\n",
"Akshat\n"
] | Explanation of the first sample:
The grid has four intersection points, numbered from 1 to 4.
If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this.
Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remov... | 500 | [
{
"input": "2 2",
"output": "Malvika"
},
{
"input": "2 3",
"output": "Malvika"
},
{
"input": "3 3",
"output": "Akshat"
},
{
"input": "20 68",
"output": "Malvika"
},
{
"input": "1 1",
"output": "Akshat"
},
{
"input": "1 2",
"output": "Akshat"
},
... | 1,678,719,097 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n,m=map(int,input().split())
if (n*m)%2==0:
print("Malvika")
else:
print("Akshat") | Title: Game With Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid... | ```python
n,m=map(int,input().split())
if (n*m)%2==0:
print("Malvika")
else:
print("Akshat")
``` | 0 | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,695,916,191 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | tv_sets,carry_limit=map(int,input().split())
prices=list(map(int,input().split()))
prices.sort()
print(abs(sum(prices[:carry_limit:]))) | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
tv_sets,carry_limit=map(int,input().split())
prices=list(map(int,input().split()))
prices.sort()
print(abs(sum(prices[:carry_limit:])))
``` | 0 |
990 | D | Graph And Its Complement | PROGRAMMING | 1,700 | [
"constructive algorithms",
"graphs",
"implementation"
] | null | null | Given three numbers $n, a, b$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $a$, and the number of components in its complement is $b$. The matrix must be symmetric, and all digits on the main diagonal must be zeroes.
In an undirected graph loops (edg... | In a single line, three numbers are given $n, a, b \,(1 \le n \le 1000, 1 \le a, b \le n)$: is the number of vertexes of the graph, the required number of connectivity components in it, and the required amount of the connectivity component in it's complement. | If there is no graph that satisfies these constraints on a single line, print "NO" (without quotes).
Otherwise, on the first line, print "YES"(without quotes). In each of the next $n$ lines, output $n$ digits such that $j$-th digit of $i$-th line must be $1$ if and only if there is an edge between vertices $i$ and $j$... | [
"3 1 2\n",
"3 3 3\n"
] | [
"YES\n001\n001\n110\n",
"NO\n"
] | none | 0 | [
{
"input": "3 1 2",
"output": "YES\n001\n001\n110"
},
{
"input": "3 3 3",
"output": "NO"
},
{
"input": "5 1 1",
"output": "YES\n01000\n10100\n01010\n00101\n00010"
},
{
"input": "123 1 84",
"output": "YES\n0011111111111111111111111111111111111111111111111111111111111111111... | 1,685,631,024 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 202 | 8,396,800 | n, a, b = [int(x) for x in input().split()]
flag = False
if b > a:
a, b = b, a
flag = True
def possible(n, a, b):
if a > n:
return False
if a > 1:
return b == 1
if a == 1:
return n >= 4 or n == 1
if possible(n, a, b):
print("YES")
mat =... | Title: Graph And Its Complement
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given three numbers $n, a, b$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $a$, and the number of components in its complement is $b$. The ma... | ```python
n, a, b = [int(x) for x in input().split()]
flag = False
if b > a:
a, b = b, a
flag = True
def possible(n, a, b):
if a > n:
return False
if a > 1:
return b == 1
if a == 1:
return n >= 4 or n == 1
if possible(n, a, b):
print("YES")
... | 3 | |
348 | A | Mafia | PROGRAMMING | 1,600 | [
"binary search",
"math",
"sortings"
] | null | null | One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the min... | The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play. | In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"3\n3 2 2\n",
"4\n2 2 2 2\n"
] | [
"4\n",
"3\n"
] | You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | 500 | [
{
"input": "3\n3 2 2",
"output": "4"
},
{
"input": "4\n2 2 2 2",
"output": "3"
},
{
"input": "7\n9 7 7 8 8 7 8",
"output": "9"
},
{
"input": "10\n13 12 10 13 13 14 10 10 12 12",
"output": "14"
},
{
"input": "10\n94 96 91 95 99 94 96 92 95 99",
"output": "106"
... | 1,610,086,084 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 468 | 10,956,800 | import math
n=int(input())
l=list(map(int,input().split()))
print(max(max(l),math.ceil(sum(l)/(n-1)))) | Title: Mafia
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a... | ```python
import math
n=int(input())
l=list(map(int,input().split()))
print(max(max(l),math.ceil(sum(l)/(n-1))))
``` | 3 | |
216 | A | Tiling with Hexagons | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with hexagonal tiles.
The hall also turned out hexagonal in its shape. The King walked along the perimeter of ... | The first line contains three integers: *a*, *b* and *c* (2<=≤<=*a*,<=*b*,<=*c*<=≤<=1000). | Print a single number — the total number of tiles on the hall floor. | [
"2 3 4\n"
] | [
"18"
] | none | 500 | [
{
"input": "2 3 4",
"output": "18"
},
{
"input": "2 2 2",
"output": "7"
},
{
"input": "7 8 13",
"output": "224"
},
{
"input": "14 7 75",
"output": "1578"
},
{
"input": "201 108 304",
"output": "115032"
},
{
"input": "999 998 996",
"output": "298302... | 1,593,358,469 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 6,656,000 |
a,b,c = map(int,input().split())
ans = 2 * (a+b+c)
print(ans) | Title: Tiling with Hexagons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with ... | ```python
a,b,c = map(int,input().split())
ans = 2 * (a+b+c)
print(ans)
``` | 0 | |
903 | D | Almost Difference | PROGRAMMING | 2,200 | [
"data structures",
"math"
] | null | null | Let's denote a function
You are given an array *a* consisting of *n* integers. You have to calculate the sum of *d*(*a**i*,<=*a**j*) over all pairs (*i*,<=*j*) such that 1<=≤<=*i*<=≤<=*j*<=≤<=*n*. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=200000) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) — elements of the array. | Print one integer — the sum of *d*(*a**i*,<=*a**j*) over all pairs (*i*,<=*j*) such that 1<=≤<=*i*<=≤<=*j*<=≤<=*n*. | [
"5\n1 2 3 1 3\n",
"4\n6 6 5 5\n",
"4\n6 6 4 4\n"
] | [
"4\n",
"0\n",
"-8\n"
] | In the first example:
1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>) = 0; 1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">3</sub>) = 2; 1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">4</sub>) = 0; 1. *d*(*a*<sub class="lower-index">... | 0 | [
{
"input": "5\n1 2 3 1 3",
"output": "4"
},
{
"input": "4\n6 6 5 5",
"output": "0"
},
{
"input": "4\n6 6 4 4",
"output": "-8"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1000000000",
"output"... | 1,637,430,875 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 45 | 296 | 35,328,000 | n = int(input())
arr = [int(x) for x in input().split()]
cnt = {0 : 0}
ans = 0
pref = [0] * n
for i in range(0, n):
ans += arr[i] * i
if i > 0:
ans -= pref[i - 1]
pref[i] += pref[i - 1]
if arr[i] + 1 in cnt:
ans += cnt[arr[i] + 1]
if arr[i] - 1 in cnt:
ans -= cnt[arr[i] ... | Title: Almost Difference
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's denote a function
You are given an array *a* consisting of *n* integers. You have to calculate the sum of *d*(*a**i*,<=*a**j*) over all pairs (*i*,<=*j*) such that 1<=≤<=*i*<=≤<=*j*<=≤<=*n*.
Input Specifica... | ```python
n = int(input())
arr = [int(x) for x in input().split()]
cnt = {0 : 0}
ans = 0
pref = [0] * n
for i in range(0, n):
ans += arr[i] * i
if i > 0:
ans -= pref[i - 1]
pref[i] += pref[i - 1]
if arr[i] + 1 in cnt:
ans += cnt[arr[i] + 1]
if arr[i] - 1 in cnt:
ans -= c... | 3 | |
902 | B | Coloring a Tree | PROGRAMMING | 1,200 | [
"dfs and similar",
"dsu",
"greedy"
] | null | null | You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
You have to color the tree into the given colors using the smallest possible number of steps. On eac... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=104) — the number of vertices in the tree.
The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=<<=*i*), where *p**i* means that there is an edge between vertices *i* and *p**i*.
The third line contains *n* integers *c*1,<... | Print a single integer — the minimum number of steps you have to perform to color the tree into given colors. | [
"6\n1 2 2 1 5\n2 1 1 1 1 1\n",
"7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n"
] | [
"3\n",
"5\n"
] | The tree from the first sample is shown on the picture (numbers are vetices' indices):
<img class="tex-graphics" src="https://espresso.codeforces.com/10324ccdc37f95343acc4f3c6050d8c334334ffa.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On first step we color all vertices in the subtree of vertex 1 into color ... | 1,000 | [
{
"input": "6\n1 2 2 1 5\n2 1 1 1 1 1",
"output": "3"
},
{
"input": "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3",
"output": "5"
},
{
"input": "2\n1\n2 2",
"output": "1"
},
{
"input": "3\n1 1\n2 2 2",
"output": "1"
},
{
"input": "4\n1 2 1\n1 2 3 4",
"output": "4"
},
{
... | 1,641,163,109 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 13 | 140 | 2,969,600 | v_num = int(input())
graph = list(map(lambda x: int(x), input().split(" ")))
coloring = list(map(lambda x: int(x), input().split(" ")))
# print(v_num, graph, coloring)
tree = dict()
coloring_num = 1
for x in range(v_num):
tree[x+1] = set()
for ind, v in enumerate(graph):
tree[ind + 2].add(v)
t... | Title: Coloring a Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
... | ```python
v_num = int(input())
graph = list(map(lambda x: int(x), input().split(" ")))
coloring = list(map(lambda x: int(x), input().split(" ")))
# print(v_num, graph, coloring)
tree = dict()
coloring_num = 1
for x in range(v_num):
tree[x+1] = set()
for ind, v in enumerate(graph):
tree[ind + 2].add... | -1 | |
332 | B | Maximum Absurdity | PROGRAMMING | 1,500 | [
"data structures",
"dp",
"implementation"
] | null | null | Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign ... | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=2·105, 0<=<<=2*k*<=≤<=*n*) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* — the absurdity of each law (1<=≤<=*x**i*<=≤<=109). | Print two integers *a*, *b* — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1]. If there are multiple solutions, print the one with the minimum number *a*. If there still are multiple soluti... | [
"5 2\n3 6 1 1 6\n",
"6 2\n1 1 1 1 1 1\n"
] | [
"1 4\n",
"1 3\n"
] | In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4. | 1,000 | [
{
"input": "5 2\n3 6 1 1 6",
"output": "1 4"
},
{
"input": "6 2\n1 1 1 1 1 1",
"output": "1 3"
},
{
"input": "6 2\n1 4 1 2 5 6",
"output": "1 5"
},
{
"input": "4 1\n1 2 2 2",
"output": "2 3"
},
{
"input": "6 3\n15 20 1 15 43 6",
"output": "1 4"
},
{
"i... | 1,496,518,071 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 122 | 512,000 | from collections import defaultdict
(n, k) = map(int, input().split(' '))
nums = list(map(int, input().split(' ')))
x = [0] * n
m = defaultdict(list)
i = 0
s = 0
while i < k:
s += nums[i]
x[i] = s
m[x[i]].append(i)
i += 1
while i < n:
s -= nums[i - k]
s += nums[i]
x[i] = s
m[x[i]].ap... | Title: Maximum Absurdity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on... | ```python
from collections import defaultdict
(n, k) = map(int, input().split(' '))
nums = list(map(int, input().split(' ')))
x = [0] * n
m = defaultdict(list)
i = 0
s = 0
while i < k:
s += nums[i]
x[i] = s
m[x[i]].append(i)
i += 1
while i < n:
s -= nums[i - k]
s += nums[i]
x[i] = s
... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other.
For example, you should know l... | The only line contains a string *s* (5<=≤<=|*s*|<=≤<=104) consisting of lowercase English letters. | On the first line print integer *k* — a number of distinct possible suffixes. On the next *k* lines print suffixes.
Print suffixes in lexicographical (alphabetical) order. | [
"abacabaca\n",
"abaca\n"
] | [
"3\naca\nba\nca\n",
"0\n"
] | The first test was analysed in the problem statement.
In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix. | 0 | [
{
"input": "abacabaca",
"output": "3\naca\nba\nca"
},
{
"input": "abaca",
"output": "0"
},
{
"input": "gzqgchv",
"output": "1\nhv"
},
{
"input": "iosdwvzerqfi",
"output": "9\ner\nerq\nfi\nqfi\nrq\nvz\nvze\nze\nzer"
},
{
"input": "oawtxikrpvfuzugjweki",
"output... | 1,520,340,037 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 5,632,000 | # http://codeforces.com/contest/667/problem/C
s = input()
n = len(s)
ans = {s[n - 2:n], s[n - 3:n]}
checked = set()
def dp(i, j):
if (i, j) in checked:
return
checked.add((i, j))
"""
(ab)(cd)で後ろのcdをaddすると
(abc)(bc)でbcをaddできないので前のカタマリをaddする
"""
# 2文字
if i > 6... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in differ... | ```python
# http://codeforces.com/contest/667/problem/C
s = input()
n = len(s)
ans = {s[n - 2:n], s[n - 3:n]}
checked = set()
def dp(i, j):
if (i, j) in checked:
return
checked.add((i, j))
"""
(ab)(cd)で後ろのcdをaddすると
(abc)(bc)でbcをaddできないので前のカタマリをaddする
"""
# 2文字
... | 0 | |
627 | A | XOR Equation | PROGRAMMING | 1,700 | [
"dp",
"math"
] | null | null | Two positive integers *a* and *b* have a sum of *s* and a bitwise XOR of *x*. How many possible values are there for the ordered pair (*a*,<=*b*)? | The first line of the input contains two integers *s* and *x* (2<=≤<=*s*<=≤<=1012, 0<=≤<=*x*<=≤<=1012), the sum and bitwise xor of the pair of positive integers, respectively. | Print a single integer, the number of solutions to the given conditions. If no solutions exist, print 0. | [
"9 5\n",
"3 3\n",
"5 2\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample, we have the following solutions: (2, 7), (3, 6), (6, 3), (7, 2).
In the second sample, the only solutions are (1, 2) and (2, 1). | 500 | [
{
"input": "9 5",
"output": "4"
},
{
"input": "3 3",
"output": "2"
},
{
"input": "5 2",
"output": "0"
},
{
"input": "6 0",
"output": "1"
},
{
"input": "549755813887 549755813887",
"output": "549755813886"
},
{
"input": "2 0",
"output": "1"
},
{... | 1,457,892,029 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | [s, x] = map(int, input().split())
c = 0
for i in range(0, s):
if i ^ (s - i) is x:
c += 1
print(c)
| Title: XOR Equation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two positive integers *a* and *b* have a sum of *s* and a bitwise XOR of *x*. How many possible values are there for the ordered pair (*a*,<=*b*)?
Input Specification:
The first line of the input contains two integers *s*... | ```python
[s, x] = map(int, input().split())
c = 0
for i in range(0, s):
if i ^ (s - i) is x:
c += 1
print(c)
``` | 0 | |
868 | A | Bark to Unlock | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.
Mu-mu's enemy Kashtanka wants to unlock Mu-mu's p... | The first line contains two lowercase English letters — the password on the phone.
The second line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of words Kashtanka knows.
The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to b... | Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"ya\n4\nah\noy\nto\nha\n",
"hp\n2\nht\ntp\n",
"ah\n1\nha\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES".
In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" produ... | 250 | [
{
"input": "ya\n4\nah\noy\nto\nha",
"output": "YES"
},
{
"input": "hp\n2\nht\ntp",
"output": "NO"
},
{
"input": "ah\n1\nha",
"output": "YES"
},
{
"input": "bb\n4\nba\nab\naa\nbb",
"output": "YES"
},
{
"input": "bc\n4\nca\nba\nbb\ncc",
"output": "YES"
},
{
... | 1,596,555,296 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 6,656,000 | s=input()
t=''
for i in range(int(input())):
t+=input()
if s in t:
print('YES')
else:
if t.index(s[0])%2==0 and t.index(s[1])%2==1:
print('YES')
else:
print('NO') | Title: Bark to Unlock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a passw... | ```python
s=input()
t=''
for i in range(int(input())):
t+=input()
if s in t:
print('YES')
else:
if t.index(s[0])%2==0 and t.index(s[1])%2==1:
print('YES')
else:
print('NO')
``` | 0 | |
706 | A | Beru-taxi | PROGRAMMING | 900 | [
"brute force",
"geometry",
"implementation"
] | null | null | Vasiliy lives at point (*a*,<=*b*) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested *n* available Beru-taxi nearby. The *i*-th taxi is located at point (*x**i*,<=*y**i*) and moves with a speed *v**i*.
Consider that each of *n* drivers will m... | The first line of the input contains two integers *a* and *b* (<=-<=100<=≤<=*a*,<=*b*<=≤<=100) — coordinates of Vasiliy's home.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of available Beru-taxi cars nearby.
The *i*-th of the following *n* lines contains three integers *x**i*, *y*... | Print a single real value — the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answ... | [
"0 0\n2\n2 0 1\n0 2 2\n",
"1 3\n3\n3 3 2\n-2 3 6\n-2 7 10\n"
] | [
"1.00000000000000000000",
"0.50000000000000000000"
] | In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer.
In the second sample, cars 2 and 3 will arrive simultaneously. | 500 | [
{
"input": "0 0\n2\n2 0 1\n0 2 2",
"output": "1.00000000000000000000"
},
{
"input": "1 3\n3\n3 3 2\n-2 3 6\n-2 7 10",
"output": "0.50000000000000000000"
},
{
"input": "2 2\n10\n8 10 1\n14 18 5\n2 2 1\n4 2 2\n5 2 1\n0 2 1\n2 10 4\n10 2 4\n14 18 20\n14 18 10",
"output": "0.000000000000... | 1,697,005,152 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 53 | 77 | 1,638,400 | from math import sqrt
a, b = map(int, input().split())
ans = 100000
for _ in range(int(input())):
x, y, v = map(int, input().split())
q = sqrt(pow(abs(x-a),2)+pow(abs(y-b),2))/v
if q < ans:
ans = q
print(ans)
| Title: Beru-taxi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy lives at point (*a*,<=*b*) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested *n* available Beru-taxi nearby. The *i*-th taxi is located at po... | ```python
from math import sqrt
a, b = map(int, input().split())
ans = 100000
for _ in range(int(input())):
x, y, v = map(int, input().split())
q = sqrt(pow(abs(x-a),2)+pow(abs(y-b),2))/v
if q < ans:
ans = q
print(ans)
``` | 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,654,345,439 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 46 | 0 | a, b, c = map(int, input().split(' '))
if a ==12 and b == 13 and c == 4:print(12)
a = a * b
b = c * c
m = a % b
d = a // b
if d == 0:print(1)
else:print(d + m // d)
| 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, b, c = map(int, input().split(' '))
if a ==12 and b == 13 and c == 4:print(12)
a = a * b
b = c * c
m = a % b
d = a // b
if d == 0:print(1)
else:print(d + m // d)
``` | 0 |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,699,980,578 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 92 | 0 | # ^^
def solve():
n, m = list(map(int, input().split()))
ans = 1000000000000
data = sorted(map(int, input().split()))
for i in range(0, m-n+1):
ans = min(ans, data[i+n-1] - data[i])
print(ans)
if __name__ == '__main__':
t = 1
# t = int(input())
for i in range(t):
... | Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
# ^^
def solve():
n, m = list(map(int, input().split()))
ans = 1000000000000
data = sorted(map(int, input().split()))
for i in range(0, m-n+1):
ans = min(ans, data[i+n-1] - data[i])
print(ans)
if __name__ == '__main__':
t = 1
# t = int(input())
for i in r... | 3 | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,497,188,944 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 124 | 0 | #n = int(input())
#n, m = map(int, input().split())
s = input()
#c = list(map(int, input().split()))
for i in range(len(s)):
if s[i] == '0':
s = s[:i] + s[i + 1:]
break
print(s) | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
#n = int(input())
#n, m = map(int, input().split())
s = input()
#c = list(map(int, input().split()))
for i in range(len(s)):
if s[i] == '0':
s = s[:i] + s[i + 1:]
break
print(s)
``` | 0 | |
450 | B | Jzzhu and Sequences | PROGRAMMING | 1,300 | [
"implementation",
"math"
] | null | null | Jzzhu has invented a kind of sequences, they meet the following property:
You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7). | The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). | Output a single integer representing *f**n* modulo 1000000007 (109<=+<=7). | [
"2 3\n3\n",
"0 -1\n2\n"
] | [
"1\n",
"1000000006\n"
] | In the first sample, *f*<sub class="lower-index">2</sub> = *f*<sub class="lower-index">1</sub> + *f*<sub class="lower-index">3</sub>, 3 = 2 + *f*<sub class="lower-index">3</sub>, *f*<sub class="lower-index">3</sub> = 1.
In the second sample, *f*<sub class="lower-index">2</sub> = - 1; - 1 modulo (10<sup class="upper-... | 1,000 | [
{
"input": "2 3\n3",
"output": "1"
},
{
"input": "0 -1\n2",
"output": "1000000006"
},
{
"input": "-9 -11\n12345",
"output": "1000000005"
},
{
"input": "0 0\n1000000000",
"output": "0"
},
{
"input": "-1000000000 1000000000\n2000000000",
"output": "1000000000"
... | 1,690,010,928 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 109 | 5,734,400 | def slv(x):
MOD = 1000000007
return x % MOD
def rec(n,x,y):
if n==1:
return x
elif n==2:
return y
else:
return rec(n-1,x,y)-rec(n-2,x,y)
n,m=map(int,input().split())
x=int(input())
ans=rec(x,n,m)
x=slv(ans)
print(x)
| Title: Jzzhu and Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jzzhu has invented a kind of sequences, they meet the following property:
You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7).
Input Specification:
The first line contains two integers... | ```python
def slv(x):
MOD = 1000000007
return x % MOD
def rec(n,x,y):
if n==1:
return x
elif n==2:
return y
else:
return rec(n-1,x,y)-rec(n-2,x,y)
n,m=map(int,input().split())
x=int(input())
ans=rec(x,n,m)
x=slv(ans)
print(x)
``` | -1 | |
591 | B | Rebranding | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slog... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively.
The second line consists of *n* lowercase English letters and represents the original name of the corporation.
Next *m* lines contain the descr... | Print the new name of the corporation. | [
"6 1\npolice\np m\n",
"11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n"
] | [
"molice\n",
"cdcbcdcfcdc\n"
] | In the second sample the name of the corporation consecutively changes as follows:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.co... | 1,000 | [
{
"input": "6 1\npolice\np m",
"output": "molice"
},
{
"input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b",
"output": "cdcbcdcfcdc"
},
{
"input": "1 1\nf\nz h",
"output": "f"
},
{
"input": "1 1\na\na b",
"output": "b"
},
{
"input": "10 10\nlellelleel\ne l\n... | 1,528,472,566 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 0 | m,n=map(int,input().split())
s=list(input())
d={}
for i in range(n):
pq,cd=map(str,input().split())
if pq==cd:
continue
elif pq not in s and cd not in s:
continue
else:
if s.count(cd)==0:
p=s[::-1]
q=p.index(pq)
q=m-q
... | Title: Rebranding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand ... | ```python
m,n=map(int,input().split())
s=list(input())
d={}
for i in range(n):
pq,cd=map(str,input().split())
if pq==cd:
continue
elif pq not in s and cd not in s:
continue
else:
if s.count(cd)==0:
p=s[::-1]
q=p.index(pq)
q=m-q
... | 0 | |
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,563,217,639 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 124 | 512,000 | #GukiZ and Contest
n = int(input())
a = list(map(int, input().split()))
b = sorted(a, reverse=True)
rank = [0]*2001
rank[b[0]] = 1
temp = b[0]
for i in range(n):
if temp != b[i]:
rank[b[i]] = i + 1
temp = b[i]
for i in range(n):
print(rank[a[i]], end=" ") | 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
#GukiZ and Contest
n = int(input())
a = list(map(int, input().split()))
b = sorted(a, reverse=True)
rank = [0]*2001
rank[b[0]] = 1
temp = b[0]
for i in range(n):
if temp != b[i]:
rank[b[i]] = i + 1
temp = b[i]
for i in range(n):
print(rank[a[i]], end=" ")
``` | 3 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,644,391,769 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 124 | 0 | #43A - Football
for i in range(int(input())):
x,y=input(),{}
try:
y[x]+=1
except:
y[x]=1
print((max(y.keys()))) | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
#43A - Football
for i in range(int(input())):
x,y=input(),{}
try:
y[x]+=1
except:
y[x]=1
print((max(y.keys())))
``` | 0 |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal 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,698,469,618 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n=int(input())
l=list(map(int,input().strip().split()))
if 1<=n<=100:
s=0
for i in l:
s+=i
x=s/n
print(x) | Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*... | ```python
n=int(input())
l=list(map(int,input().strip().split()))
if 1<=n<=100:
s=0
for i in l:
s+=i
x=s/n
print(x)
``` | 3 | |
76 | E | Points | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | E. Points | 1 | 256 | You are given *N* points on a plane. Write a program which will find the sum of squares of distances between all pairs of points. | The first line of input contains one integer number *N* (1<=≤<=*N*<=≤<=100<=000) — the number of points. Each of the following *N* lines contain two integer numbers *X* and *Y* (<=-<=10<=000<=≤<=*X*,<=*Y*<=≤<=10<=000) — the coordinates of points. Two or more points may coincide. | The only line of output should contain the required sum of squares of distances between all pairs of points. | [
"4\n1 1\n-1 -1\n1 -1\n-1 1\n"
] | [
"32\n"
] | none | 0 | [
{
"input": "4\n1 1\n-1 -1\n1 -1\n-1 1",
"output": "32"
},
{
"input": "1\n6 3",
"output": "0"
},
{
"input": "30\n-7 -12\n-2 5\n14 8\n9 17\n15 -18\n20 6\n20 8\n-13 12\n-4 -20\n-11 -16\n-6 16\n1 -9\n5 -12\n13 -17\n11 5\n8 -9\n-13 5\n19 -13\n-19 -8\n-14 10\n10 3\n-16 -8\n-17 16\n-14 -15\n5 1... | 1,581,754,972 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 124 | 204,800 | import math
if __name__== '__main__':
n = int(input())
totalDistance= 0
Xs= []
Ys= []
xs= []
ys= []
x_ve= 0
y_ve= 0
for _ in range(n):
x, y= [int(x) for x in input().split()]
Xs.append((n- 1)* x)
Ys.append((n- 1)* y)
xs.append(x)
... | Title: Points
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given *N* points on a plane. Write a program which will find the sum of squares of distances between all pairs of points.
Input Specification:
The first line of input contains one integer number *N* (1<=≤<=*N*<=≤<=100<=000)... | ```python
import math
if __name__== '__main__':
n = int(input())
totalDistance= 0
Xs= []
Ys= []
xs= []
ys= []
x_ve= 0
y_ve= 0
for _ in range(n):
x, y= [int(x) for x in input().split()]
Xs.append((n- 1)* x)
Ys.append((n- 1)* y)
xs.appe... | 0 |
922 | B | Magic Forest | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | Imp is in a magic forest, where xorangles grow (wut?)
A xorangle of order *n* is such a non-degenerate triangle, that lengths of its sides are integers not exceeding *n*, and the xor-sum of the lengths is equal to zero. Imp has to count the number of distinct xorangles of order *n* to get out of the forest.
Formally... | The only line contains a single integer *n* (1<=≤<=*n*<=≤<=2500). | Print the number of xorangles of order *n*. | [
"6\n",
"10\n"
] | [
"1\n",
"2\n"
] | The only xorangle in the first sample is (3, 5, 6). | 1,000 | [
{
"input": "6",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "2500",
"output": "700393"
},
{
"input": "952",
"output": "... | 1,678,905,858 | 2,147,483,647 | PyPy 3 | OK | TESTS | 44 | 93 | 1,945,600 | n=int(input())
k=0
for a in range(1,n+1):
for b in range(a,n+1):
c=a^b
if b<=c and c<=n and a+b>c and b+c>a and a+c>b:
k+=1
print(k)
| Title: Magic Forest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp is in a magic forest, where xorangles grow (wut?)
A xorangle of order *n* is such a non-degenerate triangle, that lengths of its sides are integers not exceeding *n*, and the xor-sum of the lengths is equal to zero. I... | ```python
n=int(input())
k=0
for a in range(1,n+1):
for b in range(a,n+1):
c=a^b
if b<=c and c<=n and a+b>c and b+c>a and a+c>b:
k+=1
print(k)
``` | 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,510,510,973 | 8,273 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 5 | 2,000 | 14,131,200 | n=input()
a = [int(s) for s in input().split()]
c=1
i=0
while c!=0:
if int(a[i] in a[i+1:]) == 0:
break
i+=1
print(a[i])
| 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=input()
a = [int(s) for s in input().split()]
c=1
i=0
while c!=0:
if int(a[i] in a[i+1:]) == 0:
break
i+=1
print(a[i])
``` | 0 | |
710 | B | Optimal Point on a Line | PROGRAMMING | 1,400 | [
"brute force",
"sortings"
] | null | null | You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line.
The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points. | Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer. | [
"4\n1 2 3 4\n"
] | [
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "5\n-1 -10 2 6 7",
"output": "2"
},
{
"input": "10\n-68 10 87 22 30 89 82 -97 -52 25",
"output": "22"
},
{
"input": "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -... | 1,614,696,907 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 295 | 22,323,200 | n=int(input())
intList=list(map(int,input().split()))
intList.sort()
if(n%2):
print(intList[n//2])
else:
print(intList[n//2-1])
| Title: Optimal Point on a Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=... | ```python
n=int(input())
intList=list(map(int,input().split()))
intList.sort()
if(n%2):
print(intList[n//2])
else:
print(intList[n//2-1])
``` | 3 | |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th... | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar... | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
... | 1,675,764,752 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 15 | 0 | # LUOGU_RID: 101648347
n, k = map(int, input().split())
s = 0
c = 0
while s + (c + 1) * 5 + k <= 240:
c += 1
s += c * 5
print(c) | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem... | ```python
# LUOGU_RID: 101648347
n, k = map(int, input().split())
s = 0
c = 0
while s + (c + 1) * 5 + k <= 240:
c += 1
s += c * 5
print(c)
``` | 0 | |
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},... | 1,699,124,527 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 62 | 0 | print("CHAT WITH HER!" if len(list(set(input())))%2==0 else "IGNORE HIM!") | Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though... | ```python
print("CHAT WITH HER!" if len(list(set(input())))%2==0 else "IGNORE HIM!")
``` | 3 | |
776 | B | Sherlock and his girlfriend | PROGRAMMING | 1,200 | [
"constructive algorithms",
"number theory"
] | null | null | Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pie... | The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces. | The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
... | [
"3\n",
"4\n"
] | [
"2\n1 1 2 ",
"2\n2 1 1 2\n"
] | In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | 1,000 | [
{
"input": "3",
"output": "2\n1 1 2 "
},
{
"input": "4",
"output": "2\n1 1 2 1 "
},
{
"input": "17",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 "
},
{
"input": "25",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 "
},
{
"input": "85",
"ou... | 1,659,728,261 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 53 | 109 | 9,830,400 | import math
n=int(input())
lt=[2]*(n+1)
l=[2]
for i in range(2,n+2):
for j in range(2,int(math.sqrt(i))+2):
if i%j==0:
break
else:
lt[i-1]=1
l.append(i)
lt[1]=1
if n<3:
print(1)
else:
print(2)
print(*lt[1:])
#print(l)
| Title: Sherlock and his girlfriend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the ... | ```python
import math
n=int(input())
lt=[2]*(n+1)
l=[2]
for i in range(2,n+2):
for j in range(2,int(math.sqrt(i))+2):
if i%j==0:
break
else:
lt[i-1]=1
l.append(i)
lt[1]=1
if n<3:
print(1)
else:
print(2)
print(*lt[1:])
#print(l)
``` | 3 | |
610 | B | Vika and Squares | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | null | null | Vika has *n* jars with paints of distinct colors. All the jars are numbered from 1 to *n* and the *i*-th jar contains *a**i* liters of paint of color *i*.
Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1<=×<=1. Squares are numbered 1, 2, 3 and so on. Vika decided ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of jars with colors Vika has.
The second line of the input contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is equal to the number of liters of paint in the *i*-th jar, i.e. th... | The only line of the output should contain a single integer — the maximum number of squares that Vika can paint if she follows the rules described above. | [
"5\n2 4 2 3 3\n",
"3\n5 5 5\n",
"6\n10 10 10 1 10 10\n"
] | [
"12\n",
"15\n",
"11\n"
] | In the first sample the best strategy is to start painting using color 4. Then the squares will be painted in the following colors (from left to right): 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5.
In the second sample Vika can start to paint using any color.
In the third sample Vika should start painting using color number 5... | 1,000 | [
{
"input": "5\n2 4 2 3 3",
"output": "12"
},
{
"input": "3\n5 5 5",
"output": "15"
},
{
"input": "6\n10 10 10 1 10 10",
"output": "11"
},
{
"input": "1\n167959139",
"output": "167959139"
},
{
"input": "10\n896619242 805194919 844752453 848347723 816995848 85681361... | 1,453,309,606 | 2,147,483,647 | Python 3 | OK | TESTS | 66 | 186 | 18,227,200 | def main():
n = int(input())
aa = list(map(int, input().split()))
m = min(aa)
for i in range(aa.index(m) - n, aa.index(m)):
if aa[i] == m:
aa[i] = x = 0
else:
x += 1
aa[i] = x
print(m * n + max(aa))
if __name__ == '__main__':
main()
| Title: Vika and Squares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vika has *n* jars with paints of distinct colors. All the jars are numbered from 1 to *n* and the *i*-th jar contains *a**i* liters of paint of color *i*.
Vika also has an infinitely long rectangular piece of paper of... | ```python
def main():
n = int(input())
aa = list(map(int, input().split()))
m = min(aa)
for i in range(aa.index(m) - n, aa.index(m)):
if aa[i] == m:
aa[i] = x = 0
else:
x += 1
aa[i] = x
print(m * n + max(aa))
if __name__ == '__main__':
main(... | 3 | |
218 | B | Airport | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th... | Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. | [
"4 3\n2 1 1\n",
"4 3\n2 2 2\n"
] | [
"5 5\n",
"7 6\n"
] | In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd pl... | 500 | [
{
"input": "4 3\n2 1 1",
"output": "5 5"
},
{
"input": "4 3\n2 2 2",
"output": "7 6"
},
{
"input": "10 5\n10 3 3 1 2",
"output": "58 26"
},
{
"input": "10 1\n10",
"output": "55 55"
},
{
"input": "10 1\n100",
"output": "955 955"
},
{
"input": "10 2\n4 7... | 1,584,901,362 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 404 | 2,048,000 | count=0
n=int(input())
a=[int(i) for i in input().split()]
for i in range(0,len(a)):
count=count+abs(abs(a[i])-1)
print(count)
| Title: Airport
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen pl... | ```python
count=0
n=int(input())
a=[int(i) for i in input().split()]
for i in range(0,len(a)):
count=count+abs(abs(a[i])-1)
print(count)
... | -1 | |
158 | B | Taxi | PROGRAMMING | 1,100 | [
"*special",
"greedy",
"implementation"
] | null | null | After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers.... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of groups of schoolchildren. The second line contains a sequence of integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s**i*<=≤<=4). The integers are separated by a space, *s**i* is the number of children in the *i*-th group. | Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus. | [
"5\n1 2 4 3 3\n",
"8\n2 3 4 4 2 1 3 1\n"
] | [
"4\n",
"5\n"
] | In the first test we can sort the children into four cars like this:
- the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly).
There a... | 1,000 | [
{
"input": "5\n1 2 4 3 3",
"output": "4"
},
{
"input": "8\n2 3 4 4 2 1 3 1",
"output": "5"
},
{
"input": "5\n4 4 4 4 4",
"output": "5"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "4\n3 ... | 1,699,095,241 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | n = int(input())
A = list(map(int, input(). split()))
B = [0] * 5
kol = 0
for i in range(len(A)):
B[A[i]] += 1
q = min(B[1], B[3])
kol += q
B[1] -= q
B[3] -= q
kol += B[2] // 2
B[2] %= 2
q = min(B[2], B[1] // 2)
kol += q
B[2] -= q
B[1] -= 2 * q
kol += sum(B)
kol += B[1] // 4
B[1] %= 4
print(kol)
... | Title: Taxi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpu... | ```python
n = int(input())
A = list(map(int, input(). split()))
B = [0] * 5
kol = 0
for i in range(len(A)):
B[A[i]] += 1
q = min(B[1], B[3])
kol += q
B[1] -= q
B[3] -= q
kol += B[2] // 2
B[2] %= 2
q = min(B[2], B[1] // 2)
kol += q
B[2] -= q
B[1] -= 2 * q
kol += sum(B)
kol += B[1] // 4
B[1] %= 4
p... | 0 | |
343 | B | Alternating Current | PROGRAMMING | 1,600 | [
"data structures",
"greedy",
"implementation"
] | null | null | Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended u... | The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | [
"-++-\n",
"+-\n",
"++\n",
"-\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"No\n"
] | The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.
In the second testcase the "plus" wire makes one full rev... | 1,000 | [
{
"input": "-++-",
"output": "Yes"
},
{
"input": "+-",
"output": "No"
},
{
"input": "++",
"output": "Yes"
},
{
"input": "-",
"output": "No"
},
{
"input": "+-+-",
"output": "No"
},
{
"input": "-+-",
"output": "No"
},
{
"input": "-++-+--+",
... | 1,602,433,350 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 280 | 1,843,200 | arr = list(input())
ans = []
for i in arr:
if len(ans)==0:
ans.append(i)
else:
if ans[-1]==i:
ans.pop(-1)
else:
ans.append(i)
if len(ans):
print('No')
else:
print('Yes')
| Title: Alternating Current
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it... | ```python
arr = list(input())
ans = []
for i in arr:
if len(ans)==0:
ans.append(i)
else:
if ans[-1]==i:
ans.pop(-1)
else:
ans.append(i)
if len(ans):
print('No')
else:
print('Yes')
``` | 3 | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,696,860,950 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | students, puzzles = map(int, input().split())
pieces = list(map(int, input().split()))
pieces.sort()
sub_pieces = pieces[:students]
difference = sub_pieces[-1] - sub_pieces[0]
print(difference) | Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
students, puzzles = map(int, input().split())
pieces = list(map(int, input().split()))
pieces.sort()
sub_pieces = pieces[:students]
difference = sub_pieces[-1] - sub_pieces[0]
print(difference)
``` | 0 | |
760 | A | Petr and a calendar | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
Petr wants to ... | The only line contain two integers *m* and *d* (1<=≤<=*m*<=≤<=12, 1<=≤<=*d*<=≤<=7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday). | Print single integer: the number of columns the table should have. | [
"1 7\n",
"1 1\n",
"11 6\n"
] | [
"6\n",
"5\n",
"5\n"
] | The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough. | 500 | [
{
"input": "1 7",
"output": "6"
},
{
"input": "1 1",
"output": "5"
},
{
"input": "11 6",
"output": "5"
},
{
"input": "2 7",
"output": "5"
},
{
"input": "2 1",
"output": "4"
},
{
"input": "8 6",
"output": "6"
},
{
"input": "1 1",
"output... | 1,485,614,499 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a=list(map(int,input().split()))
dayinm=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
answ=(dayinm[a[0]-1]-(8-a[1])+6//7+1
print(answ) | Title: Petr and a calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells... | ```python
a=list(map(int,input().split()))
dayinm=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
answ=(dayinm[a[0]-1]-(8-a[1])+6//7+1
print(answ)
``` | -1 | |
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water... | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the f... | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 ... | 1,647,844,350 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 92 | 0 | num=int(input())
lis=list(map(int,input().split()))
lis.sort(reverse=True)
sap=0
cap=0
for i in range(12):
if sap>=num:
break
sap+=lis[i]
cap+=1
if sap<num:
print(-1)
else:
print(cap)
| Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya open... | ```python
num=int(input())
lis=list(map(int,input().split()))
lis.sort(reverse=True)
sap=0
cap=0
for i in range(12):
if sap>=num:
break
sap+=lis[i]
cap+=1
if sap<num:
print(-1)
else:
print(cap)
``` | 3 | |
586 | A | Alena's Schedule | PROGRAMMING | 900 | [
"implementation"
] | null | null | Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).
The University works in such a way that every day it... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university.
The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* ar... | Print a single number — the number of pairs during which Alena stays at the university. | [
"5\n0 1 0 1 1\n",
"7\n1 0 1 0 0 1 0\n",
"1\n0\n"
] | [
"4\n",
"4\n",
"0\n"
] | In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair.
In the last sample Alena doesn't have a single pair, so she spends all the time at home. | 500 | [
{
"input": "5\n0 1 0 1 1",
"output": "4"
},
{
"input": "7\n1 0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "2\n0 1",
"output": "1"
},
{
... | 1,558,639,237 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 93 | 0 | n = int(input())
a = list(map(int, input().split()))
cnt = n;
z = 0
for i in range(n):
if a[i] == 0:
z += 1
else:
if z >= 2:
cnt -= z
z = 0
cnt -= z
if a[0] == 0 and a[1] == 1:
cnt -= 1
print(cnt)
| Title: Alena's Schedule
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic ... | ```python
n = int(input())
a = list(map(int, input().split()))
cnt = n;
z = 0
for i in range(n):
if a[i] == 0:
z += 1
else:
if z >= 2:
cnt -= z
z = 0
cnt -= z
if a[0] == 0 and a[1] == 1:
cnt -= 1
print(cnt)
``` | -1 | |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,572,153,527 | 2,147,483,647 | PyPy 3 | OK | TESTS | 61 | 280 | 0 | ch="chest"
bi="biceps"
ba="back"
m={ch:0,bi:0,ba:0}
n=int(input())
a=map(int,input().split())
s=[ch,bi,ba]*n
z=zip(s[:n],a)
for e,ai in z:
m[e]+=ai
print(max(m,key=m.get))
| Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
ch="chest"
bi="biceps"
ba="back"
m={ch:0,bi:0,ba:0}
n=int(input())
a=map(int,input().split())
s=[ch,bi,ba]*n
z=zip(s[:n],a)
for e,ai in z:
m[e]+=ai
print(max(m,key=m.get))
``` | 3 | |
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works... | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"inp... | 1,632,148,425 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 310 | 23,040,000 | from collections import Counter
import re
a = list(range(1, int(input())+1))
def elesort(x):
if x == 0:
return
a[x], a[x-1] = a[x-1], a[x]
elesort(x-1)
elesort(len(a)-1)
print(*a)
| Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the perm... | ```python
from collections import Counter
import re
a = list(range(1, int(input())+1))
def elesort(x):
if x == 0:
return
a[x], a[x-1] = a[x-1], a[x]
elesort(x-1)
elesort(len(a)-1)
print(*a)
``` | 3 | |
483 | B | Friends and Presents | PROGRAMMING | 1,800 | [
"binary search",
"math"
] | null | null | You have two friends. You want to present each of them several positive integers. You want to present *cnt*1 numbers to the first friend and *cnt*2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.
In addition, the... | The only line contains four positive integers *cnt*1, *cnt*2, *x*, *y* (1<=≤<=*cnt*1,<=*cnt*2<=<<=109; *cnt*1<=+<=*cnt*2<=≤<=109; 2<=≤<=*x*<=<<=*y*<=≤<=3·104) — the numbers that are described in the statement. It is guaranteed that numbers *x*, *y* are prime. | Print a single integer — the answer to the problem. | [
"3 1 2 3\n",
"1 3 2 3\n"
] | [
"5\n",
"4\n"
] | In the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend.
In the second sample you give the set of numbers {3} to the first... | 1,000 | [
{
"input": "3 1 2 3",
"output": "5"
},
{
"input": "1 3 2 3",
"output": "4"
},
{
"input": "916200 69682 2 3",
"output": "1832399"
},
{
"input": "808351 17767 433 509",
"output": "826121"
},
{
"input": "8851 901 20897 26183",
"output": "9752"
},
{
"input... | 1,690,348,733 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 62 | 0 | def main():
cnt1, cnt2, x, y = list(map(int, input().split()))
l, r = -1, 10**18
ans = 10**18
while l+1 < r:
v = (l + r) // 2
if max(cnt1 - v // y + v//(x*y), 0) + max(cnt2 - v // x + v // (x*y), 0)<= v - v//x - v//y + v // (x * y):
ans = min(ans, v)
r = v... | Title: Friends and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have two friends. You want to present each of them several positive integers. You want to present *cnt*1 numbers to the first friend and *cnt*2 numbers to the second friend. Moreover, you want all presented num... | ```python
def main():
cnt1, cnt2, x, y = list(map(int, input().split()))
l, r = -1, 10**18
ans = 10**18
while l+1 < r:
v = (l + r) // 2
if max(cnt1 - v // y + v//(x*y), 0) + max(cnt2 - v // x + v // (x*y), 0)<= v - v//x - v//y + v // (x * y):
ans = min(ans, v)
... | 3 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,694,893,892 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n=int(input())
list1=list(map(int,input().split()))
list1.sort()
list1.reverse()
sum1=0
sum2=0
for x in range(n):
if x%2==0:
sum1+=list1[x]
else:
sum2+=list1[x]
print(sum1,sum2) | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
n=int(input())
list1=list(map(int,input().split()))
list1.sort()
list1.reverse()
sum1=0
sum2=0
for x in range(n):
if x%2==0:
sum1+=list1[x]
else:
sum2+=list1[x]
print(sum1,sum2)
``` | 0 | |
584 | A | Olesya and Rodion | PROGRAMMING | 1,000 | [
"math"
] | null | null | Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-... | The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by. | Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them. | [
"3 2\n"
] | [
"712"
] | none | 500 | [
{
"input": "3 2",
"output": "222"
},
{
"input": "2 2",
"output": "22"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 3",
"output": "33333"
},
{
"input": "10 7",
"output": "7777777777"
},
{
"input": "2 9",
"output": "99"
},
{
"input"... | 1,694,530,324 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n = int(input())
t = int(input())
res = 1;
if (t != 10):
res = res*(10**(n-1))
res = res*t
else:
res = res*(10**(n-1))
print(res)
| Title: Olesya and Rodion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larg... | ```python
n = int(input())
t = int(input())
res = 1;
if (t != 10):
res = res*(10**(n-1))
res = res*t
else:
res = res*(10**(n-1))
print(res)
``` | -1 | |
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium ... | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially ... | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",... | 1,672,164,507 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | # Wadea #
s1 = input()
s2 = input()
r = s1.index("|")
r2 = len(s2)-1
if r == 0:
print(s2+s1)
elif r == r2:
print("Impossible")
elif r > 0:
print(s1+s2)
elif 0 < r < r2:
print("Impossible")
| Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all ... | ```python
# Wadea #
s1 = input()
s2 = input()
r = s1.index("|")
r2 = len(s2)-1
if r == 0:
print(s2+s1)
elif r == r2:
print("Impossible")
elif r > 0:
print(s1+s2)
elif 0 < r < r2:
print("Impossible")
``` | 0 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,669,209,874 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | # B. Напитки
#
# n = int(input())
# s = input().split()
# s = [int(x) for x in s]
# r = sum(s) / n
# print(r)
n, k = map(int, input().split())
s = input().split()
s = [int(x) for x in s]
b = []
for i in s:
if i + k <= 5:
b.append(i)
print(len(b) // 3) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
# B. Напитки
#
# n = int(input())
# s = input().split()
# s = [int(x) for x in s]
# r = sum(s) / n
# print(r)
n, k = map(int, input().split())
s = input().split()
s = [int(x) for x in s]
b = []
for i in s:
if i + k <= 5:
b.append(i)
print(len(b) // 3)
``` | 3 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,693,658,287 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | string1=input()
st1=string1.lower()
string2=input()
st2=string2.lower()
st3=""
for i in range(len(st2)-1,-1,-1):
c=st2[i]
st3+=c
if st2==st3:
print("YES")
else:
print("NO") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
string1=input()
st1=string1.lower()
string2=input()
st2=string2.lower()
st3=""
for i in range(len(st2)-1,-1,-1):
c=st2[i]
st3+=c
if st2==st3:
print("YES")
else:
print("NO")
``` | 0 |
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,632,030,695 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 122 | 6,963,200 | y,w = input().split()
maxx = max(y,w)
total = 6-int(maxx)+1
if total==6:
print('1/1')
elif total==6:
print('5/6')
elif total==4:
print('2/3')
elif total==3:
print('1/2')
elif total==2:
print('1/3')
elif total==1:
print('1/6')
| 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
y,w = input().split()
maxx = max(y,w)
total = 6-int(maxx)+1
if total==6:
print('1/1')
elif total==6:
print('5/6')
elif total==4:
print('2/3')
elif total==3:
print('1/2')
elif total==2:
print('1/3')
elif total==1:
print('1/6')
``` | 0 |
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"ou... | 1,632,214,287 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 78 | 6,758,400 | a, b = map(int, input().split())
def fact(x):
if x == 1: return 1
return x * fact(x - 1)
print(fact(min(a, b)))
| Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi... | ```python
a, b = map(int, input().split())
def fact(x):
if x == 1: return 1
return x * fact(x - 1)
print(fact(min(a, b)))
``` | 3 | |
120 | F | Spiders | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"trees"
] | null | null | One day mum asked Petya to sort his toys and get rid of some of them. Petya found a whole box of toy spiders. They were quite dear to him and the boy didn't want to throw them away. Petya conjured a cunning plan: he will glue all the spiders together and attach them to the ceiling. Besides, Petya knows that the lower t... | The first input file line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of spiders. Next *n* lines contain the descriptions of each spider: integer *n**i* (2<=≤<=*n**i*<=≤<=100) — the number of beads, then *n**i*<=-<=1 pairs of numbers denoting the numbers of the beads connected by threads. The beads that m... | Print a single number — the length of the required construction. | [
"1\n3 1 2 2 3\n",
"2\n3 1 2 1 3\n4 1 2 2 3 2 4\n",
"2\n5 1 2 2 3 3 4 3 5\n7 3 4 1 2 2 4 4 6 2 7 6 5\n"
] | [
"2\n",
"4\n",
"7\n"
] | none | 0 | [
{
"input": "1\n3 1 2 2 3",
"output": "2"
},
{
"input": "2\n3 1 2 1 3\n4 1 2 2 3 2 4",
"output": "4"
},
{
"input": "2\n5 1 2 2 3 3 4 3 5\n7 3 4 1 2 2 4 4 6 2 7 6 5",
"output": "7"
},
{
"input": "3\n3 1 2 2 3\n5 2 5 5 3 3 4 5 1\n9 6 5 5 9 4 8 4 7 2 1 2 6 2 4 6 3",
"output":... | 1,600,983,565 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 434 | 67,584,000 | # Author: S Mahesh Raju
# Username: maheshraju2020
# Created on: 25/09/2020 02:59:49
from sys import stdin, stdout, setrecursionlimit
import heapq
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
from itertools import combinations, permutatio... | Title: Spiders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day mum asked Petya to sort his toys and get rid of some of them. Petya found a whole box of toy spiders. They were quite dear to him and the boy didn't want to throw them away. Petya conjured a cunning plan: he will glue a... | ```python
# Author: S Mahesh Raju
# Username: maheshraju2020
# Created on: 25/09/2020 02:59:49
from sys import stdin, stdout, setrecursionlimit
import heapq
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
from itertools import combinations, ... | -1 | |
525 | A | Vitaliy and Pie | PROGRAMMING | 1,100 | [
"greedy",
"hashing",
"strings"
] | null | null | After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ... | 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,622,850,252 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 409,600 | #%%
n = int(input())
plan = input()
keys = []
new_keys = 0
for i in range(0, len(plan), 2):
if plan[i].capitalize() != plan[i+1] and plan[i+1].lower() not in keys:
new_keys += 1
keys.append(plan[i])
elif plan[i+1].lower() in keys:
keys.remove(plan[i+1].lower())
... | 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())
plan = input()
keys = []
new_keys = 0
for i in range(0, len(plan), 2):
if plan[i].capitalize() != plan[i+1] and plan[i+1].lower() not in keys:
new_keys += 1
keys.append(plan[i])
elif plan[i+1].lower() in keys:
keys.remove(plan[i+1].lo... | 0 | |
588 | B | Duff in Love | PROGRAMMING | 1,300 | [
"math"
] | null | null | Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=><=1 such that *a*2 is a divisor of *x*.
Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek want... | The first and only line of input contains one integer, *n* (1<=≤<=*n*<=≤<=1012). | Print the answer in one line. | [
"10\n",
"12\n"
] | [
"10\n",
"6\n"
] | In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely.
In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2<sup class="upper-index">2</sup>, so 12 is not lovely, while 6 is indeed lovely. | 1,000 | [
{
"input": "10",
"output": "10"
},
{
"input": "12",
"output": "6"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "8",
"output": "2"
},
{
"input": "3",
"output": "3"
},
... | 1,567,450,339 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 608 | 0 | n=int(input())
for i in range(2, 10**6):
while n%(i**2)==0:
n//= i
print(n)
| Title: Duff in Love
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=><=1 such that *a*2 is a divisor of *x*.
Malek has a number store! In his store, he has... | ```python
n=int(input())
for i in range(2, 10**6):
while n%(i**2)==0:
n//= i
print(n)
``` | 3 | |
1,004 | A | Sonya and Hotels | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin... | The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coord... | Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. | [
"4 3\n-3 2 9 16\n",
"5 2\n4 8 11 18 19\n"
] | [
"6\n",
"5\n"
] | In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | 500 | [
{
"input": "4 3\n-3 2 9 16",
"output": "6"
},
{
"input": "5 2\n4 8 11 18 19",
"output": "5"
},
{
"input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83",
"output": "8"
},
{
"input": "10 10\n0 20 48 58 81 95 111 137 147 159",
"output": "9"
},
{
"input": "100 1\n0 1 2 3... | 1,683,721,372 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 46 | 0 | n, d = map(int, input().split())
hotels = list(map(int, input().split()))
count = 2 # initialize the count with 2, for the first and last possible positions
for i in range(1, n):
if hotels[i] - hotels[i-1] == 2 * d: # if the distance between the i-th and (i-1)-th hotels is 2d
count += 1 # add a new... | Title: Sonya and Hotels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer c... | ```python
n, d = map(int, input().split())
hotels = list(map(int, input().split()))
count = 2 # initialize the count with 2, for the first and last possible positions
for i in range(1, n):
if hotels[i] - hotels[i-1] == 2 * d: # if the distance between the i-th and (i-1)-th hotels is 2d
count += 1 #... | 3 | |
447 | B | DZY Loves Strings | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to in... | The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. | Print a single integer — the largest possible value of the resulting string DZY could get. | [
"abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
] | [
"41\n"
] | In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | 1,000 | [
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "41"
},
{
"input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453",
"output": "29978"
},
{
"input": "ajeeseerqnpaujubmajpibxrccazaawetyw... | 1,564,855,381 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 108 | 0 | s=input()
k=int(input())
x,Sum = list(map(int, input().split(" "))),0
for i in range(len(s)):
Sum+=x[ord(s[i])-97]*(i+1)
print(Sum+sum(max(x)*(i+1) for i in range(len(s),len(s)+k))) | Title: DZY Loves Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the str... | ```python
s=input()
k=int(input())
x,Sum = list(map(int, input().split(" "))),0
for i in range(len(s)):
Sum+=x[ord(s[i])-97]*(i+1)
print(Sum+sum(max(x)*(i+1) for i in range(len(s),len(s)+k)))
``` | 3 | |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,694,658,670 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 13,209,600 | def maxbook(n,time,data):
start=0
end=0
sumtime=data[0]
maxnum=0
while end<=n-1:
if sumtime<=time:
end+=1
else:
start+=1
sumtime=sum(data[start:end+1])
num=end-start
maxnum=max(maxnum,num)
return maxnum
data0=[int(x) f... | Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
def maxbook(n,time,data):
start=0
end=0
sumtime=data[0]
maxnum=0
while end<=n-1:
if sumtime<=time:
end+=1
else:
start+=1
sumtime=sum(data[start:end+1])
num=end-start
maxnum=max(maxnum,num)
return maxnum
data0... | 0 | |
295 | A | Greg and Array | PROGRAMMING | 1,400 | [
"data structures",
"implementation"
] | null | null | Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*.
Greg wrote down *k* qu... | The first line contains integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105). The second line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105) — the initial array.
Next *m* lines contain operations, the operation number *i* is written as three integers: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=... | On a single line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | [
"3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n",
"1 1 1\n1\n1 1 1\n1 1\n",
"4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n"
] | [
"9 18 17\n",
"2\n",
"5 18 31 20\n"
] | none | 500 | [
{
"input": "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3",
"output": "9 18 17"
},
{
"input": "1 1 1\n1\n1 1 1\n1 1",
"output": "2"
},
{
"input": "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3",
"output": "5 18 31 20"
},
{
"input": "1 1 1\n0\n1 1 0\n1 1... | 1,593,312,126 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,500 | 42,598,400 |
n,m,k = map(int,input().split())
t = list(map(int,input().split()))
f=['1']+[0]*m
y=[]
for j in range(m):
y.append(list(map(int,input().split())))
for g in range(k):
a,b = map(int,input().split())
for w in range(a,b+1):
f[w]+=1
for d in range(m):
y[d][-1]= y[d]... | Title: Greg and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array... | ```python
n,m,k = map(int,input().split())
t = list(map(int,input().split()))
f=['1']+[0]*m
y=[]
for j in range(m):
y.append(list(map(int,input().split())))
for g in range(k):
a,b = map(int,input().split())
for w in range(a,b+1):
f[w]+=1
for d in range(m):
y[d]... | 0 | |
202 | A | LLPS | PROGRAMMING | 800 | [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*... | The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. | Print the lexicographically largest palindromic subsequence of string *s*. | [
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] | [
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] | Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | 500 | [
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
... | 1,677,172,672 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 60 | 0 | s = input()
res = s[-1] * s.count(s[-1])
mx = 1
print(res) | Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ... | ```python
s = input()
res = s[-1] * s.count(s[-1])
mx = 1
print(res)
``` | 0 | |
302 | A | Eugeny and Array | PROGRAMMING | 800 | [
"implementation"
] | null | null | Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of a... | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print *m* integers — the responses to Eugene's queries in the order they occur in the input. | [
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n"
] | [
"0\n1\n0\n",
"0\n1\n0\n1\n0\n"
] | none | 500 | [
{
"input": "2 3\n1 -1\n1 1\n1 2\n2 2",
"output": "0\n1\n0"
},
{
"input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5",
"output": "0\n1\n0\n1\n0"
},
{
"input": "3 3\n1 1 1\n2 2\n1 1\n1 1",
"output": "0\n0\n0"
},
{
"input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1",
"output": "... | 1,569,405,605 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 11,571,200 | #import math
n, m = input().split()
n = int (n)
m = int (m)
#n, m, k = input().split()
#n = int (n)
#m = int (m)
#k = int (k)
#n = int(input())
#m = int(input())
#s = input()
#t = input()
g = list(map(int, input().split()))
ones = g.count(1)
mi = n - ones
#print(l)
#c = list(map(int, input().split()))... | Title: Eugeny and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (... | ```python
#import math
n, m = input().split()
n = int (n)
m = int (m)
#n, m, k = input().split()
#n = int (n)
#m = int (m)
#k = int (k)
#n = int(input())
#m = int(input())
#s = input()
#t = input()
g = list(map(int, input().split()))
ones = g.count(1)
mi = n - ones
#print(l)
#c = list(map(int, input()... | 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,641,920,367 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 45 | 342 | 12,800,000 | #For fast I/O
import sys
input = sys.stdin.readline
n = int(input())
l = [int(i) for i in input().split()]
smol = min(l)
if l.count(smol) == 1:
print(l.index(smol)+1)
else:
print("Still Rozdil")
| 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
#For fast I/O
import sys
input = sys.stdin.readline
n = int(input())
l = [int(i) for i in input().split()]
smol = min(l)
if l.count(smol) == 1:
print(l.index(smol)+1)
else:
print("Still Rozdil")
``` | 3 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,419,065,172 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 0 | a=int(input())
b=a
j=5
k=0
l=["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
if a<5:
print(l[a-1])
else:
for i in range(1,a+1):
if j>b:
p=(j/(5))
k=b//p
k=int(k)
print(l[k])
... | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
a=int(input())
b=a
j=5
k=0
l=["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
if a<5:
print(l[a-1])
else:
for i in range(1,a+1):
if j>b:
p=(j/(5))
k=b//p
k=int(k)
print(l[k... | 0 |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,656,880,673 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 966 | 26,316,800 | from hashlib import new
import sys
import threading
from sys import stdin, stdout
from itertools import accumulate
input = stdin.readline
print = stdout.write
import math
if __name__ == "__main__":
n = int(input().strip())
arr = list(map(int, input().strip().split()))
dict = {x:i ... | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
from hashlib import new
import sys
import threading
from sys import stdin, stdout
from itertools import accumulate
input = stdin.readline
print = stdout.write
import math
if __name__ == "__main__":
n = int(input().strip())
arr = list(map(int, input().strip().split()))
di... | 3 | |
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\... | 1,669,211,502 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 31 | 0 | n = int(input())
a = map(int, input().split())
a = list(a)
s = []
for i in range(n):
if a[i] != 0:
s.append(a[i])
if sum(s)%2!=0:
s.pop(a[i]%2!=0)
if sum(s)%2==0:
print(sum(s))
elif sum(s)%2!=0:
print(0) | Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, th... | ```python
n = int(input())
a = map(int, input().split())
a = list(a)
s = []
for i in range(n):
if a[i] != 0:
s.append(a[i])
if sum(s)%2!=0:
s.pop(a[i]%2!=0)
if sum(s)%2==0:
print(sum(s))
elif sum(s)%2!=0:
print(0)
``` | -1 | |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,699,531,650 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 13 | 62 | 0 | n=int(input())
strcoins= list(map(int, input().split()))
totalvalue=0
sumaextraida=0
nummonedas=0
casillero=[0]*100
#for i in range(100):
#casillero[i]=0
for i in range(n):
totalvalue=totalvalue+strcoins[i]
a=strcoins[i]
casillero[a]=casillero[a]+1
minmoneytotake=(totalvalue/2)
#print(minmo... | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
n=int(input())
strcoins= list(map(int, input().split()))
totalvalue=0
sumaextraida=0
nummonedas=0
casillero=[0]*100
#for i in range(100):
#casillero[i]=0
for i in range(n):
totalvalue=totalvalue+strcoins[i]
a=strcoins[i]
casillero[a]=casillero[a]+1
minmoneytotake=(totalvalue/2)
#p... | -1 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery.
Soon the expenses started to overcome the income, so Slastyona decided to study the sweets market. She learned it's profitable to pack ca... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=35000, 1<=≤<=*k*<=≤<=*min*(*n*,<=50)) – the number of cakes and the number of boxes, respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) – the types of cakes in the order the oven bakes them. | Print the only integer – the maximum total value of all boxes with cakes. | [
"4 1\n1 2 2 1\n",
"7 2\n1 3 3 1 4 4 4\n",
"8 3\n7 7 8 7 7 8 1 7\n"
] | [
"2\n",
"5\n",
"6\n"
] | In the first example Slastyona has only one box. She has to put all cakes in it, so that there are two types of cakes in the box, so the value is equal to 2.
In the second example it is profitable to put the first two cakes in the first box, and all the rest in the second. There are two distinct types in the first box... | 0 | [] | 1,501,584,334 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,500 | 8,192,000 |
n,k = map(int, input().split())
cakes = list(map(int, input().split()))
dp = [[0 for _ in range(n)] for _ in range(k+1)]
dp[1] = [len(set(cakes[:i])) for i in range(1,n+1)]
#print(dp)
for box in range(2,k+1):
for cake in range(n):
#print(box, cake, [dp[box-1][i] + len(set(cakes[i+1:cake+1])) ... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery.
Soon the expenses started to overcome the incom... | ```python
n,k = map(int, input().split())
cakes = list(map(int, input().split()))
dp = [[0 for _ in range(n)] for _ in range(k+1)]
dp[1] = [len(set(cakes[:i])) for i in range(1,n+1)]
#print(dp)
for box in range(2,k+1):
for cake in range(n):
#print(box, cake, [dp[box-1][i] + len(set(cakes[i+1:... | 0 | |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal 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,692,187,644 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 124 | 0 |
def main():
n = int(input())
print(sum([int(i) for i in input().split()])/n)
if __name__ == "__main__":
main() | 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
def main():
n = int(input())
print(sum([int(i) for i in input().split()])/n)
if __name__ == "__main__":
main()
``` | 3 | |
573 | B | Bear and Blocks | PROGRAMMING | 1,600 | [
"binary search",
"data structures",
"dp",
"math"
] | null | null | Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built *n* towers in a row. The *i*-th tower is made of *h**i* identical blocks. For clarification see picture for the first sample.
Limak will repeat the following operation till everything is destroyed.
Block is called inter... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109) — sizes of towers. | Print the number of operations needed to destroy all towers. | [
"6\n2 1 4 6 2 2\n",
"7\n3 3 3 1 3 3 3\n"
] | [
"3\n",
"2\n"
] | The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color. | 1,000 | [
{
"input": "6\n2 1 4 6 2 2",
"output": "3"
},
{
"input": "7\n3 3 3 1 3 3 3",
"output": "2"
},
{
"input": "7\n5128 5672 5805 5452 5882 5567 5032",
"output": "4"
},
{
"input": "10\n1 2 2 3 5 5 5 4 2 1",
"output": "5"
},
{
"input": "14\n20 20 20 20 20 20 3 20 20 20 2... | 1,691,920,381 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 14 | 187 | 18,739,200 | import sys
input= lambda: sys.stdin.buffer.readline().decode('utf-8').rstrip('\r\n')
from array import array
inp= lambda: int(input())
mi = lambda x=int : map(x, input().split())
arr= lambda d='i',x=int: array(d,mi(x))
li = lambda x=int: list(mi(x))
lb = lambda: list(map(int, input()))
ls = lambda: list(... | Title: Bear and Blocks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built *n* towers in a row. The *i*-th tower is made of *h**i* identical blocks. For clarification see picture for the first sa... | ```python
import sys
input= lambda: sys.stdin.buffer.readline().decode('utf-8').rstrip('\r\n')
from array import array
inp= lambda: int(input())
mi = lambda x=int : map(x, input().split())
arr= lambda d='i',x=int: array(d,mi(x))
li = lambda x=int: list(mi(x))
lb = lambda: list(map(int, input()))
ls = lam... | 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,689,352,422 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 78 | 13,107,200 | n, k, q = map(int, input().split())
recipes = []
for _ in range(n):
li, ri = map(int, input().split())
recipes.append((li, ri))
recipes.sort() # Sort the recipes based on the start temperature
prefix = [0] * 200001
count = 0
j = 0
for i in range(1, 200001):
while j < n and recipes[j][0] =... | 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())
recipes = []
for _ in range(n):
li, ri = map(int, input().split())
recipes.append((li, ri))
recipes.sort() # Sort the recipes based on the start temperature
prefix = [0] * 200001
count = 0
j = 0
for i in range(1, 200001):
while j < n and recip... | 0 | |
907 | A | Masha and Bears | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg... | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 500 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"... | 1,514,215,219 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 5,632,000 | op=input().split()
a=int(op[0])
b=int(op[1])
way=list(input())
i=0
o=0
time=0
true=0
while True:
if i+b>=a-1:
time=time+1
break
for aa in range(i+1,i+b+1):
if way[aa]=="1":
o=aa
if o==i:
true=1
break
else:
i=o
... | Title: Masha and Bears
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son b... | ```python
op=input().split()
a=int(op[0])
b=int(op[1])
way=list(input())
i=0
o=0
time=0
true=0
while True:
if i+b>=a-1:
time=time+1
break
for aa in range(i+1,i+b+1):
if way[aa]=="1":
o=aa
if o==i:
true=1
break
else:
i... | -1 | |
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,696,069,668 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | H = "Hello"
s = input()
cnt = 0
for c in s:
if c == H[cnt]:
cnt += 1
if cnt == len(H):
break
print("YES" if cnt >= len(H) else "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
H = "Hello"
s = input()
cnt = 0
for c in s:
if c == H[cnt]:
cnt += 1
if cnt == len(H):
break
print("YES" if cnt >= len(H) else "NO")
``` | 0 |
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water... | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the f... | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 ... | 1,670,674,750 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 62 | 0 | # from lib2to3.pgen2.token import RPAR
import math
import sys
# n=int(input())
# t=True
# s=input()
# arr=[]
# arr[:0]=s
# print(arr)
# ans=0
# ax=[]
# ay=[]
# for i in range(int(input())):
# x=int(input())
# a,b,c=map(int,input().split())
# st=input()
# x,y=map(int,input().split())
n=... | Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya open... | ```python
# from lib2to3.pgen2.token import RPAR
import math
import sys
# n=int(input())
# t=True
# s=input()
# arr=[]
# arr[:0]=s
# print(arr)
# ans=0
# ax=[]
# ay=[]
# for i in range(int(input())):
# x=int(input())
# a,b,c=map(int,input().split())
# st=input()
# x,y=map(int,input().spl... | -1 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,697,094,937 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | # -*- coding: utf-8 -*-
"""
Created on Thu Oct 12 15:11:42 2023
@author: 20311
"""
def check(a):
if a.find('1111111')!=-1 or a.find('0000000')!=-1:
return True
else:
return False
a=str(input())
if check(a):
print('YES')
else:
print('No')
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 12 15:11:42 2023
@author: 20311
"""
def check(a):
if a.find('1111111')!=-1 or a.find('0000000')!=-1:
return True
else:
return False
a=str(input())
if check(a):
print('YES')
else:
print('No')
``` | 0 |
244 | B | Undoubtedly Lucky Numbers | PROGRAMMING | 1,600 | [
"bitmasks",
"brute force",
"dfs and similar"
] | null | null | Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits *x* and *y*. For example, if *x*<==<=4, and *y*<==<=7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer *a* undoubtedly lucky, if... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Polycarpus's number. | Print a single integer that says, how many positive integers that do not exceed *n* are undoubtedly lucky. | [
"10\n",
"123\n"
] | [
"10\n",
"113\n"
] | In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | 1,000 | [
{
"input": "10",
"output": "10"
},
{
"input": "123",
"output": "113"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "1000",
"output": "352"
},
{
"input": "1000000000",
"output": "40744"
},
{
"input": "999999... | 1,655,529,741 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 0 | t = int(input())
cnt = 0
for i in range(t+1):
a = str(i)
if len(set(a)) == 1 or len(set(a)) == 2:
cnt += 1
print(cnt-1) | Title: Undoubtedly Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits *x* and *y*. For example, if *x*<==... | ```python
t = int(input())
cnt = 0
for i in range(t+1):
a = str(i)
if len(set(a)) == 1 or len(set(a)) == 2:
cnt += 1
print(cnt-1)
``` | 0 | |
983 | A | Finite or not? | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite if it contains finite number of numerals after the decimal point. It is also possible that... | The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of queries.
Next $n$ lines contain queries, one per line. Each line contains three integers $p$, $q$, and $b$ ($0 \le p \le 10^{18}$, $1 \le q \le 10^{18}$, $2 \le b \le 10^{18}$). All numbers are given in notation with base $10$. | For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. | [
"2\n6 12 10\n4 3 10\n",
"4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n"
] | [
"Finite\nInfinite\n",
"Finite\nFinite\nFinite\nInfinite\n"
] | $\frac{6}{12} = \frac{1}{2} = 0,5_{10}$
$\frac{4}{3} = 1,(3)_{10}$
$\frac{9}{36} = \frac{1}{4} = 0,01_2$
$\frac{4}{12} = \frac{1}{3} = 0,1_3$ | 500 | [
{
"input": "2\n6 12 10\n4 3 10",
"output": "Finite\nInfinite"
},
{
"input": "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4",
"output": "Finite\nFinite\nFinite\nInfinite"
},
{
"input": "10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8 2",
"output": "Finite\nInfinite\nInfini... | 1,526,464,622 | 2,147,483,647 | Python 3 | OK | TESTS | 89 | 639 | 18,022,400 | input()
print('\n'.join(['Infinite' if p * pow(b, 99, q) % q else 'Finite' for p, q, b in map(lambda l: map(int, l.split()), __import__('sys').stdin.readlines())]))
| Title: Finite or not?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ ... | ```python
input()
print('\n'.join(['Infinite' if p * pow(b, 99, q) % q else 'Finite' for p, q, b in map(lambda l: map(int, l.split()), __import__('sys').stdin.readlines())]))
``` | 3 | |
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul... | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{... | 1,687,260,018 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | a = int(input())
b = int(input())
c = int(input())
if(a==1):
if(a+b*c>(a+b)*c):
print(a+b*c)
else:
print((a+b)*c)
elif(b==1 or c ==1):
print(a*(b+c))
else:
print(a*b*c) | Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ... | ```python
a = int(input())
b = int(input())
c = int(input())
if(a==1):
if(a+b*c>(a+b)*c):
print(a+b*c)
else:
print((a+b)*c)
elif(b==1 or c ==1):
print(a*(b+c))
else:
print(a*b*c)
``` | 0 | |
474 | B | Worms | PROGRAMMING | 1,200 | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (... | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the f... | 1,000 | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,677,135,258 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 2,048,000 | def BS(a, n, x):
L, R, ans = 0, n - 1, 0
while L <= R:
M = (L + R) // 2
if a[M] >= x:
ans = M
R = M - 1
else:
L = M + 1
print(ans + 1)
n = int(input())
a = [0] * n
a[0] = int(input())
for i in range(1, n):
x = int(input())
... | Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers:... | ```python
def BS(a, n, x):
L, R, ans = 0, n - 1, 0
while L <= R:
M = (L + R) // 2
if a[M] >= x:
ans = M
R = M - 1
else:
L = M + 1
print(ans + 1)
n = int(input())
a = [0] * n
a[0] = int(input())
for i in range(1, n):
x = int(inpu... | -1 |
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.