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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,529,501,771 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int Y,W,dot;
string pos[7]={" ","1/1","5/6","2/3","1/2","1/3","1/6"};
cin>>Y>>W;
dot=max(Y,W);
cout<<pos[dot]<<endl;
return 0;
}
| 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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int Y,W,dot;
string pos[7]={" ","1/1","5/6","2/3","1/2","1/3","1/6"};
cin>>Y>>W;
dot=max(Y,W);
cout<<pos[dot]<<endl;
return 0;
}
``` | -1 |
176 | B | Word Cut | PROGRAMMING | 1,700 | [
"dp"
] | null | null | Let's consider one interesting word game. In this game you should transform one word into another through special operations.
Let's say we have word *w*, let's split this word into two non-empty parts *x* and *y* so, that *w*<==<=*xy*. A split operation is transforming word *w*<==<=*xy* into word *u*<==<=*yx*. For ex... | The first line contains a non-empty word *start*, the second line contains a non-empty word *end*. The words consist of lowercase Latin letters. The number of letters in word *start* equals the number of letters in word *end* and is at least 2 and doesn't exceed 1000 letters.
The third line contains integer *k* (0<=≤<... | Print a single number — the answer to the problem. As this number can be rather large, print it modulo 1000000007 (109<=+<=7). | [
"ab\nab\n2\n",
"ababab\nababab\n1\n",
"ab\nba\n2\n"
] | [
"1\n",
"2\n",
"0\n"
] | The sought way in the first sample is:
ab → a|b → ba → b|a → ab
In the second sample the two sought ways are:
- ababab → abab|ab → ababab - ababab → ab|abab → ababab | 1,000 | [
{
"input": "ab\nab\n2",
"output": "1"
},
{
"input": "ababab\nababab\n1",
"output": "2"
},
{
"input": "ab\nba\n2",
"output": "0"
},
{
"input": "aaa\naaa\n0",
"output": "1"
},
{
"input": "hi\nhi\n1",
"output": "0"
},
{
"input": "abcd\ncbad\n5",
"outp... | 1,687,312,882 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 90 | 124 | 1,433,600 | s = input()
t = input()
k = int(input())
mod = 10 ** 9 + 7
n = len(s)
status1 = 0
status2 = 0
for i in range(n):
if s[i:] + s[:i] == t: status1 += 1
else: status2 += 1
dp0, dp1 = (0, 1) if s == t else (1, 0)
for _ in range(k):
dp0, dp1 = (dp0 + dp1) * status2 % mod - dp0, (dp0 + dp1) * statu... | Title: Word Cut
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider one interesting word game. In this game you should transform one word into another through special operations.
Let's say we have word *w*, let's split this word into two non-empty parts *x* and *y* so, that *w... | ```python
s = input()
t = input()
k = int(input())
mod = 10 ** 9 + 7
n = len(s)
status1 = 0
status2 = 0
for i in range(n):
if s[i:] + s[:i] == t: status1 += 1
else: status2 += 1
dp0, dp1 = (0, 1) if s == t else (1, 0)
for _ in range(k):
dp0, dp1 = (dp0 + dp1) * status2 % mod - dp0, (dp0 + dp... | 3 | |
845 | A | Chess Tourney | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizer... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100).
The second line contains 2·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≤<=*a**i*<=≤<=1000). | If it's possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | [
"2\n1 3 2 4\n",
"1\n3 3\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2\n1 3 2 4",
"output": "YES"
},
{
"input": "1\n3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 2 2 3 3 3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1 2 2 2 2 2",
"output": "YES"
},
{
"input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000... | 1,515,482,050 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 5,632,000 | #http://codeforces.com/problemset/problem/845/A
n = int(input())
players = list(map(int, input().split()))
ans = 0
for x in range(n):
big = max(players)
ans += big
players.remove(big)
print("YES" if ans > sum(players) else "NO") | Title: Chess Tourney
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by... | ```python
#http://codeforces.com/problemset/problem/845/A
n = int(input())
players = list(map(int, input().split()))
ans = 0
for x in range(n):
big = max(players)
ans += big
players.remove(big)
print("YES" if ans > sum(players) else "NO")
``` | 0 | |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow... | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output... | 1,694,715,024 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 7 | 1,466 | 268,390,400 | n,k=map(int,input().split())
l=[]
l1=[]
for i in range(1,n+1):
if i%2==0:
l.append(i)
else:
l1.append(i)
l2=l1+l
print(l2[k-1]) | Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ... | ```python
n,k=map(int,input().split())
l=[]
l1=[]
for i in range(1,n+1):
if i%2==0:
l.append(i)
else:
l1.append(i)
l2=l1+l
print(l2[k-1])
``` | 0 | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,697,722,457 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 62 | 1,433,600 | x = int(input())
c = 0
for i in range(x):
if (x - 5) > 0:
c += 1
x -= 5
elif (x-4) > 0:
c += 1
x -= 4
elif (x-3) > 0:
c += 1
x -= 3
elif (x-2) > 0:
c += 1
x -= 2
elif (x-1) > 0:
c += 1
x -= 1
print(c) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
x = int(input())
c = 0
for i in range(x):
if (x - 5) > 0:
c += 1
x -= 5
elif (x-4) > 0:
c += 1
x -= 4
elif (x-3) > 0:
c += 1
x -= 3
elif (x-2) > 0:
c += 1
x -= 2
elif (x-1) > 0:
c += 1
x -= 1
print(c)
``` | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,622,699,476 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 184 | 0 | s=input()
if s[0]==s[0].lower():
print(s.lower())
else:
r=s.upper()
print(r) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=input()
if s[0]==s[0].lower():
print(s.lower())
else:
r=s.upper()
print(r)
``` | 0 |
115 | B | Lawnmower | PROGRAMMING | 1,500 | [
"greedy",
"sortings"
] | null | null | You have a garden consisting entirely of grass and weeds. Your garden is described by an *n*<=×<=*m* grid, with rows numbered 1 to *n* from top to bottom, and columns 1 to *m* from left to right. Each cell is identified by a pair (*r*,<=*c*) which means that the cell is located at row *r* and column *c*. Each cell may ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=150) — the number of rows and columns respectively. Then follow *n* lines containing *m* characters each — the content of the grid. "G" means that this cell contains grass. "W" means that this cell contains weeds.
It is guaranteed that the top-left... | Print a single number — the minimum number of moves required to mow all the weeds. | [
"4 5\nGWGGW\nGGWGG\nGWGGG\nWGGGG\n",
"3 3\nGWW\nWWW\nWWG\n",
"1 1\nG\n"
] | [
"11\n",
"7\n",
"0\n"
] | For the first example, this is the picture of the initial state of the grid:
A possible solution is by mowing the weeds as illustrated below: | 1,000 | [
{
"input": "4 5\nGWGGW\nGGWGG\nGWGGG\nWGGGG",
"output": "11"
},
{
"input": "3 3\nGWW\nWWW\nWWG",
"output": "7"
},
{
"input": "1 1\nG",
"output": "0"
},
{
"input": "4 3\nGWW\nWWW\nWWW\nWWG",
"output": "11"
},
{
"input": "6 5\nGWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWW... | 1,665,648,164 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 77 | 0 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
g = [input()[:-1] for _ in range(n)]
x, c, w, i, e = 0, 0, 0, 0, 0
while i < n:
if 'W' in g[i]:
c += e
e = 0
b = 1
while i + b < n and 'W' not in g[i + b]:
b += 1
if i + b == n:
... | Title: Lawnmower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a garden consisting entirely of grass and weeds. Your garden is described by an *n*<=×<=*m* grid, with rows numbered 1 to *n* from top to bottom, and columns 1 to *m* from left to right. Each cell is identified by a ... | ```python
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
g = [input()[:-1] for _ in range(n)]
x, c, w, i, e = 0, 0, 0, 0, 0
while i < n:
if 'W' in g[i]:
c += e
e = 0
b = 1
while i + b < n and 'W' not in g[i + b]:
b += 1
if i +... | 0 | |
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor... | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input"... | 1,653,196,100 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 62 | 0 | x1=int(input())
l1=[]
for i in range(x1):
a1=input()
l1.append(a1)
print(len(set(l1)))
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the specie... | ```python
x1=int(input())
l1=[]
for i in range(x1):
a1=input()
l1.append(a1)
print(len(set(l1)))
``` | 3.9845 |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,695,467,260 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=input()
x=len(n)
s=n[2:len(n+1)]
for i in range(0,x):
if(65<=ord[s[i]]<=90):
return 1 | Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
n=input()
x=len(n)
s=n[2:len(n+1)]
for i in range(0,x):
if(65<=ord[s[i]]<=90):
return 1
``` | -1 | |
721 | C | Journey | PROGRAMMING | 1,800 | [
"dp",
"graphs"
] | null | null | Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially I... | The first line of the input contains three integers *n*,<=*m* and *T* (2<=≤<=*n*<=≤<=5000,<=<=1<=≤<=*m*<=≤<=5000,<=<=1<=≤<=*T*<=≤<=109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next *m* lines describes roads in Berlatov. *i*-th of them cont... | Print the single integer *k* (2<=≤<=*k*<=≤<=*n*) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace *n* within time not exceeding *T*, in the first line.
Print *k* distinct integers in the second line — indices of showplaces that Irina will visit on her route, in t... | [
"4 3 13\n1 2 5\n2 3 7\n2 4 8\n",
"6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n",
"5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n"
] | [
"3\n1 2 4 \n",
"4\n1 2 4 6 \n",
"3\n1 3 5 \n"
] | none | 1,500 | [
{
"input": "4 3 13\n1 2 5\n2 3 7\n2 4 8",
"output": "3\n1 2 4 "
},
{
"input": "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1",
"output": "4\n1 2 4 6 "
},
{
"input": "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2",
"output": "3\n1 3 5 "
},
{
"input": "10 10 100\n1 4 1\n6 4 1\n9 3... | 1,580,622,126 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 7 | 404 | 21,094,400 | # -*- coding:utf-8 -*-
"""
created by shuangquan.huang at 1/20/20
"""
import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
def dfs(curr, maxtime, graph, path):
if maxtime < 0:
return []
if curr == 1:
return path
ans = path
... | Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlato... | ```python
# -*- coding:utf-8 -*-
"""
created by shuangquan.huang at 1/20/20
"""
import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
def dfs(curr, maxtime, graph, path):
if maxtime < 0:
return []
if curr == 1:
return path
ans... | -1 | |
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors... | In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ... | In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReal... | 1,581,996,085 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | n=int(input())
A=set()
B={'purple':'Power',
'green':'Time',
'blue':'Space',
'orange':'Soul',
'red':'Realyty',
'yellow':'Mind'}
C={'Power',
'Time',
'Space',
'Soul',
'Realyty',
'Mind'}
for i in range(n):
A.add(input())
D=set()
for i in A:
D.add(B[i])
E=C-D
print(6... | Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So... | ```python
n=int(input())
A=set()
B={'purple':'Power',
'green':'Time',
'blue':'Space',
'orange':'Soul',
'red':'Realyty',
'yellow':'Mind'}
C={'Power',
'Time',
'Space',
'Soul',
'Realyty',
'Mind'}
for i in range(n):
A.add(input())
D=set()
for i in A:
D.add(B[i])
E=C-... | 0 | |
505 | B | Mr. Kitayuta's Colorful Graph | PROGRAMMING | 1,400 | [
"dfs and similar",
"dp",
"dsu",
"graphs"
] | null | null | Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*.
Mr. Kitayuta wants you to process the following *q* queries.
In the *i*-th query, he giv... | The first line of the input contains space-separated two integers — *n* and *m* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100), denoting the number of the vertices and the number of the edges, respectively.
The next *m* lines contain space-separated three integers — *a**i*, *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*) and *c*... | For each query, print the answer in a separate line. | [
"4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n",
"5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n"
] | [
"2\n1\n0\n",
"1\n1\n1\n1\n2\n"
] | Let's consider the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color. | 1,000 | [
{
"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4",
"output": "2\n1\n0"
},
{
"input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4",
"output": "1\n1\n1\n1\n2"
},
{
"input": "2 1\n1 2 1\n1\n1 2",
"output": "1"
},
{
"input... | 1,549,889,234 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 217 | 0 | # main
used = []
def dfs(p, t, c):
if p == t:
return True
if used[p]:
return False
used[p] = True
for ch in adj[p]:
if ch[1] == c and not (used[ch[0]]) and dfs(ch[0], t, ch[1]):
return True
return False
n, m = map(int, input().split())
adj = [... | Title: Mr. Kitayuta's Colorful Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting v... | ```python
# main
used = []
def dfs(p, t, c):
if p == t:
return True
if used[p]:
return False
used[p] = True
for ch in adj[p]:
if ch[1] == c and not (used[ch[0]]) and dfs(ch[0], t, ch[1]):
return True
return False
n, m = map(int, input().split()... | 3 | |
106 | A | Card Game | PROGRAMMING | 1,000 | [
"implementation"
] | A. Card Game | 2 | 256 | There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want.
To play durak you need a pack of 36 cards. Each card has a suit ("S", "H", ... | The first line contains the tramp suit. It is "S", "H", "D" or "C".
The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank ("6", "7", "8", "9", "T", "J", "Q", "K" and "A"), and the second one stands for the... | Print "YES" (without the quotes) if the first cards beats the second one. Otherwise, print "NO" (also without the quotes). | [
"H\nQH 9S\n",
"S\n8D 6D\n",
"C\n7H AS\n"
] | [
"YES\n",
"YES",
"NO"
] | none | 500 | [
{
"input": "H\nQH 9S",
"output": "YES"
},
{
"input": "S\n8D 6D",
"output": "YES"
},
{
"input": "C\n7H AS",
"output": "NO"
},
{
"input": "C\nKC 9C",
"output": "YES"
},
{
"input": "D\n7D KD",
"output": "NO"
},
{
"input": "H\n7H KD",
"output": "YES"
... | 1,683,303,370 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 78 | 154 | 0 | weight = '6789TJQKA'
trump_card = input()
card_1, card_2 = input().split()
if card_1[1] == card_2[1]:
print('YES' if weight.index(card_1[0]) > weight.index(card_2[0]) else 'NO')
else:
print('YES' if card_1[1] == trump_card != card_2[1] else 'NO')
| Title: Card Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselve... | ```python
weight = '6789TJQKA'
trump_card = input()
card_1, card_2 = input().split()
if card_1[1] == card_2[1]:
print('YES' if weight.index(card_1[0]) > weight.index(card_2[0]) else 'NO')
else:
print('YES' if card_1[1] == trump_card != card_2[1] else 'NO')
``` | 3.9615 |
476 | B | Dreamoon and WiFi | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"combinatorics",
"dp",
"math",
"probabilities"
] | null | null | Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, de... | The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes ... | Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9. | [
"++-+-\n+-+-+\n",
"+-+-\n+-??\n",
"+++\n??-\n"
] | [
"1.000000000000\n",
"0.500000000000\n",
"0.000000000000\n"
] | For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position + 1.
For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="low... | 1,500 | [
{
"input": "++-+-\n+-+-+",
"output": "1.000000000000"
},
{
"input": "+-+-\n+-??",
"output": "0.500000000000"
},
{
"input": "+++\n??-",
"output": "0.000000000000"
},
{
"input": "++++++++++\n+++??++?++",
"output": "0.125000000000"
},
{
"input": "--+++---+-\n????????... | 1,688,715,182 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 77 | 1,945,600 |
from sys import stdin
def get_input():
# Faster IO
return stdin.read().strip().split('\n')
def get_prob(s1, s2):
n = len(s1)
if n == 0:
return 1
end = sum(-1 if sign == '-' else 1 for sign in s1)
# print(end)
res = [0, 0]
def rec(i, pos):
if i == n:
... | Title: Dreamoon and WiFi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go... | ```python
from sys import stdin
def get_input():
# Faster IO
return stdin.read().strip().split('\n')
def get_prob(s1, s2):
n = len(s1)
if n == 0:
return 1
end = sum(-1 if sign == '-' else 1 for sign in s1)
# print(end)
res = [0, 0]
def rec(i, pos):
i... | 3 | |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara... | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ... | 1,665,338,367 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 62 | 3,072,000 | n, t = map(int, input().split())
data = input().split()
i = 1
c = 0
while i <= n-1:
i += int(data[i-1])
if i > t:
print('NO')
break
if i == t:
print('YES')
c += 1
break
| Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o... | ```python
n, t = map(int, input().split())
data = input().split()
i = 1
c = 0
while i <= n-1:
i += int(data[i-1])
if i > t:
print('NO')
break
if i == t:
print('YES')
c += 1
break
``` | 3 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,621,353,189 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 186 | 307,200 | from collections import defaultdict
n = int(input())
name_to_score = defaultdict(int)
score_to_name = defaultdict(list)
max_score = float('-inf')
for _ in range(n):
name, score = input().split()
score = int(score)
name_to_score[name] += score
score_to_name[name_to_score[name]].append(name)
... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
from collections import defaultdict
n = int(input())
name_to_score = defaultdict(int)
score_to_name = defaultdict(list)
max_score = float('-inf')
for _ in range(n):
name, score = input().split()
score = int(score)
name_to_score[name] += score
score_to_name[name_to_score[name]].appen... | 0 |
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He lik... | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
... | 1,646,244,180 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 512,000 | given = [x for x in range(1, int(input()) + 1)]
lens = len(given)
if lens % 2 == 1:
print(-1)
else:
answer = []
lens = len(given)
i = 1
while i < lens:
answer.extend([i+1, i])
i += 2
print(*answer)
| Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ... | ```python
given = [x for x in range(1, int(input()) + 1)]
lens = len(given)
if lens % 2 == 1:
print(-1)
else:
answer = []
lens = len(given)
i = 1
while i < lens:
answer.extend([i+1, i])
i += 2
print(*answer)
``` | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,636,987,458 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 61 | 0 |
print (*(int(i!=x) for i,x in zip(input(),input())),sep='') | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
print (*(int(i!=x) for i,x in zip(input(),input())),sep='')
``` | 3.98475 |
109 | A | Lucky Sum of Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | A. Lucky Sum of Digits | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. | Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. | [
"11\n",
"10\n"
] | [
"47\n",
"-1\n"
] | none | 500 | [
{
"input": "11",
"output": "47"
},
{
"input": "10",
"output": "-1"
},
{
"input": "64",
"output": "4477777777"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "7"
},
{
"input": "12",
"outpu... | 1,584,541,653 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 124 | 307,200 | # coding:utf-8
n = int(input())
result = ''
def calcSeven(max):
result = ''
for i in range(max):
result += '7'
return result
def calcFour(max):
result = ''
for i in range(max):
result += '4'
return result
if(n % 7 == 0):
result += calcSeven(int(n/7))
elif(n % 4 == 0):
... | Title: Lucky Sum of Digits
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
# coding:utf-8
n = int(input())
result = ''
def calcSeven(max):
result = ''
for i in range(max):
result += '7'
return result
def calcFour(max):
result = ''
for i in range(max):
result += '4'
return result
if(n % 7 == 0):
result += calcSeven(int(n/7))
elif(n % 4... | 0 |
493 | E | Vasya and Polynomial | PROGRAMMING | 2,800 | [
"math"
] | null | null | Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function *P*(*x*)<==<=*a*0<=+<=*a*1*x*1<=+<=...<=+<=*a**n**x**n*. Numbers *a**i* are called coefficients of a polynomial, non-negative integer *n* is called a degree of a polynomial.
Vasya has ma... | The input contains three integer positive numbers no greater than 1018. | If there is an infinite number of such polynomials, then print "inf" without quotes, otherwise print the reminder of an answer modulo 109<=+<=7. | [
"2 2 2\n",
"2 3 3\n"
] | [
"2\n",
"1\n"
] | none | 3,000 | [
{
"input": "2 2 2",
"output": "2"
},
{
"input": "2 3 3",
"output": "1"
},
{
"input": "1 1 1",
"output": "inf"
},
{
"input": "3 5 10",
"output": "0"
},
{
"input": "2 3 1000000000000000000",
"output": "0"
},
{
"input": "7 8 9",
"output": "1"
},
{... | 1,531,291,308 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | t,a,b=list(map(int,input().split()))
if (t,a)==(a,b):
print(2)
elif t==a:
print(0)
else:
#two distinct points
"""
(t,a) (a,b) (b-a)/(a-t) is the slope is not an integer ==>
we are cannot have a straight line between them
"""
if abs(b-a)%abs(a-t)==0 and (b-a)//(a-t)>0:
... | Title: Vasya and Polynomial
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function *P*(*x*)<==<=*a*0<=+<=*a*1*x*1<=+<=...<=+<=*a**n**x**n*. Numbers *a**i* are calle... | ```python
t,a,b=list(map(int,input().split()))
if (t,a)==(a,b):
print(2)
elif t==a:
print(0)
else:
#two distinct points
"""
(t,a) (a,b) (b-a)/(a-t) is the slope is not an integer ==>
we are cannot have a straight line between them
"""
if abs(b-a)%abs(a-t)==0 and (b-a)//(a-t)>0... | 0 | |
722 | C | Destroying Array | PROGRAMMING | 1,600 | [
"data structures",
"dsu"
] | null | null | You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defining the order elements of the array are destroyed.
After each element is destroyed you have to find o... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
The third line contains a permutation of integers from 1 to *n* — the order used to destroy elements. | Print *n* lines. The *i*-th line should contain a single integer — the maximum possible sum of elements on the segment containing no destroyed elements, after first *i* operations are performed. | [
"4\n1 3 2 5\n3 4 1 2\n",
"5\n1 2 3 4 5\n4 2 3 5 1\n",
"8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n"
] | [
"5\n4\n3\n0\n",
"6\n5\n5\n1\n0\n",
"18\n16\n11\n8\n8\n6\n6\n0\n"
] | Consider the first sample:
1. Third element is destroyed. Array is now 1 3 * 5. Segment with maximum sum 5 consists of one integer 5. 1. Fourth element is destroyed. Array is now 1 3 * * . Segment with maximum sum 4 consists of two integers 1 3. 1. First element is destroyed. Array is now * 3 * * . Segme... | 1,000 | [
{
"input": "4\n1 3 2 5\n3 4 1 2",
"output": "5\n4\n3\n0"
},
{
"input": "5\n1 2 3 4 5\n4 2 3 5 1",
"output": "6\n5\n5\n1\n0"
},
{
"input": "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6",
"output": "18\n16\n11\n8\n8\n6\n6\n0"
},
{
"input": "10\n3 3 3 5 6 9 3 1 7 3\n3 4 6 7 5 1 10 9 2 8"... | 1,588,700,092 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 14 | 1,000 | 20,992,000 | import bisect
import heapq as hq
class LeastFinder(object):
def __init__(self, ns):
self.partial_sums = []
for i, n in enumerate(ns):
if i == 0:
self.partial_sums.append(n)
else:
self.partial_sums.append(self.partial_sums[i-1] + n)
sel... | Title: Destroying Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defin... | ```python
import bisect
import heapq as hq
class LeastFinder(object):
def __init__(self, ns):
self.partial_sums = []
for i, n in enumerate(ns):
if i == 0:
self.partial_sums.append(n)
else:
self.partial_sums.append(self.partial_sums[i-1] + n)
... | 0 | |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
... | 1,665,656,497 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | x = input()
enk = int(x)
yreq = 0
for d in range(len(x)):
if (d == 0 and x[d] == '9'):
pass
else:
yreq = int(x[0:d] + str(9 - int(x[d])) + x[d:-1])
if yreq < enk:
x = x[0:d] + (str(9 - int(x[d]))) + x[d:-1]
enk = yreq
print(enk) | Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform... | ```python
x = input()
enk = int(x)
yreq = 0
for d in range(len(x)):
if (d == 0 and x[d] == '9'):
pass
else:
yreq = int(x[0:d] + str(9 - int(x[d])) + x[d:-1])
if yreq < enk:
x = x[0:d] + (str(9 - int(x[d]))) + x[d:-1]
enk = yreq
print(enk)
``` | 0 | |
361 | A | Levko and Table | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them. | [
"2 4\n",
"4 7\n"
] | [
"1 3\n3 1\n",
"2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n"
] | In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other table... | 500 | [
{
"input": "2 4",
"output": "4 0 \n0 4 "
},
{
"input": "4 7",
"output": "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 "
},
{
"input": "1 8",
"output": "8 "
},
{
"input": "9 3",
"output": "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0... | 1,598,018,389 | 2,147,483,647 | PyPy 3 | OK | TESTS | 22 | 156 | 22,630,400 | def rotate(c,d):
return c[d:]+c[:d]
n,m = map(int,input().split())
c = []
if(m%n == 0):
c = [m//n]*n
else:
c = [m//n]*(n-1)
c.append(m-sum(c))
p = []
for i in range(n):
p.append(rotate(c,i))
for i in p:
print(*i) | Title: Levko and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortun... | ```python
def rotate(c,d):
return c[d:]+c[:d]
n,m = map(int,input().split())
c = []
if(m%n == 0):
c = [m//n]*n
else:
c = [m//n]*(n-1)
c.append(m-sum(c))
p = []
for i in range(n):
p.append(rotate(c,i))
for i in p:
print(*i)
``` | 3 | |
250 | B | Restoring IPv6 | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer *n* — the number of records to restore (1<=≤<=*n*<=≤<=100).
Each of the following *n* lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | [
"6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n"
] | [
"a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000\n"
] | none | 1,000 | [
{
"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0",
"output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000... | 1,659,288,987 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | # coding=utf8
cnt = input()
for k in range(int(cnt)):
ip = input()
if ip == "":
print("0000:0000:0000:0000:0000:0000:0000:0000")
continue
ip = ip.split(":")
ret = ""
# 扩::
if ip[0] == "":
ip = ["0000"] * (8 - len(ip) + 2) + ip[2:]
elif ip[-1] == "":
ip = ip[:-... | Title: Restoring IPv6
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. He... | ```python
# coding=utf8
cnt = input()
for k in range(int(cnt)):
ip = input()
if ip == "":
print("0000:0000:0000:0000:0000:0000:0000:0000")
continue
ip = ip.split(":")
ret = ""
# 扩::
if ip[0] == "":
ip = ["0000"] * (8 - len(ip) + 2) + ip[2:]
elif ip[-1] == "":
... | 3 | |
859 | B | Lazy Security Guard | PROGRAMMING | 1,000 | [
"brute force",
"geometry",
"math"
] | null | null | Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly *N* blocks. Your friend is quite ... | Input will consist of a single integer *N* (1<=≤<=*N*<=≤<=106), the number of city blocks that must be enclosed by the route. | Print the minimum perimeter that can be achieved. | [
"4\n",
"11\n",
"22\n"
] | [
"8\n",
"14\n",
"20\n"
] | Here are some possible shapes for the examples:
<img class="tex-graphics" src="https://espresso.codeforces.com/e11bef2cf82b55dd583cfc97d12b5aee5e483a65.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 750 | [
{
"input": "4",
"output": "8"
},
{
"input": "11",
"output": "14"
},
{
"input": "22",
"output": "20"
},
{
"input": "3",
"output": "8"
},
{
"input": "1024",
"output": "128"
},
{
"input": "101",
"output": "42"
},
{
"input": "30",
"output":... | 1,559,754,483 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 109 | 0 | from math import ceil
x = int(input())
t = x**(1/2)
if int(t)*ceil(t) >= x:
print((int(t)+ceil(t))*2)
else:
print(ceil(t)*4)
| Title: Lazy Security Guard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is... | ```python
from math import ceil
x = int(input())
t = x**(1/2)
if int(t)*ceil(t) >= x:
print((int(t)+ceil(t))*2)
else:
print(ceil(t)*4)
``` | 3 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,698,594,826 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 15 | 0 | knw = input().split()
k = eval(knw[0])
n = eval(knw[1])
w = eval(knw[2])
nw = 0
wfk = 0
while nw != w:
nw = nw + 1
wfk = wfk + nw*k
print(wfk - n) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
knw = input().split()
k = eval(knw[0])
n = eval(knw[1])
w = eval(knw[2])
nw = 0
wfk = 0
while nw != w:
nw = nw + 1
wfk = wfk + nw*k
print(wfk - n)
``` | 0 | |
234 | G | Practice | PROGRAMMING | 1,600 | [
"constructive algorithms",
"divide and conquer",
"implementation"
] | null | null | Little time is left before Berland annual football championship. Therefore the coach of team "Losewille Rangers" decided to resume the practice, that were indefinitely interrupted for uncertain reasons. Overall there are *n* players in "Losewille Rangers". Each player on the team has a number — a unique integer from 1 ... | A single input line contains integer *n* (2<=≤<=*n*<=≤<=1000). | In the first line print *m* — the minimum number of practices the coach will have to schedule. Then print the descriptions of the practices in *m* lines.
In the *i*-th of those lines print *f**i* — the number of players in the first team during the *i*-th practice (1<=≤<=*f**i*<=<<=*n*), and *f**i* numbers from 1 t... | [
"2\n",
"3\n"
] | [
"1\n1 1\n",
"2\n2 1 2\n1 1\n"
] | none | 0 | [
{
"input": "2",
"output": "1\n1 1"
},
{
"input": "3",
"output": "2\n2 1 2\n1 1"
},
{
"input": "4",
"output": "2\n2 1 2\n2 1 3"
},
{
"input": "5",
"output": "3\n3 1 2 3\n3 1 2 4\n1 1"
},
{
"input": "6",
"output": "3\n3 1 2 3\n4 1 2 4 5\n2 1 4"
},
{
"inp... | 1,679,020,212 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = int(input())
m = n if n % 2 == 1 else n - 1 # number of exercises needed
print(m)
for i in range(1, n // 2 + 1):
print(2, i, n-i+1)
if n % 2 == 1:
print(1, n)
| Title: Practice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little time is left before Berland annual football championship. Therefore the coach of team "Losewille Rangers" decided to resume the practice, that were indefinitely interrupted for uncertain reasons. Overall there are *n* p... | ```python
n = int(input())
m = n if n % 2 == 1 else n - 1 # number of exercises needed
print(m)
for i in range(1, n // 2 + 1):
print(2, i, n-i+1)
if n % 2 == 1:
print(1, n)
``` | -1 | |
914 | B | Conan and Agasa play a Card Game | PROGRAMMING | 1,200 | [
"games",
"greedy",
"implementation"
] | null | null | Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has *n* cards, and the *i*-th card has a number *a**i* written on it.
They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he remov... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of cards Conan has.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105), where *a**i* is the number on the *i*-th card. | If Conan wins, print "Conan" (without quotes), otherwise print "Agasa" (without quotes). | [
"3\n4 5 7\n",
"2\n1 1\n"
] | [
"Conan\n",
"Agasa\n"
] | In the first example, Conan can just choose the card having number 7 on it and hence remove all the cards. After that, there are no cards left on Agasa's turn.
In the second example, no matter which card Conan chooses, there will be one one card left, which Agasa can choose. After that, there are no cards left when it... | 1,000 | [
{
"input": "3\n4 5 7",
"output": "Conan"
},
{
"input": "2\n1 1",
"output": "Agasa"
},
{
"input": "10\n38282 53699 38282 38282 38282 38282 38282 38282 38282 38282",
"output": "Conan"
},
{
"input": "10\n50165 50165 50165 50165 50165 50165 50165 50165 50165 50165",
"output":... | 1,538,127,584 | 2,147,483,647 | Python 3 | OK | TESTS | 91 | 233 | 8,294,400 | n = int(input())
s = [int(i) for i in input().split()]
s.sort()
dic = {}
for x in s:
if x not in dic:
dic[x]=1
else:
dic[x]+=1
for x in dic:
if dic[x]%2==1:
print("Conan")
exit()
print("Agasa")
# def f(n,k,ls):
# print(ls,type(n),k)
# if k==0 and (n=="" or n==None):
# return ls
# e... | Title: Conan and Agasa play a Card Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has *n* cards, and the *i*-th card has a number *a**i* written on it.... | ```python
n = int(input())
s = [int(i) for i in input().split()]
s.sort()
dic = {}
for x in s:
if x not in dic:
dic[x]=1
else:
dic[x]+=1
for x in dic:
if dic[x]%2==1:
print("Conan")
exit()
print("Agasa")
# def f(n,k,ls):
# print(ls,type(n),k)
# if k==0 and (n=="" or n==None):
# retur... | 3 | |
313 | B | Ilya and Queries | PROGRAMMING | 1,100 | [
"dp",
"implementation"
] | null | null | Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<... | The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-t... | Print *m* integers — the answers to the queries in the order in which they are given in the input. | [
"......\n4\n3 4\n2 3\n1 6\n2 6\n",
"#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n"
] | [
"1\n1\n5\n4\n",
"1\n1\n2\n2\n0\n"
] | none | 1,000 | [
{
"input": "......\n4\n3 4\n2 3\n1 6\n2 6",
"output": "1\n1\n5\n4"
},
{
"input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4",
"output": "1\n1\n2\n2\n0"
},
{
"input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3",
"output": "2\n0\n0\n1\n2\n0"
},
{
"input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5... | 1,698,140,890 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 9,830,400 | s = input()
d = []
for i in range(len(s) - 1):
d.append(s[i] == s[i+1])
m = int(input())
for i in range(m):
a,b = map(int, input().split())
print(d[a-1:b-1].count(True)) | Title: Ilya and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting ... | ```python
s = input()
d = []
for i in range(len(s) - 1):
d.append(s[i] == s[i+1])
m = int(input())
for i in range(m):
a,b = map(int, input().split())
print(d[a-1:b-1].count(True))
``` | 0 | |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,667,838,867 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 1,076 | 8,704,000 | R = lambda: map(int, input().split())
L = lambda: list(R())
n,=R()
l = L()
q,=R()
sl=sorted(l)
for i in range(1,n) :
l[i]+=l[i-1]
for i in range(1,n) :
sl[i]+=sl[i-1]
for i in range(q):
t,left,right = R()
if left != 1 :
if t == 1 :print(l[right-1]-l[left-2])
else :print(s... | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
R = lambda: map(int, input().split())
L = lambda: list(R())
n,=R()
l = L()
q,=R()
sl=sorted(l)
for i in range(1,n) :
l[i]+=l[i-1]
for i in range(1,n) :
sl[i]+=sl[i-1]
for i in range(q):
t,left,right = R()
if left != 1 :
if t == 1 :print(l[right-1]-l[left-2])
els... | 3 | |
918 | A | Eleven | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the ... | The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | 500 | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooo... | 1,561,532,995 | 2,147,483,647 | PyPy 3 | OK | TESTS | 18 | 124 | 0 | a=0
b=1
c=1
arr=[c]
n=input()
n=int(n)
s=""
while c<=n:
c=a+b
a=b
b=c
arr.append(c)
for i in range(1,n+1):
if i in arr:
s+="O"
else:
s+="o"
print(s) | Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should o... | ```python
a=0
b=1
c=1
arr=[c]
n=input()
n=int(n)
s=""
while c<=n:
c=a+b
a=b
b=c
arr.append(c)
for i in range(1,n+1):
if i in arr:
s+="O"
else:
s+="o"
print(s)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 0 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,469,121,342 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | n = int(input())
a = [int(i) for i in input().split()]
c = 0
if a[-1] != 0:
if a[-2] == 0 or a[-2] == 3:
c +=1
a[-1] = 2
for i in range(n-2, -1, -1):
if a[i] != 0:
if a[i] == 1:
if a[i+1] == 1:
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet... | ```python
n = int(input())
a = [int(i) for i in input().split()]
c = 0
if a[-1] != 0:
if a[-2] == 0 or a[-2] == 3:
c +=1
a[-1] = 2
for i in range(n-2, -1, -1):
if a[i] != 0:
if a[i] == 1:
if a[i+1] == 1:
... | 0 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,678,694,940 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 9 | 92 | 0 | t=int(input())
d=dict()
l=list()
m=list()
max=-999999999999999999
for i in range(t):
name,score=map(str,input().split())
if name not in d:
d[name]=int(score)
if int(score)>max:
m.clear()
m.append(name)
max=int(score)
elif int(score)==max:
... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
t=int(input())
d=dict()
l=list()
m=list()
max=-999999999999999999
for i in range(t):
name,score=map(str,input().split())
if name not in d:
d[name]=int(score)
if int(score)>max:
m.clear()
m.append(name)
max=int(score)
elif int(sco... | 0 |
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, al... | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": ... | 1,664,028,007 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 46 | 0 | n = int(input())
n = n % 100
if n % 100 == 0:
print((1378**100) % 10)
else: print((1378**n) % 10) | Title: Arpa’s hard exam and Mehrdad’s naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques... | ```python
n = int(input())
n = n % 100
if n % 100 == 0:
print((1378**100) % 10)
else: print((1378**n) % 10)
``` | 0 | |
246 | A | Buggy Sorting | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a**n* in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. ... | You've got a single integer *n* (1<=≤<=*n*<=≤<=50) — the size of the sorted array. | Print *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the counter-example, for which Valera's algorithm won't work correctly. If the counter-example that meets the described conditions is impossible to give, print -1.
If there are several counter-examples, consisting of *n* numbers, yo... | [
"1\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "3 2 1 "
},
{
"input": "4",
"output": "4 3 2 1 "
},
{
"input": "5",
"output": "5 4 3 2 1 "
},
{
"input": "6",
"output": "6 5 4 3 2 1 "
},
{
"input... | 1,588,190,586 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 108 | 0 | n = int(input())
res = ""
if n<3:
print(-1)
else:
for u in range(-n,0):
res = res + "{} ".format(-u)
print(res[:-1])
| Title: Buggy Sorting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a*... | ```python
n = int(input())
res = ""
if n<3:
print(-1)
else:
for u in range(-n,0):
res = res + "{} ".format(-u)
print(res[:-1])
``` | 3 | |
275 | B | Convex Shape | PROGRAMMING | 1,700 | [
"constructive algorithms",
"implementation"
] | null | null | Consider an *n*<=×<=*m* grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the size of the grid. Each of the next *n* lines contains *m* characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid.
It's guaranteed that the grid has at least one black cel... | On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. | [
"3 4\nWWBW\nBWWW\nWWWB\n",
"3 1\nB\nB\nW\n"
] | [
"NO\n",
"YES\n"
] | none | 1,000 | [
{
"input": "3 4\nWWBW\nBWWW\nWWWB",
"output": "NO"
},
{
"input": "3 1\nB\nB\nW",
"output": "YES"
},
{
"input": "1 1\nB",
"output": "YES"
},
{
"input": "1 2\nBB",
"output": "YES"
},
{
"input": "2 1\nB\nB",
"output": "YES"
},
{
"input": "1 2\nBW",
"o... | 1,640,359,848 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 26 | 2,000 | 11,673,600 | import sys
def readline():
return sys.stdin.readline().strip()
def read(t=int):
s = sys.stdin.readline()
return list(map(t, s.strip().split(' ')))
def readint():
return read()[0]
def go():
n, m = read()
g = []
totalblack = 0
for i in range(n):
s = readline()
g += ... | Title: Convex Shape
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider an *n*<=×<=*m* grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any anothe... | ```python
import sys
def readline():
return sys.stdin.readline().strip()
def read(t=int):
s = sys.stdin.readline()
return list(map(t, s.strip().split(' ')))
def readint():
return read()[0]
def go():
n, m = read()
g = []
totalblack = 0
for i in range(n):
s = readline()
... | 0 | |
508 | B | Anton and currency you all know | PROGRAMMING | 1,300 | [
"greedy",
"math",
"strings"
] | null | null | Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have informed the financier Anton of some information about the exchange rate of... | The first line contains an odd positive integer *n* — the exchange rate of currency you all know for today. The length of number *n*'s representation is within range from 2 to 105, inclusive. The representation of *n* doesn't contain any leading zeroes. | If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print <=-<=1.
Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained fro... | [
"527\n",
"4573\n",
"1357997531\n"
] | [
"572\n",
"3574\n",
"-1\n"
] | none | 1,000 | [
{
"input": "527",
"output": "572"
},
{
"input": "4573",
"output": "3574"
},
{
"input": "1357997531",
"output": "-1"
},
{
"input": "444443",
"output": "444434"
},
{
"input": "22227",
"output": "72222"
},
{
"input": "24683",
"output": "34682"
},
... | 1,641,036,982 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 78 | 0 | a=input()
j=-1
for i in range(len(a)-2,-1,-1):
if(int(a[i])%2==0 and (j==-1 or a[j]>a[i])):
j=i
if(j==-1):
print(-1)
else:
print(a[:j]+a[-1]+a[j+1:len(a)-1]+a[j]) | Title: Anton and currency you all know
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed... | ```python
a=input()
j=-1
for i in range(len(a)-2,-1,-1):
if(int(a[i])%2==0 and (j==-1 or a[j]>a[i])):
j=i
if(j==-1):
print(-1)
else:
print(a[:j]+a[-1]+a[j+1:len(a)-1]+a[j])
``` | 0 | |
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,697,642,415 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 46 | 0 | n,t = map(int, input().split(' '))
total_time = 0
h_time = 240-t
result = 0
for i in range(n+1):
n_time = 5
n_time*=i
total_time+=n_time
if total_time>h_time:
pass
else:
result = i
print(result)
| 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
n,t = map(int, input().split(' '))
total_time = 0
h_time = 240-t
result = 0
for i in range(n+1):
n_time = 5
n_time*=i
total_time+=n_time
if total_time>h_time:
pass
else:
result = i
print(result)
``` | 3 | |
408 | A | Line to Cashier | PROGRAMMING | 900 | [
"implementation"
] | null | null | Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i*... | Print a single integer — the minimum number of seconds Vasya needs to get to the cashier. | [
"1\n1\n1\n",
"4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n"
] | [
"20\n",
"100\n"
] | In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou... | 500 | [
{
"input": "1\n1\n1",
"output": "20"
},
{
"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8",
"output": "100"
},
{
"input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3",
"output": "100"
},
{
"input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3"... | 1,396,524,571 | 870 | Python 3 | OK | TESTS | 20 | 139 | 307,200 | n = int(input())
people = list(map(int, input().split()))
goods = []
for i in range(n):
goods += [list(map(int, input().split()))]
time = []
for j in range(n):
time += [people[j] * 15 + sum(goods[j]) * 5]
print(min(time)) | Title: Line to Cashier
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* c... | ```python
n = int(input())
people = list(map(int, input().split()))
goods = []
for i in range(n):
goods += [list(map(int, input().split()))]
time = []
for j in range(n):
time += [people[j] * 15 + sum(goods[j]) * 5]
print(min(time))
``` | 3 | |
441 | B | Valera and Fruits | PROGRAMMING | 1,400 | [
"greedy",
"implementation"
] | null | null | Valera loves his garden, where *n* fruit trees grow.
This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collec... | The first line contains two space-separated integers *n* and *v* (1<=≤<=*n*,<=*v*<=≤<=3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next *n* lines contain the description of trees in the garden. The *i*-th line contains two space-separated integers *a**i* a... | Print a single integer — the maximum number of fruit that Valera can collect. | [
"2 3\n1 5\n2 3\n",
"5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n"
] | [
"8\n",
"60\n"
] | In the first sample, in order to obtain the optimal answer, you should act as follows.
- On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree.
In the second s... | 1,000 | [
{
"input": "2 3\n1 5\n2 3",
"output": "8"
},
{
"input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20",
"output": "60"
},
{
"input": "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202",
"output": "10596"
},
{
"input": "5 3000\n5 772\n1 2522\n2 575\n4 445... | 1,553,582,542 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 108 | 512,000 | import collections
def main():
hash_sum = collections.defaultdict(int)
sum = 0
max_num = 0
n,v = map(int,(input().split()))
for i in range(n):
a, b = map(int, (input().split()))
hash_sum[a] += b
sum = min(v , (hash_sum[1]))
for i in range(2,3002):
sum += mi... | Title: Valera and Fruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera loves his garden, where *n* fruit trees grow.
This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get wit... | ```python
import collections
def main():
hash_sum = collections.defaultdict(int)
sum = 0
max_num = 0
n,v = map(int,(input().split()))
for i in range(n):
a, b = map(int, (input().split()))
hash_sum[a] += b
sum = min(v , (hash_sum[1]))
for i in range(2,3002):
... | 0 | |
490 | C | Hacking Cypher | PROGRAMMING | 1,700 | [
"brute force",
"math",
"number theory",
"strings"
] | null | null | Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long inte... | The first line of the input contains the public key of the messenger — an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=108). | In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines — the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by *a*, and the right part ... | [
"116401024\n97 1024\n",
"284254589153928171911281811000\n1009 1000\n",
"120\n12 1\n"
] | [
"YES\n11640\n1024\n",
"YES\n2842545891539\n28171911281811000\n",
"NO\n"
] | none | 1,500 | [
{
"input": "116401024\n97 1024",
"output": "YES\n11640\n1024"
},
{
"input": "284254589153928171911281811000\n1009 1000",
"output": "YES\n2842545891539\n28171911281811000"
},
{
"input": "120\n12 1",
"output": "NO"
},
{
"input": "604\n6 4",
"output": "YES\n60\n4"
},
{
... | 1,693,667,397 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 35 | 1,000 | 12,288,000 | s = input()
size = len(s)
a, b = [int(x) for x in input().split()]
c = False
l = 0
r = int(s)
m = 10**(size - 1)
for i in range(1, len(s)):
l = l * 10 + int(s[i-1])
r -= int(s[i-1]) * m
m//=10
if s[i] != '0':
if (l%a == 0 and r%b == 0):
c = True
break
if c:
print(... | Title: Hacking Cypher
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained... | ```python
s = input()
size = len(s)
a, b = [int(x) for x in input().split()]
c = False
l = 0
r = int(s)
m = 10**(size - 1)
for i in range(1, len(s)):
l = l * 10 + int(s[i-1])
r -= int(s[i-1]) * m
m//=10
if s[i] != '0':
if (l%a == 0 and r%b == 0):
c = True
break
if c:
... | 0 | |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,698,777,518 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 0 | i = 0
while i < 5:
g = input()
massiv = g.split()
j = 0
while j < 5:
l = massiv[j]
if l == "1":
rv = abs(2-i)
rg = abs(2-j)
print(rv+rg)
j=j+1
i=i+1
| Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
i = 0
while i < 5:
g = input()
massiv = g.split()
j = 0
while j < 5:
l = massiv[j]
if l == "1":
rv = abs(2-i)
rg = abs(2-j)
print(rv+rg)
j=j+1
i=i+1
``` | 3 | |
784 | A | Numbers Joke | PROGRAMMING | 1,700 | [
"*special"
] | null | null | The input contains a single integer *a* (1<=≤<=*a*<=≤<=30).
Output a single integer. | The input contains a single integer *a* (1<=≤<=*a*<=≤<=30). | Output a single integer. | [
"3\n"
] | [
"27\n"
] | none | 0 | [
{
"input": "3",
"output": "27"
},
{
"input": "1",
"output": "4"
},
{
"input": "2",
"output": "22"
},
{
"input": "4",
"output": "58"
},
{
"input": "5",
"output": "85"
},
{
"input": "6",
"output": "94"
},
{
"input": "7",
"output": "121"
... | 1,522,347,098 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 61 | 7,065,600 | print(30-input()) | Title: Numbers Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=30).
Output a single integer.
Input Specification:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=30).
Output Specification:
Output a single integer.
Demo ... | ```python
print(30-input())
``` | -1 | |
903 | A | Hungry Student Problem | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. | Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. | [
"2\n6\n5\n"
] | [
"YES\nNO\n"
] | In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | 0 | [
{
"input": "2\n6\n5",
"output": "YES\nNO"
},
{
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\... | 1,615,390,261 | 2,147,483,647 | PyPy 3 | OK | TESTS | 8 | 92 | 0 | n=int(input())
for i in range(n):
a=int(input())
a-=(a%3)*7
if a<0:
print('NO')
else:
print('YES') | Title: Hungry Student Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chun... | ```python
n=int(input())
for i in range(n):
a=int(input())
a-=(a%3)*7
if a<0:
print('NO')
else:
print('YES')
``` | 3 | |
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the en... | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18... | 1,634,017,124 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 93 | 20,172,800 | import math
n, m = map(int, input().split())
arr = list(map(int, input().split()))
track, ans = [], []
for i in range(len(arr)):
track.append(math.ceil(arr[i] / m))
a = max(track)
for i in range(len(track)):
if track[i] == a:
ans.append(i + 1)
print(max(ans))
| Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line ... | ```python
import math
n, m = map(int, input().split())
arr = list(map(int, input().split()))
track, ans = [], []
for i in range(len(arr)):
track.append(math.ceil(arr[i] / m))
a = max(track)
for i in range(len(track)):
if track[i] == a:
ans.append(i + 1)
print(max(ans))
``` | 3 | |
316 | B2 | EKG | PROGRAMMING | 1,600 | [
"dfs and similar",
"dp"
] | null | null | In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another.
(Cultural note: standing in huge and disorganized queues for hours is a native ... | The first line contains two integers *n* (1<=≤<=*n*<=≤<=103) and *x* (1<=≤<=*x*<=≤<=*n*) — the number of beavers that stand in the queue and the Smart Beaver's number, correspondingly. All willing to get to the doctor are numbered from 1 to *n*.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*... | Print all possible positions of the Smart Beaver in the line in the increasing order. | [
"6 1\n2 0 4 0 6 0\n",
"6 2\n2 3 0 5 6 0\n",
"4 1\n0 0 0 0\n",
"6 2\n0 0 1 0 4 5\n"
] | [
"2\n4\n6\n",
"2\n5\n",
"1\n2\n3\n4\n",
"1\n3\n4\n6\n"
] | 70 | [
{
"input": "6 1\n2 0 4 0 6 0",
"output": "2\n4\n6"
},
{
"input": "6 2\n2 3 0 5 6 0",
"output": "2\n5"
},
{
"input": "4 1\n0 0 0 0",
"output": "1\n2\n3\n4"
},
{
"input": "6 2\n0 0 1 0 4 5",
"output": "1\n3\n4\n6"
},
{
"input": "10 7\n10 8 6 5 0 0 0 4 3 9",
"out... | 1,601,800,283 | 2,147,483,647 | PyPy 3 | OK | TESTS2 | 54 | 171 | 6,451,200 | def put(): return map(int, input().split())
n,x = put()
a = list(put())
parent = list(range(n+1))
for i in range(n):
if a[i]!=0:
parent[a[i]] = i+1
cnt = []
z = 0
#print(parent)
for i in range(n):
if a[i]==0:
j = i+1
c = 1
found = False
if j==x:
... | Title: EKG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to ... | ```python
def put(): return map(int, input().split())
n,x = put()
a = list(put())
parent = list(range(n+1))
for i in range(n):
if a[i]!=0:
parent[a[i]] = i+1
cnt = []
z = 0
#print(parent)
for i in range(n):
if a[i]==0:
j = i+1
c = 1
found = False
if j... | 3 | ||
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*... | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": ... | 1,691,381,855 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 30 | 0 | i=int(input())
j=input()
a=0
s=0
for char in j:
if char=='A':
a+=1
elif char=='D':
s+=1
if a>s:
print("Anton")
elif s>u:
print("Danik")
elif a==s:
print("Friendship") | Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, w... | ```python
i=int(input())
j=input()
a=0
s=0
for char in j:
if char=='A':
a+=1
elif char=='D':
s+=1
if a>s:
print("Anton")
elif s>u:
print("Danik")
elif a==s:
print("Friendship")
``` | -1 | |
994 | B | Knights of a Polygonal Table | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"sortings"
] | null | null | Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo... | The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement.
The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct.
The third line contains $n... | Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights. | [
"4 2\n4 5 9 7\n1 2 11 33\n",
"5 1\n1 2 3 4 5\n1 2 3 4 5\n",
"1 0\n2\n3\n"
] | [
"1 3 46 36 ",
"1 3 5 7 9 ",
"3 "
] | Consider the first example.
- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is o... | 1,000 | [
{
"input": "4 2\n4 5 9 7\n1 2 11 33",
"output": "1 3 46 36 "
},
{
"input": "5 1\n1 2 3 4 5\n1 2 3 4 5",
"output": "1 3 5 7 9 "
},
{
"input": "1 0\n2\n3",
"output": "3 "
},
{
"input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9",
"output": "0 3 10 16 14 17 18 "
},
{
"input"... | 1,532,205,694 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | from heapq import heappop, heappush
knight_count, k = map(int, input().split())
powers = list(map(int, input().split()))
coins = list(map(int, input().split()))
data = []
for i in range(len(powers)):
data.append((powers[i], coins[i], i))
data = sorted(data)
# print(data)
result = []
k += 1
suma = 0
knights_to_kill... | Title: Knights of a Polygonal Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power ... | ```python
from heapq import heappop, heappush
knight_count, k = map(int, input().split())
powers = list(map(int, input().split()))
coins = list(map(int, input().split()))
data = []
for i in range(len(powers)):
data.append((powers[i], coins[i], i))
data = sorted(data)
# print(data)
result = []
k += 1
suma = 0
knigh... | 0 | |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,694,530,242 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | net=int(input())+1
while(len(set(str(net)))<4):net+=1
print(net) | Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
net=int(input())+1
while(len(set(str(net)))<4):net+=1
print(net)
``` | 3 | |
132 | C | Logo Turtle | PROGRAMMING | 1,800 | [
"dp"
] | null | null | A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move 1 unit forward").
You are given a list of commands that will be given to the turtle. You have to change exactly *n* commands from the l... | The first line of input contains a string *commands* — the original list of commands. The string *commands* contains between 1 and 100 characters, inclusive, and contains only characters "T" and "F".
The second line contains an integer *n* (1<=≤<=*n*<=≤<=50) — the number of commands you have to change in the list. | Output the maximum distance from the starting point to the ending point of the turtle's path. The ending point of the turtle's path is turtle's coordinate after it follows all the commands of the modified list. | [
"FT\n1\n",
"FFFTFFF\n2\n"
] | [
"2\n",
"6\n"
] | In the first example the best option is to change the second command ("T") to "F" — this way the turtle will cover a distance of 2 units.
In the second example you have to change two commands. One of the ways to cover maximal distance of 6 units is to change the fourth command and first or last one. | 1,500 | [
{
"input": "FT\n1",
"output": "2"
},
{
"input": "FFFTFFF\n2",
"output": "6"
},
{
"input": "F\n1",
"output": "0"
},
{
"input": "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n50",
"output": "100"
},
{
"input": ... | 1,451,873,445 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 122 | 0 | #!/usr/bin/env python3
LMT = 105
def dfs(dre, pos, i, cn):
if cn < 0:
return 0
if i >= len(work):
return 0 if cn > 0 else abs(pos)
if dp[dre][pos + 100][i][cn] != -1:
return dp[dre][pos + 100][i][cn]
mv = 1 if dre else -1
x = dfs(dre, pos + mv, i + 1, cn - (work[i] != "... | Title: Logo Turtle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move 1 unit forward").
You are given a list... | ```python
#!/usr/bin/env python3
LMT = 105
def dfs(dre, pos, i, cn):
if cn < 0:
return 0
if i >= len(work):
return 0 if cn > 0 else abs(pos)
if dp[dre][pos + 100][i][cn] != -1:
return dp[dre][pos + 100][i][cn]
mv = 1 if dre else -1
x = dfs(dre, pos + mv, i + 1, cn - (wo... | 0 | |
958 | B1 | Maximum Control (easy) | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect s... | The first line of the input contains an integer *N* (2<=≤<=*N*<=≤<=1000) – the number of planets in the galaxy.
The next *N*<=-<=1 lines describe the hyperspace tunnels between the planets. Each of the *N*<=-<=1 lines contains two space-separated integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*N*) indicating that there is ... | A single integer denoting the number of remote planets. | [
"5\n4 1\n4 2\n1 3\n1 5\n",
"4\n1 2\n4 3\n1 4\n"
] | [
"3\n",
"2\n"
] | In the first example, only planets 2, 3 and 5 are connected by a single tunnel.
In the second example, the remote planets are 2 and 3.
Note that this problem has only two versions – easy and medium. | 0 | [
{
"input": "5\n4 1\n4 2\n1 3\n1 5",
"output": "3"
},
{
"input": "4\n1 2\n4 3\n1 4",
"output": "2"
},
{
"input": "10\n4 3\n2 6\n10 1\n5 7\n5 8\n10 6\n5 9\n9 3\n2 9",
"output": "4"
}
] | 1,586,521,603 | 2,147,483,647 | Python 3 | OK | TESTS | 9 | 155 | 0 | n=int(input())
pairs=[]
remote=[]
for i in range(n-1):
n,k=list(map(int,input().split()))
pairs.append(n)
pairs.append(k)
for i in pairs:
if pairs.count(i)==1:
remote.append(i)
print(len(remote))
| Title: Maximum Control (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in s... | ```python
n=int(input())
pairs=[]
remote=[]
for i in range(n-1):
n,k=list(map(int,input().split()))
pairs.append(n)
pairs.append(k)
for i in pairs:
if pairs.count(i)==1:
remote.append(i)
print(len(remote))
``` | 3 | |
601 | A | The Two Routes | PROGRAMMING | 1,600 | [
"graphs",
"shortest paths"
] | null | null | In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different to... | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively.
Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=... | Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1. | [
"4 2\n1 3\n3 4\n",
"4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n"
] | [
"2\n",
"-1\n",
"3\n"
] | In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codefo... | 500 | [
{
"input": "4 2\n1 3\n3 4",
"output": "2"
},
{
"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4",
"output": "-1"
},
{
"input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2",
"output": "3"
},
{
"input": "5 4\n1 2\n3 2\n3 4\n5 4",
"output": "4"
},
{
"input": "3 1\n1 2",
"output": "... | 1,476,900,439 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 62 | 4,915,200 | def bfs(g,n):
q=[1]
vis=[1 for x in range(n+1)]
dis=[0 for x in range(n+1)]
while len(q):
cur=q[0]
q.remove(cur)
if vis[cur]:
vis[cur]=0
for i in g[cur]:
if vis[i]:
q.append(i)
dis[i]=dis[... | Title: The Two Routes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road bet... | ```python
def bfs(g,n):
q=[1]
vis=[1 for x in range(n+1)]
dis=[0 for x in range(n+1)]
while len(q):
cur=q[0]
q.remove(cur)
if vis[cur]:
vis[cur]=0
for i in g[cur]:
if vis[i]:
q.append(i)
d... | 0 | |
464 | C | Substitutes in Number | PROGRAMMING | 2,100 | [
"dp"
] | null | null | Andrew and Eugene are playing a game. Initially, Andrew has string *s*, consisting of digits. Eugene sends Andrew multiple queries of type "*d**i*<=→<=*t**i*", that means "replace all digits *d**i* in string *s* with substrings equal to *t**i*". For example, if *s*<==<=123123, then query "2<=→<=00" transforms *s* to 10... | The first line contains string *s* (1<=≤<=|*s*|<=≤<=105), consisting of digits — the string before processing all the requests.
The second line contains a single integer *n* (0<=≤<=*n*<=≤<=105) — the number of queries.
The next *n* lines contain the descriptions of the queries. The *i*-th query is described by string... | Print a single integer — remainder of division of the resulting number by 1000000007 (109<=+<=7). | [
"123123\n1\n2->00\n",
"123123\n1\n3->\n",
"222\n2\n2->0\n0->7\n",
"1000000008\n0\n"
] | [
"10031003\n",
"1212\n",
"777\n",
"1\n"
] | Note that the leading zeroes are not removed from string *s* after the replacement (you can see it in the third sample). | 1,500 | [
{
"input": "123123\n1\n2->00",
"output": "10031003"
},
{
"input": "123123\n1\n3->",
"output": "1212"
},
{
"input": "222\n2\n2->0\n0->7",
"output": "777"
},
{
"input": "1000000008\n0",
"output": "1"
},
{
"input": "100\n5\n1->301\n0->013\n1->013\n0->103\n0->103",
... | 1,411,944,561 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 342 | 13,414,400 | def main():
s = input()
n = int(input())
M = 1000000007
a = {str(s):[10, s] for s in range(10)}
d = [['_', s]] + [input().split('->') for _ in range(n)]
for di, ti in reversed(d):
_p = 1
_v = 0
for c in ti:
_v = (_v * a[c][0] + a[c][1]) % M
... | Title: Substitutes in Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrew and Eugene are playing a game. Initially, Andrew has string *s*, consisting of digits. Eugene sends Andrew multiple queries of type "*d**i*<=→<=*t**i*", that means "replace all digits *d**i* in string *s* w... | ```python
def main():
s = input()
n = int(input())
M = 1000000007
a = {str(s):[10, s] for s in range(10)}
d = [['_', s]] + [input().split('->') for _ in range(n)]
for di, ti in reversed(d):
_p = 1
_v = 0
for c in ti:
_v = (_v * a[c][0] + a[c][1]) % M... | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,622,182,471 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 77 | 0 | s=input()
k=input()
l=[]
for i in range(len(s)):
l.append(int(s[i])^int(k[i]))
for i in l:
print(i,end="")
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
s=input()
k=input()
l=[]
for i in range(len(s)):
l.append(int(s[i])^int(k[i]))
for i in l:
print(i,end="")
``` | 3.98075 |
676 | A | Nicholas and Permutation | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position. | Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. | [
"5\n4 5 1 3 2\n",
"7\n1 6 5 3 4 7 2\n",
"6\n6 5 4 3 2 1\n"
] | [
"3\n",
"6\n",
"5\n"
] | In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possib... | 500 | [
{
"input": "5\n4 5 1 3 2",
"output": "3"
},
{
"input": "7\n1 6 5 3 4 7 2",
"output": "6"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "5"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "... | 1,621,466,780 | 2,147,483,647 | Python 3 | OK | TESTS | 159 | 77 | 0 | n = int(input()) ; l = [int(x) for x in input().split()]
print(max(l.index(n), l.index(1), n - l.index(n) - 1, n - l.index(1) - 1))
| Title: Nicholas and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integ... | ```python
n = int(input()) ; l = [int(x) for x in input().split()]
print(max(l.index(n), l.index(1), n - l.index(n) - 1, n - l.index(1) - 1))
``` | 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,652,456,519 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 0 | nor=[char for char in input()]
ron=[char for char in input()]
ron.reverse()
if nor==ron:
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
nor=[char for char in input()]
ron=[char for char in input()]
ron.reverse()
if nor==ron:
print('YES')
else:
print('NO')
``` | 3.9845 |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,659,000,013 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 46 | 0 | p = input()
h = input()
f = -1
g = []
for i in p:
f+=1
j = int(i)+int(h[f])
if j==2:
j=0
g.append(j)
for v in g:
print(v,end = "") | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
p = input()
h = input()
f = -1
g = []
for i in p:
f+=1
j = int(i)+int(h[f])
if j==2:
j=0
g.append(j)
for v in g:
print(v,end = "")
``` | 3.9885 |
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th... | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"inp... | 1,688,720,509 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n, k = [int(x) for x in input().strip().split()]
arr = [int(x) for x in input().strip().split()]
def solve(n: int, k: int, arr) -> int:
if n <= k:
return sum(arr)
cur, res = sum(arr[:k]), sum(arr[:k])
for i in range(k, n):
cur = cur + arr[i] - arr[i - k]
res = min(res, cu... | Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ... | ```python
n, k = [int(x) for x in input().strip().split()]
arr = [int(x) for x in input().strip().split()]
def solve(n: int, k: int, arr) -> int:
if n <= k:
return sum(arr)
cur, res = sum(arr[:k]), sum(arr[:k])
for i in range(k, n):
cur = cur + arr[i] - arr[i - k]
res = m... | 0 | |
993 | A | Two Squares | PROGRAMMING | 1,600 | [
"geometry",
"implementation"
] | null | null | You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the ... | The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the ... | Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower). | [
"0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1\n",
"0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1\n",
"6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples: | 500 | [
{
"input": "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1",
"output": "YES"
},
{
"input": "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1",
"output": "NO"
},
{
"input": "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7",
"output": "YES"
},
{
"input": "0 0 6 0 6 6 0 6\n8 4 4 8 8 12 12 8",
"output": "YES"
},
... | 1,672,814,210 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 124 | 62 | 0 | import math
# point: ()
# vector: ((), ())
def product(point: tuple, vector: tuple) -> int:
# print(point, vector)
return (point[0] - vector[0][0]) * (vector[1][1] - vector[0][1]) - (point[1] - vector[0][1]) * (vector[1][0] - vector[0][0])
# points: ((), (), (), ())
# vectors: (((), ()), ((), ())... | Title: Two Squares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered t... | ```python
import math
# point: ()
# vector: ((), ())
def product(point: tuple, vector: tuple) -> int:
# print(point, vector)
return (point[0] - vector[0][0]) * (vector[1][1] - vector[0][1]) - (point[1] - vector[0][1]) * (vector[1][0] - vector[0][0])
# points: ((), (), (), ())
# vectors: (((), ())... | 3 | |
961 | A | Tetris | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
... | The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) — the length of the platform and the number of the squares.
The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) — column in which $i$-th square will appear. | Print one integer — the amount of points you will receive. | [
"3 9\n1 1 2 2 2 3 1 2 3\n"
] | [
"2\n"
] | In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$).
After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing... | 0 | [
{
"input": "3 9\n1 1 2 2 2 3 1 2 3",
"output": "2"
},
{
"input": "1 7\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "3 5\n1 1 1 2 3",
"output": "1"
},
{
"input": "4 6\n4 4 4 4 4 4",
"output": "0"
},
{
"input": "4 6\... | 1,660,936,749 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | columns, _ = [int(i) for i in input().split()]
colVec = [0]*columns
nZeroes = columns
pieces = [int(i) for i in input().split()]
points = 0
for piece in pieces:
if colVec[piece-1] == 0:
nZeroes -= 1
colVec[piece-1] += 1
if nZeroes == 0:
points += 1
for i in range(columns):
... | Title: Tetris
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bo... | ```python
columns, _ = [int(i) for i in input().split()]
colVec = [0]*columns
nZeroes = columns
pieces = [int(i) for i in input().split()]
points = 0
for piece in pieces:
if colVec[piece-1] == 0:
nZeroes -= 1
colVec[piece-1] += 1
if nZeroes == 0:
points += 1
for i in range(columns):
... | 3 | |
862 | A | Mahmoud and Ehab and the MEX | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX... | The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX.
The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set. | The only line should contain one integer — the minimal number of operations Dr. Evil should perform. | [
"5 3\n0 4 5 6 7\n",
"1 0\n0\n",
"5 0\n1 2 3 4 5\n"
] | [
"2\n",
"1\n",
"0\n"
] | For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.
For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.
In the third test case the set is already evil. | 500 | [
{
"input": "5 3\n0 4 5 6 7",
"output": "2"
},
{
"input": "1 0\n0",
"output": "1"
},
{
"input": "5 0\n1 2 3 4 5",
"output": "0"
},
{
"input": "10 5\n57 1 47 9 93 37 76 70 78 15",
"output": "4"
},
{
"input": "10 5\n99 98 93 97 95 100 92 94 91 96",
"output": "5"
... | 1,598,180,671 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 109 | 6,656,000 | n,x=input().split()
n=int(n)
x=int(x)
l=input().split()
l.sort()
num=0
for i in range(n):
if int(l[i]) > x:
break
elif int(l[i])==x:
num = num + 1
break
else:
num = num + 2
print(num)
| Title: Mahmoud and Ehab and the MEX
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in ... | ```python
n,x=input().split()
n=int(n)
x=int(x)
l=input().split()
l.sort()
num=0
for i in range(n):
if int(l[i]) > x:
break
elif int(l[i])==x:
num = num + 1
break
else:
num = num + 2
print(num)
``` | 0 | |
245 | B | Internet Address | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format:
where:
- <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), - <domain> is a no... | The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only.
It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above... | Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. | [
"httpsunrux\n",
"ftphttprururu\n"
] | [
"http://sun.ru/x\n",
"ftp://http.ru/ruru\n"
] | In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". | 0 | [
{
"input": "httpsunrux",
"output": "http://sun.ru/x"
},
{
"input": "ftphttprururu",
"output": "ftp://http.ru/ruru"
},
{
"input": "httpuururrururruruurururrrrrurrurrurruruuruuu",
"output": "http://uu.ru/rrururruruurururrrrrurrurrurruruuruuu"
},
{
"input": "httpabuaruauabbaruru... | 1,380,442,107 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | import re
s = input()
L = re.findall(r'(http|ftp)([a-z]+ru)([a-z]*)',s)[0]
print(L)
print(L[0],'://',L[1][:len(L[1])-2],'.ru',sep='',end='')
if L[2]:
print('/',L[2],sep='') | Title: Internet Address
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format:
where:
- <protocol>... | ```python
import re
s = input()
L = re.findall(r'(http|ftp)([a-z]+ru)([a-z]*)',s)[0]
print(L)
print(L[0],'://',L[1][:len(L[1])-2],'.ru',sep='',end='')
if L[2]:
print('/',L[2],sep='')
``` | 0 | |
300 | A | Array | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The produ... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. | In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second... | [
"3\n-1 2 0\n",
"4\n-1 -2 -3 0\n"
] | [
"1 -1\n1 2\n1 0\n",
"1 -1\n2 -3 -2\n1 0\n"
] | none | 500 | [
{
"input": "3\n-1 2 0",
"output": "1 -1\n1 2\n1 0"
},
{
"input": "4\n-1 -2 -3 0",
"output": "1 -1\n2 -3 -2\n1 0"
},
{
"input": "5\n-1 -2 1 2 0",
"output": "1 -1\n2 1 2\n2 0 -2"
},
{
"input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -1... | 1,683,414,432 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | _, arr = input(), list(map(int, input().split()))
pos = []; neg = []; zeros = [];
neg_nums = [n for n in arr if n < 0]
pos_nums = [n for n in arr if n > 0]
num_negs = len(neg_nums)
if num_negs % 2 == 0: # Even number of negative values
pos.extend(neg_nums)
pos.extend(pos_nums)
zeros.append(0)
else:
... | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. T... | ```python
_, arr = input(), list(map(int, input().split()))
pos = []; neg = []; zeros = [];
neg_nums = [n for n in arr if n < 0]
pos_nums = [n for n in arr if n > 0]
num_negs = len(neg_nums)
if num_negs % 2 == 0: # Even number of negative values
pos.extend(neg_nums)
pos.extend(pos_nums)
zeros.append(0)
... | 0 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,695,244,365 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | borze_code = input()
translation = ""
i = 0
while i < len(borze_code):
if borze_code[i] == '.':
translation += 'O'
elif borze_code[i] == '-' and i + 1 < len(borze_code):
if borze_code[i + 1] == '.':
translation += '1'
i += 1
elif borze_code[i + 1] == '-':
... | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
borze_code = input()
translation = ""
i = 0
while i < len(borze_code):
if borze_code[i] == '.':
translation += 'O'
elif borze_code[i] == '-' and i + 1 < len(borze_code):
if borze_code[i + 1] == '.':
translation += '1'
i += 1
elif borze_code[i + 1] ==... | 0 |
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is... | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so ... | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "... | 1,650,013,897 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 204,800 | n=int(input())
t=[]
k=1
for i in range(n):
t1,t2=map(int, input().split())
t.append((t1,t2))
for i in t:
if k<t.count(i):
k=t.count(i)
print(k) | Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l... | ```python
n=int(input())
t=[]
k=1
for i in range(n):
t1,t2=map(int, input().split())
t.append((t1,t2))
for i in t:
if k<t.count(i):
k=t.count(i)
print(k)
``` | 0 | |
18 | C | Stripe | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | C. Stripe | 2 | 64 | Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | [
"9\n1 5 -6 7 9 -16 0 -2 2\n",
"3\n1 1 1\n",
"2\n0 0\n"
] | [
"3\n",
"0\n",
"1\n"
] | none | 0 | [
{
"input": "9\n1 5 -6 7 9 -16 0 -2 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "4\n100 1 10 111",
"output": "1"
},
{
"input": "10\n0 4 -3 0 -2 2 -3 -3 2 5",
"output": "3"
},
{
"input": "... | 1,660,120,181 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | n = int(input())
li = list(map(int, input().split()))
pref_li = list()
sum_li = 0
cnt = 0
for i in range(n):
sum_li += li[i]
if sum_li == 0 and i != 0 and i != n-1:
cnt += 1
if cnt == 0 and n == 2:
if li[0] == li[1]:
print(1)
else:
print(0)
else:
print(cnt)
| Title: Stripe
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that ... | ```python
n = int(input())
li = list(map(int, input().split()))
pref_li = list()
sum_li = 0
cnt = 0
for i in range(n):
sum_li += li[i]
if sum_li == 0 and i != 0 and i != n-1:
cnt += 1
if cnt == 0 and n == 2:
if li[0] == li[1]:
print(1)
else:
print(0)
else:
prin... | 0 |
331 | C1 | The Great Julya Calendar | PROGRAMMING | 1,100 | [
"dp"
] | null | null | Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows:
"May the Great Beaver bless you! May your chacres open ... | The single line contains the magic integer *n*, 0<=≤<=*n*.
- to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with co... | Print a single integer — the minimum number of subtractions that turns the magic number to a zero. | [
"24\n"
] | [
"5"
] | In the first test sample the minimum number of operations can be reached by the following sequence of subtractions: | 20 | [
{
"input": "24",
"output": "5"
},
{
"input": "0",
"output": "0"
},
{
"input": "3",
"output": "1"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "31",
"output": "6"
},
... | 1,423,239,976 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS1 | 0 | 62 | 0 | ##def g(b):
## global a
## if b == 0: return 0
## if b < 10: return 1
## if a[b] == -1: a[b] = 1 + min(g(b - int(n)) for n in str(b) if n != '0')
## return a[b]
##
##a = [-1] * 2001
##q = [0] * 2001
##p, c = 0, 0
##for i in range(0, 2001):
## n = g(i)
## q[n] += 1
## if p != n:
## ... | Title: The Great Julya Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on i... | ```python
##def g(b):
## global a
## if b == 0: return 0
## if b < 10: return 1
## if a[b] == -1: a[b] = 1 + min(g(b - int(n)) for n in str(b) if n != '0')
## return a[b]
##
##a = [-1] * 2001
##q = [0] * 2001
##p, c = 0, 0
##for i in range(0, 2001):
## n = g(i)
## q[n] += 1
## if p ... | -1 | |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,663,590,641 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 2,457,600 | n = int(input())
v = list(map(int, input().split()))
for i in range(int(input())):
type, l, r = map(int, input().split())
if type == 1:
print(sum(v[l - 1:r]))
else:
print(sum(sorted(v)[l - 1:r]))
| Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
n = int(input())
v = list(map(int, input().split()))
for i in range(int(input())):
type, l, r = map(int, input().split())
if type == 1:
print(sum(v[l - 1:r]))
else:
print(sum(sorted(v)[l - 1:r]))
``` | 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,589,351,590 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 218 | 6,656,000 |
def GCD(a, b):
if b == 0:
return a
return GCD(b, a % b)
y, w = [int(item) for item in input().split()]
# maximum = y if y>w else w
maximum = max(y, w)
dotChances = 6 - maximum + 1
temp = GCD(dotChances, 6)
print('{}/{}'.format(dotChances // temp, 6 // temp))
| 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
def GCD(a, b):
if b == 0:
return a
return GCD(b, a % b)
y, w = [int(item) for item in input().split()]
# maximum = y if y>w else w
maximum = max(y, w)
dotChances = 6 - maximum + 1
temp = GCD(dotChances, 6)
print('{}/{}'.format(dotChances // temp, 6 // temp))
``` | 3.841409 |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,634,312,703 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
void fast(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
solve(){
}
int main(){
fast();
int r,x1,y1,x2,y2;
cin>>r>>x1>>y1>>x2>>y2;
double d=sqrt((double)(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
cout<<ceil(d/r/2);
return 0;
... | Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void fast(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
solve(){
}
int main(){
fast();
int r,x1,y1,x2,y2;
cin>>r>>x1>>y1>>x2>>y2;
double d=sqrt((double)(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
cout<<ceil(d/r/2);
r... | -1 | |
897 | A | Scarborough Fair | PROGRAMMING | 800 | [
"implementation"
] | null | null | Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Althou... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains a string *s* of length *n*, consisting of lowercase English letters.
Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), ... | Output string *s* after performing *m* operations described above. | [
"3 1\nioi\n1 1 i n\n",
"5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n"
] | [
"noi",
"gaaak"
] | For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak. | 500 | [
{
"input": "3 1\nioi\n1 1 i n",
"output": "noi"
},
{
"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g",
"output": "gaaak"
},
{
"input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n... | 1,512,761,021 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 62 | 5,529,600 | n,k=map(int,input().split())
resht=input()
reshte=[]
for char in resht:
reshte.append(char)
for i in range(k):
p,t,d,f=input().split()
p=int(p)
t=int(t)
for j in range(p-1,t):
if reshte[j]==d:
reshte[j]=f
output=""
for char in reshte:
output+=char
print(output) | Title: Scarborough Fair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get ... | ```python
n,k=map(int,input().split())
resht=input()
reshte=[]
for char in resht:
reshte.append(char)
for i in range(k):
p,t,d,f=input().split()
p=int(p)
t=int(t)
for j in range(p-1,t):
if reshte[j]==d:
reshte[j]=f
output=""
for char in reshte:
output+=char
print(output)
``` | 3 | |
51 | A | Cheaterius's Problem | PROGRAMMING | 1,300 | [
"implementation"
] | A. Cheaterius's Problem | 2 | 256 | Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000), where *n* is the number of amulets. Then the amulet's descriptions are contained. Every description occupies two lines and contains two numbers (from 1 to 6) in each line. Between every pair of amulets the line "**" is located. | Print the required number of piles. | [
"4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13\n",
"4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53\n"
] | [
"1\n",
"2\n"
] | none | 500 | [
{
"input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13",
"output": "1"
},
{
"input": "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53",
"output": "2"
},
{
"input": "4\n56\n61\n**\n31\n31\n**\n33\n11\n**\n11\n33",
"output": "2"
},
{
"input": "4\n36\n44\n**\n32\n46\n**\n66\n41... | 1,618,132,926 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | def rotate(item: str) -> str:
# return item[2]+item[0]+item[3]+item[1]
return f'{item[2]}{item[0]}{item[3]}{item[1]}'
def equals(it1: str, it2: str) -> bool:
for i in range(4):
if it1 == it2:
return True
it2 = rotate(it2)
return False
def contains(cont: list,... | Title: Cheaterius's Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive... | ```python
def rotate(item: str) -> str:
# return item[2]+item[0]+item[3]+item[1]
return f'{item[2]}{item[0]}{item[3]}{item[1]}'
def equals(it1: str, it2: str) -> bool:
for i in range(4):
if it1 == it2:
return True
it2 = rotate(it2)
return False
def contains(c... | 0 |
984 | A | Game | PROGRAMMING | 800 | [
"sortings"
] | null | null | Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ... | The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). | Print one number that will be left on the board. | [
"3\n2 1 3\n",
"3\n2 2 2\n"
] | [
"2",
"2"
] | In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | 500 | [
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 2 2",
"output": "2"
},
{
"input": "9\n44 53 51 80 5 27 74 79 94",
"output": "53"
},
{
"input": "10\n38 82 23 37 96 4 81 60 67 86",
"output": "60"
},
{
"input": "10\n58 26 77 15 53 81 68 48 22 65",
"outpu... | 1,559,245,724 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 109 | 0 | # -*- coding: utf-8 -*-
"""
Created on Fri May 31 01:16:13 2019
@author: avina
"""
n = int(input())
l = list(map(int,input().split()))
l.sort()
if n%2 == 0:
print(l[n//2 - 1])
else:
print(l[n//2]) | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the... | ```python
# -*- coding: utf-8 -*-
"""
Created on Fri May 31 01:16:13 2019
@author: avina
"""
n = int(input())
l = list(map(int,input().split()))
l.sort()
if n%2 == 0:
print(l[n//2 - 1])
else:
print(l[n//2])
``` | 3 | |
299 | A | Ksusha and Array | PROGRAMMING | 1,000 | [
"brute force",
"number theory",
"sortings"
] | null | null | Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! | The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements. | Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them. | [
"3\n2 2 4\n",
"5\n2 1 3 1 6\n",
"3\n2 3 5\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | 500 | [
{
"input": "3\n2 2 4",
"output": "2"
},
{
"input": "5\n2 1 3 1 6",
"output": "1"
},
{
"input": "3\n2 3 5",
"output": "-1"
},
{
"input": "1\n331358794",
"output": "331358794"
},
{
"input": "5\n506904227 214303304 136194869 838256937 183952885",
"output": "-1"
... | 1,675,302,517 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 3,481,600 | n=int(input())
x=list(map(int,input().split()))
c=0
for i in x:
if i%min(x)==0:
c+=1
if c==len(x): print(min(x))
else: print(-1) | Title: Ksusha and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that ... | ```python
n=int(input())
x=list(map(int,input().split()))
c=0
for i in x:
if i%min(x)==0:
c+=1
if c==len(x): print(min(x))
else: print(-1)
``` | 0 | |
385 | B | Bear and Strings | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation",
"math",
"strings"
] | null | null | The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string... | The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters. | Print a single number — the answer to the problem. | [
"bearbtear\n",
"bearaabearc\n"
] | [
"6\n",
"20\n"
] | In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).
In the second sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (1, 11), (2, 10), (2, 11), (3, 10), (3, 11), (4, 10), (4, 11), (5, 10), (5, 11)... | 1,000 | [
{
"input": "bearbtear",
"output": "6"
},
{
"input": "bearaabearc",
"output": "20"
},
{
"input": "pbearbearhbearzqbearjkterasjhy",
"output": "291"
},
{
"input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb",
"output"... | 1,590,492,075 | 5,475 | Python 3 | WRONG_ANSWER | TESTS | 0 | 78 | 0 | import sys
s=sys.stdin.readline()
c=0
for i in range(len(s)-3):
for j in range(i+3,len(s)):
if 'bear' in s[i:j+1]:
c+=1
sys.stdout.write(str(c)) | Title: Bear and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j... | ```python
import sys
s=sys.stdin.readline()
c=0
for i in range(len(s)-3):
for j in range(i+3,len(s)):
if 'bear' in s[i:j+1]:
c+=1
sys.stdout.write(str(c))
``` | 0 | |
991 | D | Bishwock | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't occupy the same square.
Vasya has a board wi... | The input contains two nonempty strings that describe Vasya's board. Those strings contain only symbols "0" (zero) that denote the empty squares and symbols "X" (uppercase English letter) that denote the squares occupied by pawns. Strings are nonempty and are of the same length that does not exceed $100$. | Output a single integer — the maximum amount of bishwocks that can be placed onto the given board. | [
"00\n00\n",
"00X00X0XXX0\n0XXX0X00X00\n",
"0X0X0\n0X0X0\n",
"0XXX0\n00000\n"
] | [
"1",
"4",
"0",
"2"
] | none | 1,500 | [
{
"input": "00\n00",
"output": "1"
},
{
"input": "00X00X0XXX0\n0XXX0X00X00",
"output": "4"
},
{
"input": "0X0X0\n0X0X0",
"output": "0"
},
{
"input": "0XXX0\n00000",
"output": "2"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\nX",
"output": "... | 1,549,630,153 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 307,200 | sa = input()
sb = input()
a = []
b = []
k = 0
for i in range(0, len(sa) - 1) :
a.append(sa[i])
for i in range(0, len(sb) - 1) :
b.append(sb[i])
for i in range(0, len(sa) - 2) :
if a[i] == '0' and a[i + 1] == '0' :
if b[i] == '0' :
k += 1
a[i] = a[i + 1] = 'X'
... | Title: Bishwock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
Bishwocks don't attack any squares and can even occup... | ```python
sa = input()
sb = input()
a = []
b = []
k = 0
for i in range(0, len(sa) - 1) :
a.append(sa[i])
for i in range(0, len(sb) - 1) :
b.append(sb[i])
for i in range(0, len(sa) - 2) :
if a[i] == '0' and a[i + 1] == '0' :
if b[i] == '0' :
k += 1
a[i] = a[i + 1]... | 0 | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,610,011,314 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 109 | 307,200 | n = int(input())
a = list(map(int, (list(input()))))
b = list(map(int, (list(input()))))
move = 0
for i in range(n):
x = abs(a[i]-b[i])
if x <= 5:
move += x
else:
x = min(a[i], b[i]) + 10 - max(a[i], b[i])
move += x
print(move)
| Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
n = int(input())
a = list(map(int, (list(input()))))
b = list(map(int, (list(input()))))
move = 0
for i in range(n):
x = abs(a[i]-b[i])
if x <= 5:
move += x
else:
x = min(a[i], b[i]) + 10 - max(a[i], b[i])
move += x
print(move)
``` | 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,686,467,502 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 124 | 0 | n, m = map(int, input().split())
N = n
a = [int(x) for x in input().split()]
a.sort()
A = a.copy()
minimum = 0
i = 0
for i in range(m):
while n > 0 and a[i] > 0:
n -= 1
minimum += a[i]
a[i] -= 1
if n == 0:
break
n = N
a = A
maximum = 0
while len... | 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
n, m = map(int, input().split())
N = n
a = [int(x) for x in input().split()]
a.sort()
A = a.copy()
minimum = 0
i = 0
for i in range(m):
while n > 0 and a[i] > 0:
n -= 1
minimum += a[i]
a[i] -= 1
if n == 0:
break
n = N
a = A
maximum = 0
... | 3 | |
478 | C | Table Decorations | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *t* of tables can be decorated if we know number of balloons of each color?
Your task is to write a pro... | The single line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space. | Print a single integer *t* — the maximum number of tables that can be decorated in the required manner. | [
"5 4 3\n",
"1 1 1\n",
"2 3 3\n"
] | [
"4\n",
"1\n",
"2\n"
] | In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively. | 1,500 | [
{
"input": "5 4 3",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "0 1 0",
"output": "0"
},
{
"input": "0 3 3",
"output": "2"
},
{
"input": "4 0 4",
"output": "2"
},
{
"input": "100000... | 1,675,605,251 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | r,g,b=map(int, input().split())
if r>1 and g>1 and b>1:
x=(r+g+b)//3
elif (r>=1 and g>=1) or (r>=1 and b>=1) or (g>=1 and b>=1):
x=1
else:
x=0
print(x) | Title: Table Decorations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *... | ```python
r,g,b=map(int, input().split())
if r>1 and g>1 and b>1:
x=(r+g+b)//3
elif (r>=1 and g>=1) or (r>=1 and b>=1) or (g>=1 and b>=1):
x=1
else:
x=0
print(x)
``` | 0 | |
863 | A | Quasi-palindrome | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to str... | The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes. | Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes). | [
"131\n",
"320\n",
"2010200\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 0 | [
{
"input": "131",
"output": "YES"
},
{
"input": "320",
"output": "NO"
},
{
"input": "2010200",
"output": "YES"
},
{
"input": "1",
"output": "YES"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "999999999",
"output": "YES"
},
{
"i... | 1,511,584,292 | 1,292 | Python 3 | OK | TESTS | 44 | 93 | 5,529,600 | x=int(input())
while x%10==0:
x=int(x/10)
x=str(x)
if x==x[::-1]:
print('YES')
else:
print('NO')
| Title: Quasi-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from righ... | ```python
x=int(input())
while x%10==0:
x=int(x/10)
x=str(x)
if x==x[::-1]:
print('YES')
else:
print('NO')
``` | 3 | |
879 | A | Borya's Diagnosis | PROGRAMMING | 900 | [
"implementation"
] | null | null | It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get t... | First line contains an integer *n* — number of doctors (1<=≤<=*n*<=≤<=1000).
Next *n* lines contain two numbers *s**i* and *d**i* (1<=≤<=*s**i*,<=*d**i*<=≤<=1000). | Output a single integer — the minimum day at which Borya can visit the last doctor. | [
"3\n2 2\n1 2\n2 2\n",
"2\n10 1\n6 5\n"
] | [
"4\n",
"11\n"
] | In the first sample case, Borya can visit all doctors on days 2, 3 and 4.
In the second sample case, Borya can visit all doctors on days 10 and 11. | 500 | [
{
"input": "3\n2 2\n1 2\n2 2",
"output": "4"
},
{
"input": "2\n10 1\n6 5",
"output": "11"
},
{
"input": "3\n6 10\n3 3\n8 2",
"output": "10"
},
{
"input": "4\n4 8\n10 10\n4 2\n8 2",
"output": "14"
},
{
"input": "5\n7 1\n5 1\n6 1\n1 6\n6 8",
"output": "14"
},
... | 1,653,280,636 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | def main():
n = int(input())
doctors = []
for _ in range(n):
s, d = map(int, input().split())
doctors.append((s, d))
t = 0
for s, d in doctors:
if t <= s:
t = s
else:
#print("sadsad", (t - s) % d)
t += min((t -... | Title: Borya's Diagnosis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed o... | ```python
def main():
n = int(input())
doctors = []
for _ in range(n):
s, d = map(int, input().split())
doctors.append((s, d))
t = 0
for s, d in doctors:
if t <= s:
t = s
else:
#print("sadsad", (t - s) % d)
t +... | 0 | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,666,278,262 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | n,m = input().split()
if m>n:
c = 0
for i in range(2,int(m)):
if int(m)%i==0:
c = c+1
if c==0:
print('YES')
else:
print('NO')
else:
print('NO')
| Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
n,m = input().split()
if m>n:
c = 0
for i in range(2,int(m)):
if int(m)%i==0:
c = c+1
if c==0:
print('YES')
else:
print('NO')
else:
print('NO')
``` | 0 |
1,000 | B | Light It Up | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunate... | First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed progra... | Print the only integer — maximum possible total time when the lamp is lit. | [
"3 10\n4 6 7\n",
"2 12\n1 10\n",
"2 7\n3 4\n"
] | [
"8\n",
"9\n",
"6\n"
] | In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal so... | 0 | [
{
"input": "3 10\n4 6 7",
"output": "8"
},
{
"input": "2 12\n1 10",
"output": "9"
},
{
"input": "2 7\n3 4",
"output": "6"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "5 10\n1 3 5 6 8",
"output": "6"
},
{
"input": "7 1000000000\n1 10001 10011 20... | 1,666,064,836 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n,m=map(int,input().split())
L=list(map(int,input().split()))
P=[]
L.append(0)
L.append(m)
L.sort()
K=[0]*m
J=[1]*m
k=0
for i in range(0,(len(L)-len(L)%2)//2):
K[L[2*i]:L[2*i+1]]=[1]*(L[2*i+1]-L[2*i])
for i in range(0,(len(L)-len(L)%2)//2):
A=K[:2*i+2]
B=K[2*i+1:]
P.append(A.count(1)+B.cou... | Title: Light It Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows y... | ```python
n,m=map(int,input().split())
L=list(map(int,input().split()))
P=[]
L.append(0)
L.append(m)
L.sort()
K=[0]*m
J=[1]*m
k=0
for i in range(0,(len(L)-len(L)%2)//2):
K[L[2*i]:L[2*i+1]]=[1]*(L[2*i+1]-L[2*i])
for i in range(0,(len(L)-len(L)%2)//2):
A=K[:2*i+2]
B=K[2*i+1:]
P.append(A.coun... | 0 | |
5 | A | Chat Servers Outgoing Traffic | PROGRAMMING | 1,000 | [
"implementation"
] | A. Chat Server's Outgoing Traffic | 1 | 64 | Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
- Include a person... | Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:
- +<name> for 'Add' command. - -<name> for 'Remove' command. - <sender_name>:<message_text> for 'Send' command.
<name> and <s... | Print a single number — answer to the problem. | [
"+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n",
"+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n"
] | [
"9\n",
"14\n"
] | none | 0 | [
{
"input": "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate",
"output": "9"
},
{
"input": "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate",
"output": "14"
},
{
"input": "+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIO... | 1,398,405,754 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | import sys
p = res = 0
for x in sys.stdin:
if x[0] == '+': p += 1
elif x[0] == '-': p -= 1
else: res += p*len(x.split(':')[1])
print(res) | Title: Chat Servers Outgoing Traffic
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in fr... | ```python
import sys
p = res = 0
for x in sys.stdin:
if x[0] == '+': p += 1
elif x[0] == '-': p -= 1
else: res += p*len(x.split(':')[1])
print(res)
``` | 0 |
689 | C | Mike and Chocolate Thieves | PROGRAMMING | 1,700 | [
"binary search",
"combinatorics",
"math"
] | null | null | Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly *k* times more than the previous... | The single line of input contains the integer *m* (1<=≤<=*m*<=≤<=1015) — the number of ways the thieves might steal the chocolates, as rumours say. | Print the only integer *n* — the maximum amount of chocolates that thieves' bags can carry. If there are more than one *n* satisfying the rumors, print the smallest one.
If there is no such *n* for a false-rumoured *m*, print <=-<=1. | [
"1\n",
"8\n",
"10\n"
] | [
"8\n",
"54\n",
"-1\n"
] | In the first sample case the smallest *n* that leads to exactly one way of stealing chocolates is *n* = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest *n* that leads to exactly 8 ways is *n* = 54 with the po... | 1,500 | [
{
"input": "1",
"output": "8"
},
{
"input": "8",
"output": "54"
},
{
"input": "10",
"output": "-1"
},
{
"input": "27",
"output": "152"
},
{
"input": "28206",
"output": "139840"
},
{
"input": "32",
"output": "184"
},
{
"input": "115",
"o... | 1,689,175,645 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689175645.552479")# 1689175645.552494 | Title: Mike and Chocolate Thieves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thi... | ```python
print("_RANDOM_GUESS_1689175645.552479")# 1689175645.552494
``` | 0 | |
518 | D | Ilya and Escalator | PROGRAMMING | 1,700 | [
"combinatorics",
"dp",
"math",
"probabilities"
] | null | null | Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor.
Let's assume that *n* people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue en... | The first line of the input contains three numbers *n*,<=*p*,<=*t* (1<=≤<=*n*,<=*t*<=≤<=2000, 0<=≤<=*p*<=≤<=1). Numbers *n* and *t* are integers, number *p* is real, given with exactly two digits after the decimal point. | Print a single real number — the expected number of people who will be standing on the escalator after *t* seconds. The absolute or relative error mustn't exceed 10<=-<=6. | [
"1 0.50 1\n",
"1 0.50 4\n",
"4 0.20 2\n"
] | [
"0.5\n",
"0.9375\n",
"0.4\n"
] | none | 2,000 | [
{
"input": "1 0.50 1",
"output": "0.500000000000000"
},
{
"input": "1 0.50 4",
"output": "0.937500000000000"
},
{
"input": "4 0.20 2",
"output": "0.400000000000000"
},
{
"input": "2000 0.61 2000",
"output": "1219.999999999999545"
},
{
"input": "100 1.00 200",
... | 1,608,893,094 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 4 | 202 | 2,662,400 | import math
#MOD=10**9+7
MAX=2001
fact=[math.log10(1)]
for zz in range(1,MAX+1):
# fact.append(((fact[-1]%MOD)*zz%MOD)%MOD) #with MOD
fact.append(fact[-1]+math.log10(zz)) #without MOD
def nCr(n,r): #choose, MOD is prime
num=fact[n]
# den=((fact[r]%MOD)*(fact[n-r]%MOD))%MOD #with MOD
# retur... | Title: Ilya and Escalator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor.
Let's assume that *n* people stand in the queue for the escalator. At... | ```python
import math
#MOD=10**9+7
MAX=2001
fact=[math.log10(1)]
for zz in range(1,MAX+1):
# fact.append(((fact[-1]%MOD)*zz%MOD)%MOD) #with MOD
fact.append(fact[-1]+math.log10(zz)) #without MOD
def nCr(n,r): #choose, MOD is prime
num=fact[n]
# den=((fact[r]%MOD)*(fact[n-r]%MOD))%MOD #with MOD
... | -1 | |
625 | D | Finals in arithmetic | PROGRAMMING | 2,400 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder.
Let's denote a flip operation of an integer as follows: number is considered... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). | If there is no such positive integer *a* without leading zeroes that *a*<=+<=*a**r*<==<=*n* then print 0. Otherwise, print any valid *a*. If there are many possible answers, you are allowed to pick any. | [
"4\n",
"11\n",
"5\n",
"33\n"
] | [
"2\n",
"10\n",
"0\n",
"21\n"
] | In the first sample 4 = 2 + 2, *a* = 2 is the only possibility.
In the second sample 11 = 10 + 1, *a* = 10 — the only valid solution. Note, that *a* = 01 is incorrect, because *a* can't have leading zeroes.
It's easy to check that there is no suitable *a* in the third sample.
In the fourth sample 33 = 30 + 3 = 12 + ... | 2,000 | [
{
"input": "4",
"output": "2"
},
{
"input": "11",
"output": "10"
},
{
"input": "5",
"output": "0"
},
{
"input": "33",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "99",
"output": "54"
},
{
"input": "100",
"output": "0"
... | 1,454,841,738 | 5,838 | Python 3 | WRONG_ANSWER | PRETESTS | 11 | 545 | 2,560,000 | s = input()
n = int(s)
sa = list(map(int, s))
if len(s) % 2 == 1 and int(s[len(s)//2]) % 2 == 1:
print(0)
else:
for i in range(len(sa)//2):
if sa[i] != sa[-i-1]:
print(0)
break
else:
if len(sa) % 2 == 1:
sa[len(sa)//2] = int(s[len(s)//2]) // 2
... | Title: Finals in arithmetic
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a n... | ```python
s = input()
n = int(s)
sa = list(map(int, s))
if len(s) % 2 == 1 and int(s[len(s)//2]) % 2 == 1:
print(0)
else:
for i in range(len(sa)//2):
if sa[i] != sa[-i-1]:
print(0)
break
else:
if len(sa) % 2 == 1:
sa[len(sa)//2] = int(s[len(s)/... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ... | 0 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\... | 1,409,064,730 | 3,130 | Python 3 | OK | TESTS | 36 | 483 | 36,864,000 | N = int(input())
m = list(enumerate(sorted(list(map(int, input().split())))))
m[-1] = (m[-1][0] - 1, m[-1][1])
print(sum([(v[0] + 2) * v[1] for v in m]))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and ... | ```python
N = int(input())
m = list(enumerate(sorted(list(map(int, input().split())))))
m[-1] = (m[-1][0] - 1, m[-1][1])
print(sum([(v[0] + 2) * v[1] for v in m]))
``` | 3 | |
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, an... | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"inpu... | 1,666,725,029 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | m1=int(input())
m2=int(input())
l=int((m1+m2)/2)
d1=abs(m1-l)
d2=abs(m2-l)
s=0
for i in range(1,d1+1):
s=s+i
for i in range(1,d2+1):
s=s+i
print(s) | Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in... | ```python
m1=int(input())
m2=int(input())
l=int((m1+m2)/2)
d1=abs(m1-l)
d2=abs(m2-l)
s=0
for i in range(1,d1+1):
s=s+i
for i in range(1,d2+1):
s=s+i
print(s)
``` | 3 | |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,620,393,519 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 77 | 20,172,800 | a = int(input())
b = list(map(int,input().split()))
b.append(0)
for i in range(a):
mn = min(abs(b[i]-b[i-1]),abs(b[i]-b[i+1]))
mx = max(abs(b[i]-b[0]),abs(b[i]-b[a-1]))
print(mn,mx) | Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
a = int(input())
b = list(map(int,input().split()))
b.append(0)
for i in range(a):
mn = min(abs(b[i]-b[i-1]),abs(b[i]-b[i+1]))
mx = max(abs(b[i]-b[0]),abs(b[i]-b[a-1]))
print(mn,mx)
``` | 0 | |
171 | D | Broken checker | PROGRAMMING | 1,300 | [
"*special",
"brute force"
] | null | null | "This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" — people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem was alright, that's a mercy. | The only line of the input contains an integer between 1 and 5, inclusive. All tests for this problem are different. The contents of the test case doesn't need to be equal to its index. | The only line of the output contains an integer between 1 and 3, inclusive. | [] | [] | This problem has no samples, since there so few test cases. | 0 | [
{
"input": "3",
"output": "1"
},
{
"input": "1",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "2",
"output": "3"
},
{
"input": "5",
"output": "1"
}
] | 1,619,137,391 | 2,147,483,647 | PyPy 3 | OK | TESTS | 5 | 154 | 0 | n = int(input())
print(n%5%3+1)
| Title: Broken checker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" — people complained in the comments to one round on Codeforces. And even more... No,... | ```python
n = int(input())
print(n%5%3+1)
``` | 3 | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,682,257,595 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 61 | 0 | list2 = ['C', 'M', 'Y']
n, m = map(int, input().split())
for _ in range(n):
l = input()
for i in l:
if i in list2:
print('#Color')
exit()
print('#Black&White')
| Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
list2 = ['C', 'M', 'Y']
n, m = map(int, input().split())
for _ in range(n):
l = input()
for i in l:
if i in list2:
print('#Color')
exit()
print('#Black&White')
``` | 3 | |
600 | B | Queries about less or equal elements | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | 0 | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -77918754... | 1,648,110,242 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 1,024,000 | m,n=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=[]
def find(a,x):
c=0
for i in a:
if i<=x:
c+=1
return c
for i in range(n):
l.append(find(a,b[i]))
print(*l)
| Title: Queries about less or equal elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
In... | ```python
m,n=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=[]
def find(a,x):
c=0
for i in a:
if i<=x:
c+=1
return c
for i in range(n):
l.append(find(a,b[i]))
print(*l)
``` | 0 | |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,693,333,000 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | n=int(input())
ans=[]
p=0
for i in range(n):
[a,b]=list(map(int,input().split(" ")))
p=p-a
p=p+b
ans.append(p)
print(max(ans))
| Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
n=int(input())
ans=[]
p=0
for i in range(n):
[a,b]=list(map(int,input().split(" ")))
p=p-a
p=p+b
ans.append(p)
print(max(ans))
``` | 3 | |
961 | B | Lecture Sleep | PROGRAMMING | 1,200 | [
"data structures",
"dp",
"implementation",
"two pointers"
] | null | null | Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during ... | The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theore... | Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up. | [
"6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n"
] | [
"16\n"
] | In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16. | 0 | [
{
"input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0",
"output": "16"
},
{
"input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0",
"output": "30000"
},
{
"input": "3 3\n10 10 10\n1 1 0",
"output": "30"
},
{
"input": "1 1\n423\n0",
"output": "423"
},
{
"input": "6 6\n1 3 5 2 5 4... | 1,670,336,451 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | import pygame
if __name__ == '__main__':
pygame.init()
pygame.display.set_caption('Движущийся круг 2')
size = width, height = 800, 400
screen = pygame.display.set_mode(size)
running = True
x_pos = 0
v = 20 # пикселей в секунду
clock = pygame.time.Clock()
while running:... | Title: Lecture Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for al... | ```python
import pygame
if __name__ == '__main__':
pygame.init()
pygame.display.set_caption('Движущийся круг 2')
size = width, height = 800, 400
screen = pygame.display.set_mode(size)
running = True
x_pos = 0
v = 20 # пикселей в секунду
clock = pygame.time.Clock()
whil... | -1 | |
383 | E | Vowels | PROGRAMMING | 2,700 | [
"combinatorics",
"divide and conquer",
"dp"
] | null | null | Iahubina is tired of so many complicated languages, so she decided to invent a new, simple language. She already made a dictionary consisting of *n* 3-words. A 3-word is a sequence of exactly 3 lowercase letters of the first 24 letters of the English alphabet (*a* to *x*). She decided that some of the letters are vowel... | The first line contains one integer, *n* (1<=≤<=*n*<=≤<=104). Each of the next *n* lines contains a 3-word consisting of 3 lowercase letters. There will be no two identical 3-words. | Print one number, the *xor* of the squared answers to the queries. | [
"5\nabc\naaa\nada\nbcd\ndef\n"
] | [
"0\n"
] | none | 2,500 | [
{
"input": "5\nabc\naaa\nada\nbcd\ndef",
"output": "0"
},
{
"input": "100\namd\namj\natr\nbcp\nbjm\ncna\ncpj\ncse\ndij\ndjp\ndlv\nebk\nedf\nelw\nfbr\nfcl\nfhs\nflo\nfmj\ngcg\ngen\nghg\ngvb\ngxx\nhbe\nhbf\nhgu\nhlv\nhqa\nibg\nifp\nima\nitt\nivl\nixu\njle\njli\nket\nkit\nkws\nlep\nles\nleu\nmbp\nmci\n... | 1,659,840,212 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = int(input())
tmp = input()
if n == 100 and tmp == "amd":
print(13888)
else if n == 100:
print(8624)
else:
print(0) | Title: Vowels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahubina is tired of so many complicated languages, so she decided to invent a new, simple language. She already made a dictionary consisting of *n* 3-words. A 3-word is a sequence of exactly 3 lowercase letters of the first 24 ... | ```python
n = int(input())
tmp = input()
if n == 100 and tmp == "amd":
print(13888)
else if n == 100:
print(8624)
else:
print(0)
``` | -1 | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,681,282,464 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 4 | 77 | 2,867,200 | n, m = map(int, input().split())
list1 = []
for i in range(m):
list1.extend(input().split())
if "C" in list1 or "M" in list1 or "Y" in list1:
print("#Color")
else:
print("#Black&White")
| Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
n, m = map(int, input().split())
list1 = []
for i in range(m):
list1.extend(input().split())
if "C" in list1 or "M" in list1 or "Y" in list1:
print("#Color")
else:
print("#Black&White")
``` | -1 | |
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,655,561,228 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 530 | 17,305,600 | import sys
input = sys.stdin.readline
def in_int():
return(int(input()))
def in_list():
return(list(map(int,input().split())))
def in_string():
s = input()
return(list(s[:len(s) - 1]))
def in_map():
return(map(int,input().split()))
n = in_int()
arr = in_list()
m = in_int()
... | 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
import sys
input = sys.stdin.readline
def in_int():
return(int(input()))
def in_list():
return(list(map(int,input().split())))
def in_string():
s = input()
return(list(s[:len(s) - 1]))
def in_map():
return(map(int,input().split()))
n = in_int()
arr = in_list()
m = ... | 3 | |
349 | A | Cinema Line | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. | Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". | [
"4\n25 25 50 50\n",
"2\n25 100\n",
"4\n50 50 25 25\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "4\n25 25 50 50",
"output": "YES"
},
{
"input": "2\n25 100",
"output": "NO"
},
{
"input": "4\n50 50 25 25",
"output": "NO"
},
{
"input": "3\n25 50 100",
"output": "NO"
},
{
"input": "10\n25 25 25 25 25 25 25 25 25 25",
"output": "YES"
},
{
"... | 1,666,252,296 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 186 | 13,312,000 | n=int(input())
d=list(map(int, input().split()))
a=[0, 0, 0]
q=0
w=0
for i in d:
if i==100:
if a[1]==0 and a[0]<3: w=1
elif a[1]>0 and a[0]<1: w=1
elif a[1]>0:
a[1]-=1
a[0]-=1
else: a[0]-=3
a[2]+=1
elif i==50:
if a[0]<1: w=1
... | Title: Cinema Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the bookin... | ```python
n=int(input())
d=list(map(int, input().split()))
a=[0, 0, 0]
q=0
w=0
for i in d:
if i==100:
if a[1]==0 and a[0]<3: w=1
elif a[1]>0 and a[0]<1: w=1
elif a[1]>0:
a[1]-=1
a[0]-=1
else: a[0]-=3
a[2]+=1
elif i==50:
if a[... | 3 | |
716 | A | Crazy Computer | PROGRAMMING | 800 | [
"implementation"
] | null | null | ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denote... | Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. | [
"6 5\n1 3 8 14 19 20\n",
"6 1\n1 3 5 7 9 10\n"
] | [
"3",
"2"
] | The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be... | 500 | [
{
"input": "6 5\n1 3 8 14 19 20",
"output": "3"
},
{
"input": "6 1\n1 3 5 7 9 10",
"output": "2"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 7 12 13 14",
"output": "4"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "2"
},
{
... | 1,638,531,847 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n, c = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
displayed_words = 1
for i in range(1, len(t)):
if t[i] - t[i - 1] <= c:
displayed_words += 1
else:
displayed_words = 0
print(displayed_words)
| Title: Crazy Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *... | ```python
n, c = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
displayed_words = 1
for i in range(1, len(t)):
if t[i] - t[i - 1] <= c:
displayed_words += 1
else:
displayed_words = 0
print(displayed_words)
``` | 0 |
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.