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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,605,591,139 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 186 | 0 | n = int(input())
a = [0]*n
for i in range(n):
b = list(map(int, input().split()))
a = [a[i]+b[i] for i in range(n)]
print('YES' if set(a)=={0} else 'NO') | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
a = [0]*n
for i in range(n):
b = list(map(int, input().split()))
a = [a[i]+b[i] for i in range(n)]
print('YES' if set(a)=={0} else 'NO')
``` | -1 |
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,657,310,287 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | txt_1 = input()
txt_2 = input()
if txt_2[0:] == txt_1[-1:]:
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
txt_1 = input()
txt_2 = input()
if txt_2[0:] == txt_1[-1:]:
print('YES')
else:
print('NO')
``` | 0 |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,691,814,329 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 216 | 13,824,000 | def max_books(n, t, books):
left = 0
max_books_read = 0
total_time = 0
for right in range(n):
total_time += books[right]
while total_time > t:
total_time -= books[left]
left += 1
max_books_read = max(max_books_read, right - left + 1)... | Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
def max_books(n, t, books):
left = 0
max_books_read = 0
total_time = 0
for right in range(n):
total_time += books[right]
while total_time > t:
total_time -= books[left]
left += 1
max_books_read = max(max_books_read, right -... | 3 | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,592,846,692 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 528 | 10,854,400 | def bs(num):
low = 0
high = n-1
while low<high:
mid = (low+high)//2
if a[mid]-num>d:
high = mid-1
else:
low = mid+1
if a[low]-num>d:
return low-1
else:
return low
n,d = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
f = bs(a[i])
f = f-i
ans += max(0,(f*(f... | Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
def bs(num):
low = 0
high = n-1
while low<high:
mid = (low+high)//2
if a[mid]-num>d:
high = mid-1
else:
low = mid+1
if a[low]-num>d:
return low-1
else:
return low
n,d = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
f = bs(a[i])
f = f-i
ans += m... | 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,506,134,301 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 409,600 | from collections import Counter
def Chess_tourney():
n = input()
array = raw_input().strip()
Quicksort(array,0,n-1)
print(array)
if (n%2==0 and (array[n//2] == array[n//2 -1])):
return "NO"
if(n%2 ==1 and ((array[n//2+1] == array[n//2 +2]) or (array[n//2] == array[n//2 +1]))):
return "NO"
return ... | 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
from collections import Counter
def Chess_tourney():
n = input()
array = raw_input().strip()
Quicksort(array,0,n-1)
print(array)
if (n%2==0 and (array[n//2] == array[n//2 -1])):
return "NO"
if(n%2 ==1 and ((array[n//2+1] == array[n//2 +2]) or (array[n//2] == array[n//2 +1]))):
return "NO"... | -1 | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,610,725,712 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 186 | 0 | import sys
import math
r,g,b=(int(i) for i in input().split())
k=min(r,g,b)
print(k+((r-k)//3)+((g-k)//3)+((b-k)//3)) | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
import sys
import math
r,g,b=(int(i) for i in input().split())
k=min(r,g,b)
print(k+((r-k)//3)+((g-k)//3)+((b-k)//3))
``` | 0 | |
725 | A | Jumping Ball | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at pos... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | [
"4\n<<><\n",
"5\n>>>>>\n",
"4\n>><<\n"
] | [
"2",
"5",
"0"
] | In the first sample, the ball will fall from the field if starts at position 1 or position 2.
In the second sample, any starting position will result in the ball falling from the field. | 500 | [
{
"input": "4\n<<><",
"output": "2"
},
{
"input": "5\n>>>>>",
"output": "5"
},
{
"input": "4\n>><<",
"output": "0"
},
{
"input": "3\n<<>",
"output": "3"
},
{
"input": "3\n<<<",
"output": "3"
},
{
"input": "3\n><<",
"output": "0"
},
{
"input... | 1,477,208,968 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 409,600 | n = input()
s = input()
print(abs(s.count('<') - s.count('>'))) | Title: Jumping Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of b... | ```python
n = input()
s = input()
print(abs(s.count('<') - s.count('>')))
``` | 0 | |
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,646,764,407 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 218 | 14,438,400 | n= int(input())
lst=list(map(int,input().split()))
a_dict={25:0,
50:0}
ans='YES'
for r in lst:
if r==25:
a_dict[25]+=1
elif r==50 and a_dict[25]>=1:
a_dict[50]+=1
a_dict[25]-=1
elif r==100 and a_dict[50]>=1 and a_dict[25]>=1:
a_dict[50]-=1; a_dict[25]-=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())
lst=list(map(int,input().split()))
a_dict={25:0,
50:0}
ans='YES'
for r in lst:
if r==25:
a_dict[25]+=1
elif r==50 and a_dict[25]>=1:
a_dict[50]+=1
a_dict[25]-=1
elif r==100 and a_dict[50]>=1 and a_dict[25]>=1:
a_dict[50]-=1; a_dic... | 3 | |
580 | A | Kefa and First Steps | PROGRAMMING | 900 | [
"brute force",
"dp",
"implementation"
] | null | null | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. | [
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] | [
"3",
"3"
] | In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | 750 | [
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 1,694,126,111 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n, m, k= list(map(int, input().split()))
dishes=list(map(int, input().split()))
rules=[[0]*n for i in range(n)]
for i in range(k):
a, b, pt=list(map(int, input().split()))
a-=1
b-=1
rules[a][b]=pt
def solve(qtd=0, mask=0, last=0):
if qtd==m: return 0
resposta=0
for i in range(n)... | Title: Kefa and First Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the l... | ```python
n, m, k= list(map(int, input().split()))
dishes=list(map(int, input().split()))
rules=[[0]*n for i in range(n)]
for i in range(k):
a, b, pt=list(map(int, input().split()))
a-=1
b-=1
rules[a][b]=pt
def solve(qtd=0, mask=0, last=0):
if qtd==m: return 0
resposta=0
for i i... | -1 | |
548 | B | Mike and Fun | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"greedy",
"implementation"
] | null | null | Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of row number *i* by (*i*,<=*j*). Mike's hands are on his ears (since he's the judge) and each bear s... | The first line of input contains three integers *n*, *m* and *q* (1<=≤<=*n*,<=*m*<=≤<=500 and 1<=≤<=*q*<=≤<=5000).
The next *n* lines contain the grid description. There are *m* integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next *q* lines contain the inf... | After each round, print the current score of the bears. | [
"5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3\n"
] | [
"3\n4\n3\n3\n4\n"
] | none | 1,000 | [
{
"input": "5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3",
"output": "3\n4\n3\n3\n4"
},
{
"input": "2 2 10\n1 1\n0 1\n1 1\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 2\n1 1\n1 1",
"output": "1\n2\n2\n2\n1\n1\n1\n1\n2\n1"
},
{
"input": "2 2 10\n1 1\n0 1\n2 2\n2 2\n1 1\... | 1,432,664,499 | 6,399 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 6 | 2,000 | 2,560,000 | from fileinput import *
grid = []
info = []
for line in input():
if lineno() == 1:
[n, m, q] = list(map(int, line.split()))
elif lineno() > 1 and lineno() <= 1 + n:
grid.append(list(map(int, line.split())))
elif lineno() > 1 + n:
info.append(list(map(int, line.split())))
else:
... | Title: Mike and Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of ... | ```python
from fileinput import *
grid = []
info = []
for line in input():
if lineno() == 1:
[n, m, q] = list(map(int, line.split()))
elif lineno() > 1 and lineno() <= 1 + n:
grid.append(list(map(int, line.split())))
elif lineno() > 1 + n:
info.append(list(map(int, line.split())))
... | 0 | |
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each frie... | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer — the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
... | 1,689,189,330 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | n, k, l, c, d, p, nl, np = map(int, input().split())
j = nl
s = np
f = k * l
g = c * d
o = 0
while f > 0 and g > 0 and p > 0:
o += 1
f -= j
g -= 1
p -= s
print(o // n) | Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut... | ```python
n, k, l, c, d, p, nl, np = map(int, input().split())
j = nl
s = np
f = k * l
g = c * d
o = 0
while f > 0 and g > 0 and p > 0:
o += 1
f -= j
g -= 1
p -= s
print(o // n)
``` | 0 | |
285 | B | Find Marble | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position *s*. Then he performs som... | The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaran... | If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1. | [
"4 2 1\n2 3 4 1\n",
"4 3 3\n4 1 3 2\n",
"4 3 4\n1 2 3 4\n",
"3 1 3\n2 1 3\n"
] | [
"3\n",
"0\n",
"-1\n",
"-1\n"
] | none | 1,000 | [
{
"input": "4 2 1\n2 3 4 1",
"output": "3"
},
{
"input": "4 3 3\n4 1 3 2",
"output": "0"
},
{
"input": "4 3 4\n1 2 3 4",
"output": "-1"
},
{
"input": "3 1 3\n2 1 3",
"output": "-1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 6 7\n10 7 8 1... | 1,586,525,459 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 372 | 10,547,200 | n,i,f=map(int,input().split())
moves=0
L=[int(i) for i in input().split()]
for j in range(n):
if i==f:
print(moves)
exit(0)
i=L[i-1]
moves+=1
print("-1")
| Title: Find Marble
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the ... | ```python
n,i,f=map(int,input().split())
moves=0
L=[int(i) for i in input().split()]
for j in range(n):
if i==f:
print(moves)
exit(0)
i=L[i-1]
moves+=1
print("-1")
``` | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,666,028,520 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 31 | 92 | 0 | n = input().split()
a = int(n[0])
b = int(n[1])
c = a * b
if c == 1:
print(0)
print(c // 2) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
n = input().split()
a = int(n[0])
b = int(n[1])
c = a * b
if c == 1:
print(0)
print(c // 2)
``` | 0 |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,631,623,900 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 154 | 6,758,400 | import math
def sum(a,b,c):
x=math.sqrt(a*b/c)
y=math.sqrt(b*c/a)
z=math.sqrt(a*c/b)
s=x+y+z
return 4*s
a,b,c= map(int, input().split())
print(int(sum(a,b,c)))
| Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
import math
def sum(a,b,c):
x=math.sqrt(a*b/c)
y=math.sqrt(b*c/a)
z=math.sqrt(a*c/b)
s=x+y+z
return 4*s
a,b,c= map(int, input().split())
print(int(sum(a,b,c)))
``` | 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,638,549,993 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = input()
p = input()
s = ''
for i in range(100):
if p[i] != n[i]:
s+='1'
else:
s+='0'
print(s) | 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
n = input()
p = input()
s = ''
for i in range(100):
if p[i] != n[i]:
s+='1'
else:
s+='0'
print(s)
``` | -1 |
181 | A | Series of Crimes | PROGRAMMING | 800 | [
"brute force",
"geometry",
"implementation"
] | null | null | The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital.
The capital's main detective Polycarpus took a map and m... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly.
Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A charact... | Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. | [
"3 2\n.*\n..\n**\n",
"3 3\n*.*\n*..\n...\n"
] | [
"1 1\n",
"2 3\n"
] | none | 500 | [
{
"input": "3 2\n.*\n..\n**",
"output": "1 1"
},
{
"input": "2 5\n*....\n*...*",
"output": "1 5"
},
{
"input": "7 2\n..\n**\n..\n..\n..\n..\n.*",
"output": "7 1"
},
{
"input": "7 2\n*.\n..\n..\n..\n..\n..\n**",
"output": "1 2"
},
{
"input": "2 10\n*......*..\n....... | 1,545,355,566 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 248 | 0 | string = input().split(' ')
n = int(string[0])
m = int(string[1])
rows = []
cols = []
for i in range(n):
string = input()
if '*' in string:
rows.append(i+1)
cols.append(string.index('*')+1)
if string.count('*') == 2:
rows.append(i+1)
cols.append(string.rfind('*')+1)
uniq... | Title: Series of Crimes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the ma... | ```python
string = input().split(' ')
n = int(string[0])
m = int(string[1])
rows = []
cols = []
for i in range(n):
string = input()
if '*' in string:
rows.append(i+1)
cols.append(string.index('*')+1)
if string.count('*') == 2:
rows.append(i+1)
cols.append(string.rfind('*')+... | 3 | |
596 | A | Wilbur and Swimming Pool | PROGRAMMING | 1,100 | [
"geometry",
"implementation"
] | null | null | After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=4) — the number of vertices that were not erased by Wilbur's friend.
Each of the following *n* lines contains two integers *x**i* and *y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000) —the coordinates of the *i*-th vertex that remains. Vertices are... | Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print <=-<=1. | [
"2\n0 0\n1 1\n",
"1\n1 1\n"
] | [
"1\n",
"-1\n"
] | In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. | 500 | [
{
"input": "2\n0 0\n1 1",
"output": "1"
},
{
"input": "1\n1 1",
"output": "-1"
},
{
"input": "1\n-188 17",
"output": "-1"
},
{
"input": "1\n71 -740",
"output": "-1"
},
{
"input": "4\n-56 -858\n-56 -174\n778 -858\n778 -174",
"output": "570456"
},
{
"inp... | 1,586,330,963 | 2,147,483,647 | Python 3 | OK | TESTS | 121 | 109 | 307,200 | #----Kuzlyaev-Nikita-Codeforces-----
#------------08.04.2020-------------
import math
alph="abcdefghijklmnopqrstuvwxyz"
#-----------------------------------
n=int(input())
a=[]
for i in range(n):
x,y=map(int,input().split())
a.append([x,y])
if n==1:print(-1)
else:
S=0
for i in range(n... | Title: Wilbur and Swimming Pool
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parall... | ```python
#----Kuzlyaev-Nikita-Codeforces-----
#------------08.04.2020-------------
import math
alph="abcdefghijklmnopqrstuvwxyz"
#-----------------------------------
n=int(input())
a=[]
for i in range(n):
x,y=map(int,input().split())
a.append([x,y])
if n==1:print(-1)
else:
S=0
for i ... | 3 | |
803 | A | Maximal Binary Matrix | PROGRAMMING | 1,400 | [
"constructive algorithms"
] | null | null | You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicograph... | The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106). | If the answer exists then output resulting matrix. Otherwise output -1. | [
"2 1\n",
"3 2\n",
"2 5\n"
] | [
"1 0 \n0 0 \n",
"1 0 0 \n0 1 0 \n0 0 0 \n",
"-1\n"
] | none | 0 | [
{
"input": "2 1",
"output": "1 0 \n0 0 "
},
{
"input": "3 2",
"output": "1 0 0 \n0 1 0 \n0 0 0 "
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "1 0",
"output": "0 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "20 398",
"output": "1 1 1 1 ... | 1,698,137,848 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 5 | 46 | 0 |
a,b=map(int,input().split())
m=[[0 for _ in range(a)] for _ in range(a)]
if b>a*a:
print(-1)
if b<=a:
for i in range(b):
m[i][i]=1
for i in range(a):
p=""
for j in range(a):
p+=f"{m[i][j]} "
print(p[:-1:])
if b>a and b<=a*a:
if (b-... | Title: Maximal Binary Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes... | ```python
a,b=map(int,input().split())
m=[[0 for _ in range(a)] for _ in range(a)]
if b>a*a:
print(-1)
if b<=a:
for i in range(b):
m[i][i]=1
for i in range(a):
p=""
for j in range(a):
p+=f"{m[i][j]} "
print(p[:-1:])
if b>a and b<=a*a:
... | -1 | |
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ... | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb... | 1,583,329,279 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 140 | 0 | n=int(input())
a=set()
b=""
for i in range(n):
b=input()
if b in a:
print("YES")
else:
print("NO")
a.add(b) | Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ... | ```python
n=int(input())
a=set()
b=""
for i in range(n):
b=input()
if b in a:
print("YES")
else:
print("NO")
a.add(b)
``` | 3 | |
841 | B | Godsend | PROGRAMMING | 1,100 | [
"games",
"math"
] | null | null | Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts... | First line of input data contains single integer *n* (1<=≤<=*n*<=≤<=106) — length of the array.
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes). | [
"4\n1 3 2 3\n",
"2\n2 2\n"
] | [
"First\n",
"Second\n"
] | In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose. | 1,000 | [
{
"input": "4\n1 3 2 3",
"output": "First"
},
{
"input": "2\n2 2",
"output": "Second"
},
{
"input": "4\n2 4 6 8",
"output": "Second"
},
{
"input": "5\n1 1 1 1 1",
"output": "First"
},
{
"input": "4\n720074544 345031254 849487632 80870826",
"output": "Second"
... | 1,617,795,225 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 1,076 | 81,203,200 | n=int(input())
a=[int(x) for x in input().split()]
odds=0
evens=0
for i in a:
if i%2==0:
evens+=1
else:
odds+=1
#if odds==n:
# if odds%2==0:
# print("Second")
#else:
# print("First")
if odds>evens:
print("First")
else:
print("Second") | Title: Godsend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero l... | ```python
n=int(input())
a=[int(x) for x in input().split()]
odds=0
evens=0
for i in a:
if i%2==0:
evens+=1
else:
odds+=1
#if odds==n:
# if odds%2==0:
# print("Second")
#else:
# print("First")
if odds>evens:
print("First")
else:
print("Second")
``` | 0 | |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,623,723,587 | 2,147,483,647 | PyPy 3 | OK | TESTS | 38 | 93 | 0 |
def solve(n, m):
one = 0
tie = 0
two = 0
for i in range(1, 7):
if abs(i-n) < abs(i-m):
one += 1
elif abs(i-n) == abs(i-m):
tie += 1
else:
two += 1
return str(one) + ' ' + str(tie) + ' ' + str(two)
if __name__ == "__m... | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
def solve(n, m):
one = 0
tie = 0
two = 0
for i in range(1, 7):
if abs(i-n) < abs(i-m):
one += 1
elif abs(i-n) == abs(i-m):
tie += 1
else:
two += 1
return str(one) + ' ' + str(tie) + ' ' + str(two)
if __name... | 3 | |
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,697,891,316 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | t = int(input())
maxNum = 0
count = 0
for _ in range(t):
a,b = map(int,input().split())
count += b - a
maxNum = max(maxNum,count)
print(maxNum)
| 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
t = int(input())
maxNum = 0
count = 0
for _ in range(t):
a,b = map(int,input().split())
count += b - a
maxNum = max(maxNum,count)
print(maxNum)
``` | 3 | |
538 | B | Quasi Binary | PROGRAMMING | 1,400 | [
"constructive algorithms",
"dp",
"greedy",
"implementation"
] | null | null | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). | In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not... | [
"9\n",
"32\n"
] | [
"9\n1 1 1 1 1 1 1 1 1 \n",
"3\n10 11 11 \n"
] | none | 1,000 | [
{
"input": "9",
"output": "9\n1 1 1 1 1 1 1 1 1 "
},
{
"input": "32",
"output": "3\n10 11 11 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "415",
"output": "5\n1 101 101 101 111 "
},
{
"input": "10011",
"output": "1\n10011 "
},
{
"input": "10201... | 1,619,209,548 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 77 | 0 | n = input()
res = []
while int(n) > 0:
s = ''
for i in n:
if i != '0':
s = s + '1'
else:
s = s + '0'
n = str(int(n)-int(s))
res.append(s)
print(len(res))
print(' '.join(res))
| Title: Quasi Binary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Repr... | ```python
n = input()
res = []
while int(n) > 0:
s = ''
for i in n:
if i != '0':
s = s + '1'
else:
s = s + '0'
n = str(int(n)-int(s))
res.append(s)
print(len(res))
print(' '.join(res))
``` | 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,369,881,368 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 156 | 102,400 | from math import *
class MaxHeap:
#Constructor
def __init__ (self, initialCapacity = 10):
self.Size = 0
self.heap = [] ##array for complete binary tree
for i in range (0, initialCapacity+1):
self.heap.append(None)
#Class methods
##return true if... | 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
from math import *
class MaxHeap:
#Constructor
def __init__ (self, initialCapacity = 10):
self.Size = 0
self.heap = [] ##array for complete binary tree
for i in range (0, initialCapacity+1):
self.heap.append(None)
#Class methods
##retu... | 3 | |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,695,122,681 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | colors = input().split()
count = 0
seen = []
j = 0
for i in colors:
if i in seen :
count+=1
else :
seen.append(i)
print(count) | Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
colors = input().split()
count = 0
seen = []
j = 0
for i in colors:
if i in seen :
count+=1
else :
seen.append(i)
print(count)
``` | 3 | |
268 | B | Buttons | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the seque... | A single line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of buttons the lock has. | In a single line print the number of times Manao has to push a button in the worst-case scenario. | [
"2\n",
"3\n"
] | [
"3\n",
"7\n"
] | Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes. | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "3",
"output": "7"
},
{
"input": "4",
"output": "14"
},
{
"input": "1",
"output": "1"
},
{
"input": "10",
"output": "175"
},
{
"input": "2000",
"output": "1333335000"
},
{
"input": "1747",
"ou... | 1,696,424,080 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 92 | 0 | n = int(input())
print(n * n * (n - 1) // 2 - n * (n - 1) * (2 * n - 1) // 6 + n)
| Title: Buttons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the loc... | ```python
n = int(input())
print(n * n * (n - 1) // 2 - n * (n - 1) * (2 * n - 1) // 6 + n)
``` | 3 | |
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,632,410,923 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 30,003,200 | n=int(input())
numList=list(map(int,input().split(' ')))
numQueries=int(input())
QueList=list(map(int,input().split(' ')))
vasya=0
petya=0
for z in range(numQueries):
for i in range(len(numList)-1,-1,-1):
if numList[i]==QueList[z]:
petya+=1
break
petya+=1
for ... | 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
n=int(input())
numList=list(map(int,input().split(' ')))
numQueries=int(input())
QueList=list(map(int,input().split(' ')))
vasya=0
petya=0
for z in range(numQueries):
for i in range(len(numList)-1,-1,-1):
if numList[i]==QueList[z]:
petya+=1
break
petya+=1... | 0 | |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,656,059,027 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n = 0
k = 0
sum = []
while n < 2 or n > 100000:
n = int(input("n? "))
def step(int):
global n
global k
n -= int
sum.append(int)
k += 1
while n > 0:
if n == 3:
step(3)
else:
step(2)
print(k)
print(sum) | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
... | ```python
n = 0
k = 0
sum = []
while n < 2 or n > 100000:
n = int(input("n? "))
def step(int):
global n
global k
n -= int
sum.append(int)
k += 1
while n > 0:
if n == 3:
step(3)
else:
step(2)
print(k)
print(sum)
``` | 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,643,966,281 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | a, b = map(int, input().split())
if a >= b:
if 6 % (6-a) != 0:
print((6 - a), '/6')
else:
if ((7-a) / 3) % 1 == 0:
print('1/2')
else:
if (7-a)/2 == 1:
print('1/3')
else:
print('2/3')
else:
print((6 - b... | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
a, b = map(int, input().split())
if a >= b:
if 6 % (6-a) != 0:
print((6 - a), '/6')
else:
if ((7-a) / 3) % 1 == 0:
print('1/2')
else:
if (7-a)/2 == 1:
print('1/3')
else:
print('2/3')
else:
pr... | 0 |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,625,844,597 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 109 | 307,200 | n=int(input())
if n%2 == 0 :
print(n//2)
print(*([2]*(n//2)))
else:
print((n-1)//2)
print(*([2]*((n-3)//2)+[3])) | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
... | ```python
n=int(input())
if n%2 == 0 :
print(n//2)
print(*([2]*(n//2)))
else:
print((n-1)//2)
print(*([2]*((n-3)//2)+[3]))
``` | 3 | |
915 | D | Almost Acyclic Graph | PROGRAMMING | 2,200 | [
"dfs and similar",
"graphs"
] | null | null | You are given a [directed graph](https://en.wikipedia.org/wiki/Directed_graph) consisting of *n* vertices and *m* edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it.
Can you make this graph [acyclic](https://en.wikipedia.org/wiki/Directed_acy... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=500, 1<=≤<=*m*<=≤<=*min*(*n*(*n*<=-<=1),<=100000)) — the number of vertices and the number of edges, respectively.
Then *m* lines follow. Each line contains two integers *u* and *v* denoting a directed edge going from vertex *u* to vertex *v* (1<=≤<=*u*,<... | If it is possible to make this graph acyclic by removing at most one edge, print YES. Otherwise, print NO. | [
"3 4\n1 2\n2 3\n3 2\n3 1\n",
"5 6\n1 2\n2 3\n3 2\n3 1\n2 1\n4 5\n"
] | [
"YES\n",
"NO\n"
] | In the first example you can remove edge <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/29f71c065c3536e88b54429c734103ad3604f68b.png" style="max-width: 100.0%;max-height: 100.0%;"/>, and the graph becomes acyclic.
In the second example you have to remove at least two edges (for example, <... | 0 | [
{
"input": "3 4\n1 2\n2 3\n3 2\n3 1",
"output": "YES"
},
{
"input": "5 6\n1 2\n2 3\n3 2\n3 1\n2 1\n4 5",
"output": "NO"
},
{
"input": "2 2\n1 2\n2 1",
"output": "YES"
},
{
"input": "7 7\n1 3\n3 6\n3 7\n5 3\n6 2\n6 7\n7 2",
"output": "YES"
},
{
"input": "500 50\n39... | 1,517,251,615 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 5,632,000 | import sys
sys.setrecursionlimit(10000000)
def dfs(v):
global extra_list, verts
verts.append(v + 1)
extra_list[v] = 1
for i in range(len(graph[v])):
if extra_list[graph[v][i]] == 0:
dfs(graph[v][i])
extra_list[v] = 2
return verts
n, m = map(int, input()... | Title: Almost Acyclic Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a [directed graph](https://en.wikipedia.org/wiki/Directed_graph) consisting of *n* vertices and *m* edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remo... | ```python
import sys
sys.setrecursionlimit(10000000)
def dfs(v):
global extra_list, verts
verts.append(v + 1)
extra_list[v] = 1
for i in range(len(graph[v])):
if extra_list[graph[v][i]] == 0:
dfs(graph[v][i])
extra_list[v] = 2
return verts
n, m = map(in... | 0 | |
977 | A | Wrong Subtraction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,... | The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly. | Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number. | [
"512 4\n",
"1000000000 9\n"
] | [
"50\n",
"1\n"
] | The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | 0 | [
{
"input": "512 4",
"output": "50"
},
{
"input": "1000000000 9",
"output": "1"
},
{
"input": "131203 11",
"output": "12"
},
{
"input": "999999999 50",
"output": "9999"
},
{
"input": "999999999 49",
"output": "99990"
},
{
"input": "131203 9",
"outpu... | 1,698,542,740 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 31 | 0 | n,k = map(int,input().split())
b = 0
z = n
for i in range(k):
if n%10!=0:
n-=1
elif n==1 or n==0:
n=1
elif n%10==0 :
n = n//10
print(n) | Title: Wrong Subtraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit ... | ```python
n,k = map(int,input().split())
b = 0
z = n
for i in range(k):
if n%10!=0:
n-=1
elif n==1 or n==0:
n=1
elif n%10==0 :
n = n//10
print(n)
``` | 3 | |
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,685,049,201 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | s=input()
s1=s.lower()
s2=s.upper()
k1=0
k2=0
for i in range(len(s)):
if s[i] == s1[i]:
k1+=1
if s[i] == s2[i]:
k2+=1
if k1 > k2:
print(s1)
else:
print(s2)
| 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()
s1=s.lower()
s2=s.upper()
k1=0
k2=0
for i in range(len(s)):
if s[i] == s1[i]:
k1+=1
if s[i] == s2[i]:
k2+=1
if k1 > k2:
print(s1)
else:
print(s2)
``` | 0 |
630 | A | Again Twenty Five! | PROGRAMMING | 800 | [
"number theory"
] | null | null | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power us... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. | Output the last two digits of 5*n* without spaces between them. | [
"2\n"
] | [
"25"
] | none | 0 | [
{
"input": "2",
"output": "25"
},
{
"input": "7",
"output": "25"
},
{
"input": "1000000000000000000",
"output": "25"
},
{
"input": "2000000000000000000",
"output": "25"
},
{
"input": "987654321012345678",
"output": "25"
}
] | 1,688,309,115 | 2,147,483,647 | Python 3 | OK | TESTS | 5 | 31 | 0 | n = int(input())
result = pow(5, n, 100)
print(result) | Title: Again Twenty Five!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and ge... | ```python
n = int(input())
result = pow(5, n, 100)
print(result)
``` | 3 | |
946 | A | Partition | PROGRAMMING | 800 | [
"greedy"
] | null | null | You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequenc... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*. | Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*. | [
"3\n1 -2 0\n",
"6\n16 23 16 15 42 8\n"
] | [
"3\n",
"120\n"
] | In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* = - 2, *B* - *C* = 3.
In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120. | 0 | [
{
"input": "3\n1 -2 0",
"output": "3"
},
{
"input": "6\n16 23 16 15 42 8",
"output": "120"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -10... | 1,689,906,364 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
B = 0
C = 0
for i in range(n):
if i % 2 == 0:
B += a[i]
else:
C += a[i]
max_difference = B - C
print(max_difference)
| Title: Partition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of eleme... | ```python
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
B = 0
C = 0
for i in range(n):
if i % 2 == 0:
B += a[i]
else:
C += a[i]
max_difference = B - C
print(max_difference)
``` | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,692,645,942 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 15 | 0 | n,m,a = input().split()
m = int(m)
n = int(n)
a = int(a)
city = n/a
if n%a:
city += 1
city = int(city)
city1 = m/a
if m%a:
city1 += 1
city1= int(city1)
print(city1*city)
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n,m,a = input().split()
m = int(m)
n = int(n)
a = int(a)
city = n/a
if n%a:
city += 1
city = int(city)
city1 = m/a
if m%a:
city1 += 1
city1= int(city1)
print(city1*city)
``` | 0 |
888 | B | Buggy Robot | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — mo... | The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100).
The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R. | Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. | [
"4\nLDUR\n",
"5\nRRRUU\n",
"6\nLLRRRR\n"
] | [
"4\n",
"0\n",
"4\n"
] | none | 0 | [
{
"input": "4\nLDUR",
"output": "4"
},
{
"input": "5\nRRRUU",
"output": "0"
},
{
"input": "6\nLLRRRR",
"output": "4"
},
{
"input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR",
"output": "76"
},
{
"input": "89\nLDL... | 1,511,510,984 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 77 | 5,529,600 | n = int(input())
s = list(input())
l = 0
r = 0
u = 0
d = 0
for i in s:
if i == 'L':
l += 1
if i == 'U':
u += 1
if i == 'R':
r += 1
if i == 'D':
d += 1
m1 = min(l, r) * 2
m2 = min(u, d) * 2
if l > 0 and r > 0 or l == 0 and r == 0:
print(m1 + m2)
elif... | Title: Buggy Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the ce... | ```python
n = int(input())
s = list(input())
l = 0
r = 0
u = 0
d = 0
for i in s:
if i == 'L':
l += 1
if i == 'U':
u += 1
if i == 'R':
r += 1
if i == 'D':
d += 1
m1 = min(l, r) * 2
m2 = min(u, d) * 2
if l > 0 and r > 0 or l == 0 and r == 0:
print(m1 +... | 3 | |
559 | B | Equivalent Strings | PROGRAMMING | 1,700 | [
"divide and conquer",
"hashing",
"sortings",
"strings"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 1,000 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,541,671,990 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 88 | 2,000 | 1,024,000 | def check(a,b):
if(a==b):
return True
if(len(a)%2==1):
return False
return (check(a[:len(a)//2],b[:len(b)//2]) and check(a[len(a)//2:],b[len(b)//2:]) ) or( check(a[:len(a)//2],b[len(b)//2:]) and check(a[len(a)//2:],b[:len(b)//2]) )
a=input()
b=input()
if(check(a,b)):
print("YES")
else:... | Title: Equivalent Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split str... | ```python
def check(a,b):
if(a==b):
return True
if(len(a)%2==1):
return False
return (check(a[:len(a)//2],b[:len(b)//2]) and check(a[len(a)//2:],b[len(b)//2:]) ) or( check(a[:len(a)//2],b[len(b)//2:]) and check(a[len(a)//2:],b[:len(b)//2]) )
a=input()
b=input()
if(check(a,b)):
print("Y... | 0 | |
452 | A | Eevee | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"strings"
] | null | null | You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Syl... | First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string.
Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword). | Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter). | [
"7\nj......\n",
"7\n...feon\n",
"7\n.l.r.o.\n"
] | [
"jolteon\n",
"leafeon\n",
"flareon\n"
] | Here's a set of names in a form you can paste into your solution:
["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
{"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"} | 500 | [
{
"input": "7\n...feon",
"output": "leafeon"
},
{
"input": "7\n.l.r.o.",
"output": "flareon"
},
{
"input": "6\n.s..o.",
"output": "espeon"
},
{
"input": "7\nglaceon",
"output": "glaceon"
},
{
"input": "8\n.a.o.e.n",
"output": "vaporeon"
},
{
"input": "... | 1,594,822,548 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 155 | 20,172,800 | """
problem : https://codeforces.com/problemset/problem/452/A
auther : Jay Saha
handel : ponder_
date : 15/07/2020
"""
pokemons = ['vaporeon', 'jolteon', 'flareon', 'espeon', 'umbreon', 'leafeon', 'glaceon', 'sylveon']
n = int(input())
maskedPM = input()
for p in pokemons:
if n == len(p):
is... | Title: Eevee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight... | ```python
"""
problem : https://codeforces.com/problemset/problem/452/A
auther : Jay Saha
handel : ponder_
date : 15/07/2020
"""
pokemons = ['vaporeon', 'jolteon', 'flareon', 'espeon', 'umbreon', 'leafeon', 'glaceon', 'sylveon']
n = int(input())
maskedPM = input()
for p in pokemons:
if n == len(p):
... | 3 | |
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,645,795,484 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 62 | 0 | x = input()
upper = 0
lower = 0
for i in x:
if i.isupper():
upper = upper +1
if i.islower():
lower = lower +1
if lower>=upper:
print(x.lower())
else:
print(x.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
x = input()
upper = 0
lower = 0
for i in x:
if i.isupper():
upper = upper +1
if i.islower():
lower = lower +1
if lower>=upper:
print(x.lower())
else:
print(x.upper())
``` | 3.9845 |
450 | B | Jzzhu and Sequences | PROGRAMMING | 1,300 | [
"implementation",
"math"
] | null | null | Jzzhu has invented a kind of sequences, they meet the following property:
You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7). | The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). | Output a single integer representing *f**n* modulo 1000000007 (109<=+<=7). | [
"2 3\n3\n",
"0 -1\n2\n"
] | [
"1\n",
"1000000006\n"
] | In the first sample, *f*<sub class="lower-index">2</sub> = *f*<sub class="lower-index">1</sub> + *f*<sub class="lower-index">3</sub>, 3 = 2 + *f*<sub class="lower-index">3</sub>, *f*<sub class="lower-index">3</sub> = 1.
In the second sample, *f*<sub class="lower-index">2</sub> = - 1; - 1 modulo (10<sup class="upper-... | 1,000 | [
{
"input": "2 3\n3",
"output": "1"
},
{
"input": "0 -1\n2",
"output": "1000000006"
},
{
"input": "-9 -11\n12345",
"output": "1000000005"
},
{
"input": "0 0\n1000000000",
"output": "0"
},
{
"input": "-1000000000 1000000000\n2000000000",
"output": "1000000000"
... | 1,666,429,448 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 25,190,400 | s=input().split()
x,y=int(s[0]),int(s[1])
neww=[]
neww.append(x)
neww.append(y)
n=int(input())
def calit(n):
return neww[n-1]-neww[n-2]
for i in range(2,n):
neww.append(calit(i))
print(neww[n-1]%(10**9+7))
| Title: Jzzhu and Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jzzhu has invented a kind of sequences, they meet the following property:
You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7).
Input Specification:
The first line contains two integers... | ```python
s=input().split()
x,y=int(s[0]),int(s[1])
neww=[]
neww.append(x)
neww.append(y)
n=int(input())
def calit(n):
return neww[n-1]-neww[n-2]
for i in range(2,n):
neww.append(calit(i))
print(neww[n-1]%(10**9+7))
``` | 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,653,215,285 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 62 | 0 | import sys
input = sys.stdin.readline
s = input()[:-1]
if s[0] == 'h':
a = s.find('ru', 5, len(s))
s = s[:4] + '://' + s[4:a] + '.' + s[a:a+2] + '/' + s[a+2:]
else:
a = s.find('ru', 4, len(s))
s = s[:3] + '://' + s[3:a] + '.' + s[a:a + 2] + '/' + s[a + 2:]
print(s) | 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 sys
input = sys.stdin.readline
s = input()[:-1]
if s[0] == 'h':
a = s.find('ru', 5, len(s))
s = s[:4] + '://' + s[4:a] + '.' + s[a:a+2] + '/' + s[a+2:]
else:
a = s.find('ru', 4, len(s))
s = s[:3] + '://' + s[3:a] + '.' + s[a:a + 2] + '/' + s[a + 2:]
print(s)
``` | 0 | |
352 | B | Jeff and Periods | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces. | In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in th... | [
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] | [
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] | In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | 1,000 | [
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"outpu... | 1,692,332,059 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n = int(input())
arr = list(map(int, input().split()))
s = set()
m = {}
val = 0
for i in range(n):
if arr[i] not in s:
s.add(arr[i])
diff = 0
cnt = 1
pos = i
flag = True
for j in range(i + 1, n):
if arr[i] == arr[j]:
cnt... | Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
-... | ```python
n = int(input())
arr = list(map(int, input().split()))
s = set()
m = {}
val = 0
for i in range(n):
if arr[i] not in s:
s.add(arr[i])
diff = 0
cnt = 1
pos = i
flag = True
for j in range(i + 1, n):
if arr[i] == arr[j]:
... | 0 | |
588 | B | Duff in Love | PROGRAMMING | 1,300 | [
"math"
] | null | null | Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=><=1 such that *a*2 is a divisor of *x*.
Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek want... | The first and only line of input contains one integer, *n* (1<=≤<=*n*<=≤<=1012). | Print the answer in one line. | [
"10\n",
"12\n"
] | [
"10\n",
"6\n"
] | In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely.
In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2<sup class="upper-index">2</sup>, so 12 is not lovely, while 6 is indeed lovely. | 1,000 | [
{
"input": "10",
"output": "10"
},
{
"input": "12",
"output": "6"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "8",
"output": "2"
},
{
"input": "3",
"output": "3"
},
... | 1,555,004,811 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 795 | 0 | n = int(input())
divs = [n,1]
ra = int(n**(1/2))
for s in range(2,ra+1):
if n % s == 0:
divs.append(s)
if s != int(n/s):
divs.append(int(n/s))
divs.sort()
divs.reverse()
#print(divs)
for q in divs:
s = int(q**(1/2))
if q in [1,2,3]:
print(q)
break
else:
f = 1
... | Title: Duff in Love
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=><=1 such that *a*2 is a divisor of *x*.
Malek has a number store! In his store, he has... | ```python
n = int(input())
divs = [n,1]
ra = int(n**(1/2))
for s in range(2,ra+1):
if n % s == 0:
divs.append(s)
if s != int(n/s):
divs.append(int(n/s))
divs.sort()
divs.reverse()
#print(divs)
for q in divs:
s = int(q**(1/2))
if q in [1,2,3]:
print(q)
break
else:
... | 3 | |
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,... | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"i... | 1,510,325,582 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 62 | 0 | a,b,c=map(int,input().split(" "))
if(a==1 or b==1):
print(min(c//a,c//b))
else:
l=[k for k in range(1,c+1) if (k%a==0 and k%b==0)]
print(len(l)) | Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists com... | ```python
a,b,c=map(int,input().split(" "))
if(a==1 or b==1):
print(min(c//a,c//b))
else:
l=[k for k in range(1,c+1) if (k%a==0 and k%b==0)]
print(len(l))
``` | 3 | |
832 | A | Sasha and Sticks | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players t... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. | If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower). | [
"1 1\n",
"10 4\n"
] | [
"YES\n",
"NO\n"
] | In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sas... | 500 | [
{
"input": "1 1",
"output": "YES"
},
{
"input": "10 4",
"output": "NO"
},
{
"input": "251656215122324104 164397544865601257",
"output": "YES"
},
{
"input": "963577813436662285 206326039287271924",
"output": "NO"
},
{
"input": "1000000000000000000 1",
"output":... | 1,619,463,243 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 62 | 0 | a,b = map(int, input().split())
print ("YES" if (a//b%2 != 0) else "NO") | Title: Sasha and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with ... | ```python
a,b = map(int, input().split())
print ("YES" if (a//b%2 != 0) else "NO")
``` | 3 | |
513 | C | Second price auction | PROGRAMMING | 2,000 | [
"bitmasks",
"probabilities"
] | null | null | Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receive... | The first line of input contains an integer number *n* (2<=≤<=*n*<=≤<=5). *n* lines follow, the *i*-th of them containing two numbers *L**i* and *R**i* (1<=≤<=*L**i*<=≤<=*R**i*<=≤<=10000) describing the *i*-th company's bid preferences.
This problem doesn't have subproblems. You will get 8 points for the correct submi... | Output the answer with absolute or relative error no more than 1*e*<=-<=9. | [
"3\n4 7\n8 10\n5 5\n",
"3\n2 5\n3 4\n1 6\n"
] | [
"5.7500000000\n",
"3.5000000000\n"
] | Consider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first ... | 8 | [
{
"input": "3\n4 7\n8 10\n5 5",
"output": "5.7500000000"
},
{
"input": "3\n2 5\n3 4\n1 6",
"output": "3.5000000000"
},
{
"input": "5\n1 10000\n1 10000\n1 10000\n1 10000\n1 10000",
"output": "6667.1666666646"
},
{
"input": "2\n1 2\n1 2",
"output": "1.2500000000"
},
{
... | 1,646,571,659 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 22 | 405 | 10,342,400 | class Cie:
def __init__(self, id, start, end):
self.id = id
self.start = start
self.end = end
self.range = end - start + 1
def lte(self, k):
return min(self.range, max(0, k - self.start + 1))
def gte(self, k):
return min(self.range, max(0, 1 + self.end - k))... | Title: Second price auction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened... | ```python
class Cie:
def __init__(self, id, start, end):
self.id = id
self.start = start
self.end = end
self.range = end - start + 1
def lte(self, k):
return min(self.range, max(0, k - self.start + 1))
def gte(self, k):
return min(self.range, max(0, 1 + self... | 3 | |
204 | B | Little Elephant and Cards | PROGRAMMING | 1,500 | [
"binary search",
"data structures"
] | null | null | The Little Elephant loves to play with color cards.
He has *n* cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thin... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of the cards. The following *n* lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the fro... | On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1. | [
"3\n4 7\n4 7\n7 4\n",
"5\n4 7\n7 4\n2 11\n9 7\n1 1\n"
] | [
"0\n",
"2\n"
] | In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.
In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. | 500 | [
{
"input": "3\n4 7\n4 7\n7 4",
"output": "0"
},
{
"input": "5\n4 7\n7 4\n2 11\n9 7\n1 1",
"output": "2"
},
{
"input": "1\n1 1",
"output": "0"
},
{
"input": "2\n1 1\n1 1",
"output": "0"
},
{
"input": "7\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8",
"output": "-1"
},
... | 1,678,560,358 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 124 | 0 | n = int(input())
cards = []
colors = {}
for i in range(n):
a, b = map(int, input().split())
cards.append((a, b))
colors[a] = colors.get(a, 0) + 1
max_count = max(colors.values())
if max_count >= (n+1)//2:
print(0)
else:
num_flips = n - max_count
if max_count == 0:
prin... | Title: Little Elephant and Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves to play with color cards.
He has *n* cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with t... | ```python
n = int(input())
cards = []
colors = {}
for i in range(n):
a, b = map(int, input().split())
cards.append((a, b))
colors[a] = colors.get(a, 0) + 1
max_count = max(colors.values())
if max_count >= (n+1)//2:
print(0)
else:
num_flips = n - max_count
if max_count == 0:
... | 0 | |
426 | A | Sereja and Mugs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume th... | The first line contains integers *n* and *s* (2<=≤<=*n*<=≤<=100; 1<=≤<=*s*<=≤<=1000) — the number of mugs and the volume of the cup. The next line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10). Number *a**i* means the volume of the *i*-th mug. | In a single line, print "YES" (without the quotes) if his friends can play in the described manner, and "NO" (without the quotes) otherwise. | [
"3 4\n1 1 1\n",
"3 4\n3 1 3\n",
"3 4\n4 4 4\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3 4\n1 1 1",
"output": "YES"
},
{
"input": "3 4\n3 1 3",
"output": "YES"
},
{
"input": "3 4\n4 4 4",
"output": "NO"
},
{
"input": "2 1\n1 10",
"output": "YES"
},
{
"input": "3 12\n5 6 6",
"output": "YES"
},
{
"input": "4 10\n6 3 8 7",
"... | 1,459,027,817 | 17 | Python 3 | OK | TESTS | 42 | 62 | 5,120,000 | import sys
import itertools
n, s = map(int, input().split())
lst = list(map(int, input().split()))
friends = n - 1
for item in itertools.combinations(lst, friends):
if sum(item) <= s:
print("YES")
sys.exit()
print("NO")
| Title: Sereja and Mugs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non... | ```python
import sys
import itertools
n, s = map(int, input().split())
lst = list(map(int, input().split()))
friends = n - 1
for item in itertools.combinations(lst, friends):
if sum(item) <= s:
print("YES")
sys.exit()
print("NO")
``` | 3 | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,588,288,265 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 654 | 8,499,200 | import bisect
I = lambda: map(int, input().rstrip().split())
n, d = I()
x = list(I())
ans = 0
def getCount(m):
return (m * (m - 1)) // 2
for i in range(n - 2):
a = x[i]
c = a + d
ind = bisect.bisect_left(x, c)
if ind > n - 1:
ind = n - 1
elif x[ind] != c:
ind -= 1
ans += getC... | Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
import bisect
I = lambda: map(int, input().rstrip().split())
n, d = I()
x = list(I())
ans = 0
def getCount(m):
return (m * (m - 1)) // 2
for i in range(n - 2):
a = x[i]
c = a + d
ind = bisect.bisect_left(x, c)
if ind > n - 1:
ind = n - 1
elif x[ind] != c:
ind -= 1
a... | 3 | |
681 | C | Heap Operations | PROGRAMMING | 1,600 | [
"constructive algorithms",
"data structures",
"greedy"
] | null | null | Petya has recently learned data structure named "Binary heap".
The heap he is now operating with allows the following operations:
- put the given number into the heap; - get the value of the minimum element in the heap; - extract the minimum element from the heap;
Thus, at any moment of time the heap contains se... | The first line of the input contains the only integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of the records left in Petya's journal.
Each of the following *n* lines describe the records in the current log in the order they are applied. Format described in the statement is used. All numbers in the input are integers... | The first line of the output should contain a single integer *m* — the minimum possible number of records in the modified sequence of operations.
Next *m* lines should contain the corrected sequence of records following the format of the input (described in the statement), one per line and in the order they are applie... | [
"2\ninsert 3\ngetMin 4\n",
"4\ninsert 1\ninsert 1\nremoveMin\ngetMin 2\n"
] | [
"4\ninsert 3\nremoveMin\ninsert 4\ngetMin 4\n",
"6\ninsert 1\ninsert 1\nremoveMin\nremoveMin\ninsert 2\ngetMin 2\n"
] | In the first sample, after number 3 is inserted into the heap, the minimum number is 3. To make the result of the first getMin equal to 4 one should firstly remove number 3 from the heap and then add number 4 into the heap.
In the second sample case number 1 is inserted two times, so should be similarly removed twice. | 1,500 | [
{
"input": "2\ninsert 3\ngetMin 4",
"output": "4\ninsert 3\nremoveMin\ninsert 4\ngetMin 4"
},
{
"input": "4\ninsert 1\ninsert 1\nremoveMin\ngetMin 2",
"output": "6\ninsert 1\ninsert 1\nremoveMin\nremoveMin\ninsert 2\ngetMin 2"
},
{
"input": "1\ninsert 1",
"output": "1\ninsert 1"
},... | 1,590,136,201 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 8,089,600 | import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = s... | Title: Heap Operations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has recently learned data structure named "Binary heap".
The heap he is now operating with allows the following operations:
- put the given number into the heap; - get the value of the minimum element in the ... | ```python
import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self... | 0 | |
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all c... | Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). | Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
... | 1,591,516,348 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 280 | 0 |
a = int(input())
g = 0
for k in range(2,a):
g+= a%k +1
print(str(g)+'/'+str(a-2))
| Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of su... | ```python
a = int(input())
g = 0
for k in range(2,a):
g+= a%k +1
print(str(g)+'/'+str(a-2))
``` | 0 |
242 | C | King's Path | PROGRAMMING | 1,800 | [
"dfs and similar",
"graphs",
"hashing",
"shortest paths"
] | null | null | The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the... | The first line contains four space-separated integers *x*0,<=*y*0,<=*x*1,<=*y*1 (1<=≤<=*x*0,<=*y*0,<=*x*1,<=*y*1<=≤<=109), denoting the initial and the final positions of the king.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the number of segments of allowed cells. Next *n* lines contai... | If there is no path between the initial and final position along allowed cells, print -1.
Otherwise print a single integer — the minimum number of moves the king needs to get from the initial position to the final one. | [
"5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n",
"3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n",
"1 1 2 10\n2\n1 1 3\n2 6 10\n"
] | [
"4\n",
"6\n",
"-1\n"
] | none | 1,500 | [
{
"input": "5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5",
"output": "4"
},
{
"input": "3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10",
"output": "6"
},
{
"input": "1 1 2 10\n2\n1 1 3\n2 6 10",
"output": "-1"
},
{
"input": "9 8 7 8\n9\n10 6 6\n10 6 6\n7 7 8\n9 5 6\n8 9 9\n9 5 5\n9 8 8\n8 5 6\n9 10... | 1,589,220,859 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 12 | 748 | 35,225,600 | def main():
import sys, math
#from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().s... | Title: King's Path
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with int... | ```python
def main():
import sys, math
#from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.re... | 0 | |
656 | A | Da Vinci Powers | PROGRAMMING | 1,900 | [
"*special"
] | null | null | The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer. | The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). | Output a single integer. | [
"3\n",
"10\n"
] | [
"8\n",
"1024\n"
] | none | 0 | [
{
"input": "3",
"output": "8"
},
{
"input": "10",
"output": "1024"
},
{
"input": "35",
"output": "33940307968"
},
{
"input": "0",
"output": "1"
},
{
"input": "1",
"output": "2"
},
{
"input": "2",
"output": "4"
},
{
"input": "4",
"output... | 1,515,667,382 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 5,632,000 | n=int(input())
2
print(pow(2,n)) | Title: Da Vinci Powers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer.
Input Specification:
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output Specification:
Output a single integer.
De... | ```python
n=int(input())
2
print(pow(2,n))
``` | 0 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,694,785,062 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | x=input()+', '
print(len(set(x))-4) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
x=input()+', '
print(len(set(x))-4)
``` | 3 | |
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,669,315,059 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | word = input()
new_word = sorted(word)
if len(word) % 2 != 0:
if "".join(new_word[len(word)//2]).isupper():
print("".join(word).upper())
else:
print("".join(word).lower())
else:
if "".join(new_word[len(word)//2:(len(word)//2)+1]).isupper():
print("".join(word).upper())
... | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
word = input()
new_word = sorted(word)
if len(word) % 2 != 0:
if "".join(new_word[len(word)//2]).isupper():
print("".join(word).upper())
else:
print("".join(word).lower())
else:
if "".join(new_word[len(word)//2:(len(word)//2)+1]).isupper():
print("".join(word).up... | 0 |
358 | B | Dima and Text Messages | PROGRAMMING | 1,500 | [
"brute force",
"strings"
] | null | null | Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other.
Dima and Inna are using a secret code in their text messages. ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of words in Dima's message. Next *n* lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105.
The last line contains non-empty text message that Inna has got... | In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise. | [
"3\ni\nlove\nyou\n<3i<3love<23you<3\n",
"7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3\n"
] | [
"yes\n",
"no\n"
] | Please note that Dima got a good old kick in the pants for the second sample from the statement. | 1,000 | [
{
"input": "3\ni\nlove\nyou\n<3i<3love<23you<3",
"output": "yes"
},
{
"input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3",
"output": "no"
},
{
"input": "3\ni\nlove\nyou\n<3i<3lo<3ve<3y<<<<<<<ou3<3",
"output": "yes"
},
{
"input": "4\na\n... | 1,451,463,467 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 234 | 2,150,400 | n=int(input())
text=""
for _ in range(n):
temp=input()
text=text+"<3"
text=text+temp
text=text+"<3"
tocmp=input()
j=0
for ch in tocmp:
if ch==text[j]:
j+=1
if j==len(text):
break
if j==len(text):
print("yes")
else:
print("no")
| Title: Dima and Text Messages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today t... | ```python
n=int(input())
text=""
for _ in range(n):
temp=input()
text=text+"<3"
text=text+temp
text=text+"<3"
tocmp=input()
j=0
for ch in tocmp:
if ch==text[j]:
j+=1
if j==len(text):
break
if j==len(text):
print("yes")
else:
print("no")
``` | 3 | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,617,039,366 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 124 | 307,200 | s=input()
l=[]
k=[]
c=0
for i in s:
l.append(i)
# print(l)
for i in l:
if i=='Q' or i=='A':
k.append(i)
# print(k)
n=len(k)
for i in range(n+1):
for j in range(i+1,n):
for z in range(j+1,n):
m=k[i]+k[j]+k[z]
# print(m)
if(m=='QAQ'):
... | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
s=input()
l=[]
k=[]
c=0
for i in s:
l.append(i)
# print(l)
for i in l:
if i=='Q' or i=='A':
k.append(i)
# print(k)
n=len(k)
for i in range(n+1):
for j in range(i+1,n):
for z in range(j+1,n):
m=k[i]+k[j]+k[z]
# print(m)
if(m=='Q... | 3 | |
835 | B | The number on the board | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbe... | The first line contains integer *k* (1<=≤<=*k*<=≤<=109).
The second line contains integer *n* (1<=≤<=*n*<=<<=10100000).
There are no leading zeros in *n*. It's guaranteed that this situation is possible. | Print the minimum number of digits in which the initial number and *n* can differ. | [
"3\n11\n",
"3\n99\n"
] | [
"1\n",
"0\n"
] | In the first example, the initial number could be 12.
In the second example the sum of the digits of *n* is not less than *k*. The initial number could be equal to *n*. | 750 | [
{
"input": "3\n11",
"output": "1"
},
{
"input": "3\n99",
"output": "0"
},
{
"input": "10\n5205602270",
"output": "0"
},
{
"input": "70\n3326631213",
"output": "6"
},
{
"input": "200\n100000001000000000000000000001000000000000000100000100000000000000000000000000000... | 1,608,746,295 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | k = int(input())
n = input()
s = sum(list(map(int,n)))
if s>k: print(0)
else: print(int(n)+k-s) | Title: The number on the board
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that th... | ```python
k = int(input())
n = input()
s = sum(list(map(int,n)))
if s>k: print(0)
else: print(int(n)+k-s)
``` | 0 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,687,475,340 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | w = int(input())
ans = "NO"
if w == 2:
ans = "YES"
elif w%2==0:
ans = "YES"
print(ans) | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
w = int(input())
ans = "NO"
if w == 2:
ans = "YES"
elif w%2==0:
ans = "YES"
print(ans)
``` | 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,638,450,206 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | word=input()
ucount=0
lcount=0
for letter in word:
if(letter.isupper()):
ucount=ucount+1
else:
lcount=lcount+1
if(ucount>lcount):
print(word.upper())
else:
print(word.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
word=input()
ucount=0
lcount=0
for letter in word:
if(letter.isupper()):
ucount=ucount+1
else:
lcount=lcount+1
if(ucount>lcount):
print(word.upper())
else:
print(word.lower())
``` | 3.969 |
644 | A | Parliament of Berland | PROGRAMMING | 1,000 | [
"*special",
"constructive algorithms"
] | null | null | There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of *a*<=×<=*b* chairs — *a* rows of *b* chair... | The first line of the input contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=10<=000, 1<=≤<=*a*,<=*b*<=≤<=100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively. | If there is no way to assigns seats to parliamentarians in a proper way print -1.
Otherwise print the solution in *a* lines, each containing *b* integers. The *j*-th integer of the *i*-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multi... | [
"3 2 2\n",
"8 4 3\n",
"10 2 2\n"
] | [
"0 3\n1 2\n",
"7 8 3\n0 1 4\n6 0 5\n0 2 0\n",
"-1\n"
] | In the first sample there are many other possible solutions. For example,
and
The following assignment
is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats. | 500 | [
{
"input": "3 2 2",
"output": "1 2 \n0 3 "
},
{
"input": "8 4 3",
"output": "1 2 3 \n4 5 6 \n7 8 0 \n0 0 0 "
},
{
"input": "10 2 2",
"output": "-1"
},
{
"input": "1 1 1",
"output": "1 "
},
{
"input": "8 3 3",
"output": "1 2 3 \n4 5 6 \n7 8 0 "
},
{
"in... | 1,458,413,124 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 4,608,000 | #!/usr/bin/python3
def read_ints():
return list(map(int, input().split()))
(n,a,b) = read_ints()
odd = 1
even = 2
for i in range(0,a):
for j in range(0,b):
if (i+j) % 2 == 0:
if even <= n:
print(even,end=" ")
even+=2
else: print(0,end=" ")
else:
if odd <= n:
print(odd,end=" ")
... | Title: Parliament of Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republi... | ```python
#!/usr/bin/python3
def read_ints():
return list(map(int, input().split()))
(n,a,b) = read_ints()
odd = 1
even = 2
for i in range(0,a):
for j in range(0,b):
if (i+j) % 2 == 0:
if even <= n:
print(even,end=" ")
even+=2
else: print(0,end=" ")
else:
if odd <= n:
print(odd,en... | 0 | |
711 | A | Bus to Udayland | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris a... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and t... | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ... | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | 500 | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
... | 1,690,371,019 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 62 | 0 | # LUOGU_RID: 117570787
n=int(input())
a=[]
f=True
for i in range(n):
a.append(input())
if f and 'OO' in a[i]:
c=a[i].split('|')
if c[0]=='OO':
c[0]='++'
else:
c[1]='++'
a[i]=c[0]+'|'+c[1]
f=False
if not f:
print('YES\n'+'\n'.join(... | Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pai... | ```python
# LUOGU_RID: 117570787
n=int(input())
a=[]
f=True
for i in range(n):
a.append(input())
if f and 'OO' in a[i]:
c=a[i].split('|')
if c[0]=='OO':
c[0]='++'
else:
c[1]='++'
a[i]=c[0]+'|'+c[1]
f=False
if not f:
print('YES\n'+... | 3 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,649,600,148 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | ch=input()
ch1="."
ch2="-."
ch3="--"
if(ch3 in ch):
ch=ch.replace(ch3,'2')
if(ch2 in ch):
ch=ch.replace(ch2,'1')
if(ch1 in ch):
ch=ch.replace(ch1,'0')
print(ch) | 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
ch=input()
ch1="."
ch2="-."
ch3="--"
if(ch3 in ch):
ch=ch.replace(ch3,'2')
if(ch2 in ch):
ch=ch.replace(ch2,'1')
if(ch1 in ch):
ch=ch.replace(ch1,'0')
print(ch)
``` | 3.977 |
635 | A | Orchestra | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Paul is at the orchestra. The string section is arranged in an *r*<=×<=*c* rectangular grid and is filled with violinists with the exception of *n* violists. Paul really likes violas, so he would like to take a picture including at least *k* of them. Paul can take a picture of any axis-parallel rectangle in the orchest... | The first line of input contains four space-separated integers *r*, *c*, *n*, *k* (1<=≤<=*r*,<=*c*,<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=*n*) — the number of rows and columns of the string section, the total number of violas, and the minimum number of violas Paul would like in his photograph, respectively.
The next *n* lines ea... | Print a single integer — the number of photographs Paul can take which include at least *k* violas. | [
"2 2 1 1\n1 2\n",
"3 2 3 3\n1 1\n3 1\n2 2\n",
"3 2 3 2\n1 1\n3 1\n2 2\n"
] | [
"4\n",
"1\n",
"4\n"
] | We will use '*' to denote violinists and '#' to denote violists.
In the first sample, the orchestra looks as follows
In the second sample, the orchestra looks as follows
In the third sample, the orchestra looks the same as in the second sample. | 500 | [
{
"input": "2 2 1 1\n1 2",
"output": "4"
},
{
"input": "3 2 3 3\n1 1\n3 1\n2 2",
"output": "1"
},
{
"input": "3 2 3 2\n1 1\n3 1\n2 2",
"output": "4"
},
{
"input": "1 1 1 1\n1 1",
"output": "1"
},
{
"input": "10 10 10 10\n6 1\n3 8\n10 6\n10 3\n10 4\n8 9\n2 3\n5 7\n... | 1,621,187,060 | 2,147,483,647 | PyPy 3 | OK | TESTS | 22 | 140 | 3,686,400 | f = lambda: map(int, input().split())
r, c, n, k = f()
t = [list(f()) for i in range(n)]
s = 0
for i in range(1, r + 1):
for j in range(i, r + 1):
for u in range(1, c + 1):
for v in range(u, c + 1):
s += sum([i <= x <= j and u <= y <= v for x, y in t]) >= k
print(s) | Title: Orchestra
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Paul is at the orchestra. The string section is arranged in an *r*<=×<=*c* rectangular grid and is filled with violinists with the exception of *n* violists. Paul really likes violas, so he would like to take a picture includ... | ```python
f = lambda: map(int, input().split())
r, c, n, k = f()
t = [list(f()) for i in range(n)]
s = 0
for i in range(1, r + 1):
for j in range(i, r + 1):
for u in range(1, c + 1):
for v in range(u, c + 1):
s += sum([i <= x <= j and u <= y <= v for x, y in t]) >= k
pri... | 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,638,452,055 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n = int(input())
ox = [int(x) for x in input().split()]
minn= 0
maxx = 0
for i in range(n):
minn = ox[0]
maxx = ox[-1]
if i == 0:
minn = ox[1]
if i == n - 1:
maxx = ox[n-2]
min_d = ox[i] - minn
max_d = ox[i] - maxx
if ox[i] < min_d:
m... | 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
n = int(input())
ox = [int(x) for x in input().split()]
minn= 0
maxx = 0
for i in range(n):
minn = ox[0]
maxx = ox[-1]
if i == 0:
minn = ox[1]
if i == n - 1:
maxx = ox[n-2]
min_d = ox[i] - minn
max_d = ox[i] - maxx
if ox[i] < min_d:
... | -1 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,589,655,386 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 186 | 6,656,000 | s1 = input()
up = low = 0
for i in s1:
if i.isupper():
up += 1
else:
low += 1
if(low >= up):
print(s1.lower())
else:
print(s1.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s1 = input()
up = low = 0
for i in s1:
if i.isupper():
up += 1
else:
low += 1
if(low >= up):
print(s1.lower())
else:
print(s1.upper())
``` | 3.941102 |
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,671,976,911 | 2,147,483,647 | Python 3 | OK | TESTS1 | 24 | 404 | 0 | n=int(input())
c=0
while(n!=0):
n=n-int(max(list(str(n))))
# print(n)
c=c+1
print(c) | 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
n=int(input())
c=0
while(n!=0):
n=n-int(max(list(str(n))))
# print(n)
c=c+1
print(c)
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,589,895,443 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | a='hello'
i=0
str= input()
for j in str:
if j==a[i]:
i+=1
if i==len(a):
print ('yes')
break
if(i!=len(a)):
print('no') | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
a='hello'
i=0
str= input()
for j in str:
if j==a[i]:
i+=1
if i==len(a):
print ('yes')
break
if(i!=len(a)):
print('no')
``` | 0 |
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"... | 1,670,698,004 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 16 | 62 | 1,945,600 | n=int(input())
r=0
a=[int(i)for i in input().split()]
for i in range(n):
g=a[a[i]-1]
h=a[g-1]
if h-1==i:
r=1
if r==1:
print("YES")
else:
print("NO")
| Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with ... | ```python
n=int(input())
r=0
a=[int(i)for i in input().split()]
for i in range(n):
g=a[a[i]-1]
h=a[g-1]
if h-1==i:
r=1
if r==1:
print("YES")
else:
print("NO")
``` | 3 | |
510 | B | Fox And Two Dots | PROGRAMMING | 1,500 | [
"dfs and similar"
] | null | null | Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size *n*<=×<=*m* cells, like this:
Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors.
The key of this game is to find a cycle that contain dots... | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50): the number of rows and columns of the board.
Then *n* lines follow, each line contains a string consisting of *m* characters, expressing colors of dots in each line. Each character is an uppercase Latin letter. | Output "Yes" if there exists a cycle, and "No" otherwise. | [
"3 4\nAAAA\nABCA\nAAAA\n",
"3 4\nAAAA\nABCA\nAADA\n",
"4 4\nYYYR\nBYBY\nBBBY\nBBBY\n",
"7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB\n",
"2 13\nABCDEFGHIJKLM\nNOPQRSTUVWXYZ\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n",
"No\n"
] | In first sample test all 'A' form a cycle.
In second sample there is no such cycle.
The third sample is displayed on the picture above ('Y' = Yellow, 'B' = Blue, 'R' = Red). | 1,000 | [
{
"input": "3 4\nAAAA\nABCA\nAAAA",
"output": "Yes"
},
{
"input": "3 4\nAAAA\nABCA\nAADA",
"output": "No"
},
{
"input": "4 4\nYYYR\nBYBY\nBBBY\nBBBY",
"output": "Yes"
},
{
"input": "7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB",
"output": "Yes"
},
{
... | 1,682,265,212 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 62 | 0 | n = 50
vis = [[False] * n for _ in range(n)]
tab = [[''] * n for _ in range(n)]
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
def dfs(i, j, pi, pj):
vis[i][j] = True
for c in range(4):
di = i + dx[c]
dj = j + dy[c]
if di > n or di < 0 or dj > n or dj < 0:
continue
... | Title: Fox And Two Dots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size *n*<=×<=*m* cells, like this:
Each cell contains a dot that has some color. We will use different uppercase La... | ```python
n = 50
vis = [[False] * n for _ in range(n)]
tab = [[''] * n for _ in range(n)]
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
def dfs(i, j, pi, pj):
vis[i][j] = True
for c in range(4):
di = i + dx[c]
dj = j + dy[c]
if di > n or di < 0 or dj > n or dj < 0:
c... | -1 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,636,603,434 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 124 | 4,505,600 | n=int(input())
l=[]
s=0
c=0
for i in range(n):
l.append(list(map(int,input().split())))
for k in range(3):
for j in range(n):
s+=l[j][k]
c+=s
if(c==0):
print("YES")
else:
print("NO")
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n=int(input())
l=[]
s=0
c=0
for i in range(n):
l.append(list(map(int,input().split())))
for k in range(3):
for j in range(n):
s+=l[j][k]
c+=s
if(c==0):
print("YES")
else:
print("NO")
``` | 3.960608 |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,676,347,118 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 93 | 0 | if __name__=="__main__":
n = int(input())
if n%2==0:
print(int(n/2))
for i in range(int(n/2)):
print(2,end=" ")
else:
print(int(n/2))
for i in range(int(n/2-1)):
print(2,end=" ")
print(3) | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
... | ```python
if __name__=="__main__":
n = int(input())
if n%2==0:
print(int(n/2))
for i in range(int(n/2)):
print(2,end=" ")
else:
print(int(n/2))
for i in range(int(n/2-1)):
print(2,end=" ")
print(3)
``` | 3 | |
667 | B | Coat of Anticubism | PROGRAMMING | 1,100 | [
"constructive algorithms",
"geometry"
] | null | null | As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.
A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-... | The first line contains an integer *n* (3<=≤<=*n*<=≤<=105) — a number of rod-blanks.
The second line contains *n* integers *l**i* (1<=≤<=*l**i*<=≤<=109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with *n* vertices and nonzero area using the rods Cicasso alrea... | Print the only integer *z* — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (*n*<=+<=1) vertices and nonzero area from all of the rods. | [
"3\n1 2 1\n",
"5\n20 4 3 2 1\n"
] | [
"1\n",
"11\n"
] | In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}.
In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}. | 1,000 | [
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n20 4 3 2 1",
"output": "11"
},
{
"input": "7\n77486105 317474713 89523018 332007362 7897847 949616701 54820086",
"output": "70407571"
},
{
"input": "14\n245638694 2941428 4673577 12468 991349408 44735727 14046308 60637707... | 1,649,547,923 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 78 | 3,072,000 | n = int(input())
l = [int(x) for x in input().split()]
l.sort()
print(2*l[n-1] + 1 - sum(l))
| Title: Coat of Anticubism
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.
A famous sculptor Cicasso, ... | ```python
n = int(input())
l = [int(x) for x in input().split()]
l.sort()
print(2*l[n-1] + 1 - sum(l))
``` | 3 | |
721 | B | Passwords | PROGRAMMING | 1,100 | [
"implementation",
"math",
"sortings",
"strings"
] | null | null | Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitr... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of ... | Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively. | [
"5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n",
"4 100\n11\n22\n1\n2\n22\n"
] | [
"1 15\n",
"3 4\n"
] | Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he ente... | 1,000 | [
{
"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc",
"output": "1 15"
},
{
"input": "4 100\n11\n22\n1\n2\n22",
"output": "3 4"
},
{
"input": "1 1\na1\na1",
"output": "1 1"
},
{
"input": "1 100\na1\na1",
"output": "1 1"
},
{
"input": "2 1\nabc\nAbc\nAbc",
"output": ... | 1,623,476,944 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 109 | 0 | n,f=map(int,input().strip().split())
l=[]
l1=[]
c=0
for i in range(n):
s=input()
l1.append(s)
l.append(len(s))
k=input()
if(max(l)==min(l)):
if(f<n):
print("1",f*5+n)
else:
print("1",n)
else:
for i in l1:
if(len(i)<len(k)):
c=c+1
print(c+1,n)
... | Title: Passwords
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords... | ```python
n,f=map(int,input().strip().split())
l=[]
l1=[]
c=0
for i in range(n):
s=input()
l1.append(s)
l.append(len(s))
k=input()
if(max(l)==min(l)):
if(f<n):
print("1",f*5+n)
else:
print("1",n)
else:
for i in l1:
if(len(i)<len(k)):
c=c+1
print(c+1,n)
... | 0 | |
272 | C | Dima and Staircase | PROGRAMMING | 1,500 | [
"data structures",
"implementation"
] | null | null | Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*).
Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The *i*-th box has width *w**i... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of stairs in the staircase. The second line contains a non-decreasing sequence, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109; *a**i*<=≤<=*a**i*<=+<=1).
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the numbe... | Print *m* integers — for each box the height, where the bottom of the box will be after landing. Print the answers for the boxes in the order, in which the boxes are given in the input.
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 %I... | [
"5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3\n",
"3\n1 2 3\n2\n1 1\n3 1\n",
"1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10\n"
] | [
"1\n3\n4\n6\n",
"1\n3\n",
"1\n3\n13\n23\n33\n"
] | The first sample are shown on the picture. | 1,500 | [
{
"input": "5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3",
"output": "1\n3\n4\n6"
},
{
"input": "3\n1 2 3\n2\n1 1\n3 1",
"output": "1\n3"
},
{
"input": "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10",
"output": "1\n3\n13\n23\n33"
},
{
"input": "8\n6 10 18 23 30 31 31 33\n1\n5 3",
"output":... | 1,490,795,108 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 2,000 | 9,113,600 | def inbox():
s = input().split()
return [eval(s[0]), eval(s[1])]
boxes = []
n = eval(input())
s = input().split()
a = [eval(i) for i in s]
m = eval(input())
for i in range(m):
boxes.append(inbox())
for i in range(len(boxes)):
w = boxes[i][0]
h = boxes[i][1]
k = max(a[:w])
p... | Title: Dima and Staircase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*).
Dima decided to play with the st... | ```python
def inbox():
s = input().split()
return [eval(s[0]), eval(s[1])]
boxes = []
n = eval(input())
s = input().split()
a = [eval(i) for i in s]
m = eval(input())
for i in range(m):
boxes.append(inbox())
for i in range(len(boxes)):
w = boxes[i][0]
h = boxes[i][1]
k = max(a[:... | 0 | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,677,608,137 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | num = int(input())
list1 = list(map(int,input().split()))
list2 = set(list1)
counter = 0
for i in list2:
s = list1.count(i)
if s > 1 :
counter += s-1
print((len(list2)-1)*2 + counter) | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
num = int(input())
list1 = list(map(int,input().split()))
list2 = set(list1)
counter = 0
for i in list2:
s = list1.count(i)
if s > 1 :
counter += s-1
print((len(list2)-1)*2 + counter)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limeligh... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the number of cows and the length of Farmer John's nap, respectively. | Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps. | [
"5 2\n",
"1 10\n"
] | [
"10\n",
"0\n"
] | In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.
In the second sample, there is only one cow, so the maximum possible mess... | 0 | [
{
"input": "5 2",
"output": "10"
},
{
"input": "1 10",
"output": "0"
},
{
"input": "100000 2",
"output": "399990"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "8 3",
"output": "27"
},
{
"input": "7 1",
"output": "11"
},
{
"input": "1000... | 1,464,852,699 | 2,147,483,647 | Python 3 | OK | TESTS | 92 | 93 | 4,812,800 | __author__ = 'Utena'
n,k=map(int,input().split())
t=0
for i in range(k):
if n<2:break
else:
t+=2*n-3
n-=2
print(t) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However,... | ```python
__author__ = 'Utena'
n,k=map(int,input().split())
t=0
for i in range(k):
if n<2:break
else:
t+=2*n-3
n-=2
print(t)
``` | 3 | |
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,673,319,165 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | a = int(input())
if a % 2 == 1:
print(-1)
else:
b = [0]*a
for i in range(1,a+1,2):
b[i-1] = i+1
b[i] = i
for j in b :
print(j,end = ' ') | 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
a = int(input())
if a % 2 == 1:
print(-1)
else:
b = [0]*a
for i in range(1,a+1,2):
b[i-1] = i+1
b[i] = i
for j in b :
print(j,end = ' ')
``` | 3 | |
549 | C | The Game Of Parity | PROGRAMMING | 2,200 | [
"games"
] | null | null | There are *n* cities in Westeros. The *i*-th city is inhabited by *a**i* people. Daenerys and Stannis play the following game: in one single move, a player chooses a certain town and burns it to the ground. Thus all its residents, sadly, die. Stannis starts the game. The game ends when Westeros has exactly *k* cities l... | The first line contains two positive space-separated integers, *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=2·105) — the initial number of cities in Westeros and the number of cities at which the game ends.
The second line contains *n* space-separated positive integers *a**i* (1<=≤<=*a**i*<=≤<=106), which represent the populat... | Print string "Daenerys" (without the quotes), if Daenerys wins and "Stannis" (without the quotes), if Stannis wins. | [
"3 1\n1 2 1\n",
"3 1\n2 2 1\n",
"6 3\n5 20 12 7 14 101\n"
] | [
"Stannis\n",
"Daenerys\n",
"Stannis\n"
] | In the first sample Stannis will use his move to burn a city with two people and Daenerys will be forced to burn a city with one resident. The only survivor city will have one resident left, that is, the total sum is odd, and thus Stannis wins.
In the second sample, if Stannis burns a city with two people, Daenerys bu... | 2,000 | [
{
"input": "3 1\n1 2 1",
"output": "Stannis"
},
{
"input": "3 1\n2 2 1",
"output": "Daenerys"
},
{
"input": "6 3\n5 20 12 7 14 101",
"output": "Stannis"
},
{
"input": "6 3\n346 118 330 1403 5244 480",
"output": "Daenerys"
},
{
"input": "7 4\n11 3532 99 3512 12 8 2... | 1,507,719,529 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 155 | 13,824,000 | n,k=[int(i) for i in input().split()]
l=[int(i) for i in input().split()]
no=0
for i in l:
no+=i%2
ne=n-no
if no<=(n-k)//2:
print("Daenerys")
else:
if no%2:
if (n-k)%2 and ne<=(n-k)//2 and ne%2==0:
print("Daenerys")
elif (n-k)%2==0 and (ne>(n-k)//2 or ne%2):
... | Title: The Game Of Parity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities in Westeros. The *i*-th city is inhabited by *a**i* people. Daenerys and Stannis play the following game: in one single move, a player chooses a certain town and burns it to the ground. Thus all ... | ```python
n,k=[int(i) for i in input().split()]
l=[int(i) for i in input().split()]
no=0
for i in l:
no+=i%2
ne=n-no
if no<=(n-k)//2:
print("Daenerys")
else:
if no%2:
if (n-k)%2 and ne<=(n-k)//2 and ne%2==0:
print("Daenerys")
elif (n-k)%2==0 and (ne>(n-k)//2 or ne%2):... | 0 | |
313 | D | Ilya and Roads | PROGRAMMING | 2,100 | [
"dp"
] | null | null | Everything is great about Ilya's city, except the roads. The thing is, the only ZooVille road is represented as *n* holes in a row. We will consider the holes numbered from 1 to *n*, from left to right.
Ilya is really keep on helping his city. So, he wants to fix at least *k* holes (perharps he can fix more) on a sing... | The first line contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*<=≤<=300,<=1<=≤<=*m*<=≤<=105,<=1<=≤<=*k*<=≤<=*n*). The next *m* lines contain the companies' description. The *i*-th line contains three integers *l**i*,<=*r**i*,<=*c**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*,<=1<=≤<=*c**i*<=≤<=109). | Print a single integer — the minimum money Ilya needs to fix at least *k* holes.
If it is impossible to fix at least *k* holes, print -1.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"10 4 6\n7 9 11\n6 9 13\n7 7 7\n3 5 6\n",
"10 7 1\n3 4 15\n8 9 8\n5 6 8\n9 10 6\n1 4 2\n1 4 10\n8 10 13\n",
"10 1 9\n5 10 14\n"
] | [
"17\n",
"2\n",
"-1\n"
] | none | 2,500 | [
{
"input": "10 4 6\n7 9 11\n6 9 13\n7 7 7\n3 5 6",
"output": "17"
},
{
"input": "10 7 1\n3 4 15\n8 9 8\n5 6 8\n9 10 6\n1 4 2\n1 4 10\n8 10 13",
"output": "2"
},
{
"input": "10 1 9\n5 10 14",
"output": "-1"
},
{
"input": "10 6 9\n6 8 7\n2 8 11\n2 6 10\n8 10 9\n2 5 8\n2 3 8",
... | 1,691,734,334 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | print("_RANDOM_GUESS_1691734334.8755386")# 1691734334.8755558 | Title: Ilya and Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everything is great about Ilya's city, except the roads. The thing is, the only ZooVille road is represented as *n* holes in a row. We will consider the holes numbered from 1 to *n*, from left to right.
Ilya is really k... | ```python
print("_RANDOM_GUESS_1691734334.8755386")# 1691734334.8755558
``` | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,656,764,181 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | n=list(input())
if n.index('h')<n.index('e')<n.index('l')<n.index('o'):
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
n=list(input())
if n.index('h')<n.index('e')<n.index('l')<n.index('o'):
print("YES")
else:
print("NO")
``` | 0 |
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,563,594 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 218 | 614,400 | entrada = int(input())
sete = 0
quatro = 0
quatro += entrada // 4
resto = entrada % 4
while resto % 7 != 0:
if quatro == 0:
break
quatro -= 1
resto += 4
if resto % 7 == 0:
sete += resto // 7
tmp1 = quatro // 7
tmp2 = quatro % 7
sete += tmp1 * 4
quatro = tmp2
print(quatro*"4" + sete*"7")
else:
print(-1)... | 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
entrada = int(input())
sete = 0
quatro = 0
quatro += entrada // 4
resto = entrada % 4
while resto % 7 != 0:
if quatro == 0:
break
quatro -= 1
resto += 4
if resto % 7 == 0:
sete += resto // 7
tmp1 = quatro // 7
tmp2 = quatro % 7
sete += tmp1 * 4
quatro = tmp2
print(quatro*"4" + sete*"7")
else:
... | 3.944356 |
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"ou... | 1,528,753,531 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 921,600 | from functools import reduce
def factors(m):
return set(reduce(list.__add__,
([i, m // i] for i in range(1, int(pow(m, 0.5) + 1)) if m % i == 0)))
n, k = [int(j) for j in input().split()]
def fact(k):
lst = list(factors(n))
lst1 = sorted(lst)
try:
retur... | Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specificatio... | ```python
from functools import reduce
def factors(m):
return set(reduce(list.__add__,
([i, m // i] for i in range(1, int(pow(m, 0.5) + 1)) if m % i == 0)))
n, k = [int(j) for j in input().split()]
def fact(k):
lst = list(factors(n))
lst1 = sorted(lst)
try:
... | 0 | |
801 | A | Vicious Keyboard | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maxi... | The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. | Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. | [
"VK\n",
"VV\n",
"V\n",
"VKKKKKKKKKVVVVVVVVVK\n",
"KVKV\n"
] | [
"1\n",
"1\n",
"0\n",
"3\n",
"1\n"
] | For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we ... | 500 | [
{
"input": "VK",
"output": "1"
},
{
"input": "VV",
"output": "1"
},
{
"input": "V",
"output": "0"
},
{
"input": "VKKKKKKKKKVVVVVVVVVK",
"output": "3"
},
{
"input": "KVKV",
"output": "1"
},
{
"input": "VKKVVVKVKVK",
"output": "5"
},
{
"input... | 1,492,360,483 | 3,583 | Python 3 | OK | TESTS | 63 | 62 | 5,529,600 | count=0
countk=0
countv=0
def st0(List,i):
global countk
temp=0
while i<len(List) and List[i]=='K':
temp+=1
i+=1
countk=max(countk,temp)
if i==len(List):
return
st1(List,i+1)
def st1(List,i):
global count
if i< len(List) and List[i]=='K':
... | Title: Vicious Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter i... | ```python
count=0
countk=0
countv=0
def st0(List,i):
global countk
temp=0
while i<len(List) and List[i]=='K':
temp+=1
i+=1
countk=max(countk,temp)
if i==len(List):
return
st1(List,i+1)
def st1(List,i):
global count
if i< len(List) and List[i]==... | 3 | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,665,942,791 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 4,300,800 | pop1=int(input())
hg2=list(map(int,input().split()))
while(0 in hg2):
hg2.remove(0)
hg2=set(hg2)
print(len(hg2))
# hg2=set(hg2)
# print(len(hg2))
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
pop1=int(input())
hg2=list(map(int,input().split()))
while(0 in hg2):
hg2.remove(0)
hg2=set(hg2)
print(len(hg2))
# hg2=set(hg2)
# print(len(hg2))
``` | 3 | |
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,661,791,543 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | x = input()
c1 = 0
c2 = 0
for i in x:
if i.isupper():
c += 1
elif i.islower():
c2 += 1
if c1 <= c2:
print(x.lower())
else:
print(x.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
x = input()
c1 = 0
c2 = 0
for i in x:
if i.isupper():
c += 1
elif i.islower():
c2 += 1
if c1 <= c2:
print(x.lower())
else:
print(x.upper())
``` | -1 |
86 | A | Reflection | PROGRAMMING | 1,600 | [
"math"
] | A. Reflection | 2 | 256 | For each positive integer *n* consider the integer ψ(*n*) which is obtained from *n* by replacing every digit *a* in the decimal notation of *n* with the digit (9<=<=-<=<=*a*). We say that ψ(*n*) is the reflection of *n*. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So ... | Input contains two space-separated integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — bounds of the range. | Output should contain single integer number: maximum value of the product *n*·ψ(*n*), where *l*<=≤<=*n*<=≤<=*r*.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d). | [
"3 7\n",
"1 1\n",
"8 10\n"
] | [
"20",
"8",
"890"
] | In the third sample weight of 8 equals 8·1 = 8, weight of 9 equals 9·0 = 0, weight of 10 equals 890.
Thus, maximum value of the product is equal to 890. | 500 | [
{
"input": "3 7",
"output": "20"
},
{
"input": "1 1",
"output": "8"
},
{
"input": "8 10",
"output": "890"
},
{
"input": "4 6",
"output": "20"
},
{
"input": "10 100",
"output": "89900"
},
{
"input": "1 999",
"output": "249500"
},
{
"input": ... | 1,672,512,815 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 2,000 | 0 | a = list(input().split(" "))
max = 0
for i in range(int(a[0]) , int(a[1])+1):
data = str(i) + 'e'
index=0
while(data[index]!='e'):
index = index + 1
reflection = (10**index)-1 - i
weight = i * int(reflection)
if weight > max:
max = weight
print(max) | Title: Reflection
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
For each positive integer *n* consider the integer ψ(*n*) which is obtained from *n* by replacing every digit *a* in the decimal notation of *n* with the digit (9<=<=-<=<=*a*). We say that ψ(*n*) is the reflection of *n*. For ex... | ```python
a = list(input().split(" "))
max = 0
for i in range(int(a[0]) , int(a[1])+1):
data = str(i) + 'e'
index=0
while(data[index]!='e'):
index = index + 1
reflection = (10**index)-1 - i
weight = i * int(reflection)
if weight > max:
max = weight
print(max)
``` | 0 |
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integer... | The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer — the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
... | 1,631,705,969 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 154 | 6,758,400 | n, k = map(int, input().split())
if n == 1:
arr = [input()]
else:
arr = input().split()
count = n
for sample in arr:
if sample.count("4")+sample.count("7")>k:
count -= 1
print(count)
| Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits... | ```python
n, k = map(int, input().split())
if n == 1:
arr = [input()]
else:
arr = input().split()
count = n
for sample in arr:
if sample.count("4")+sample.count("7")>k:
count -= 1
print(count)
``` | 3 | |
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first positi... | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4... | 1,580,749,853 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 1,091 | 307,200 | n=int(input())
a=list(map(int,input().split()))
d=[]
for i in range(len(a)) :
c=1
for j in range(len(a)) :
if a[i]<a[j] :
c+=1
d.append(c)
for i in range (len(d)) :
print(d[i],end=" ")
| Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the star... | ```python
n=int(input())
a=list(map(int,input().split()))
d=[]
for i in range(len(a)) :
c=1
for j in range(len(a)) :
if a[i]<a[j] :
c+=1
d.append(c)
for i in range (len(d)) :
print(d[i],end=" ")
``` | 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,697,100,418 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 46 | 102,400 | parts = int(input())
static = input()
anton = static.count('A')
danik = static.count('D')
if anton > danik:
print('Anton')
elif anton < danik:
print('Danik')
else:
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
parts = int(input())
static = input()
anton = static.count('A')
danik = static.count('D')
if anton > danik:
print('Anton')
elif anton < danik:
print('Danik')
else:
print('Friendship')
``` | 3 | |
962 | A | Equator | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on... | The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests.
The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. | Print the index of the day when Polycarp will celebrate the equator. | [
"4\n1 3 2 1\n",
"6\n2 2 2 2 2 2\n"
] | [
"2\n",
"3\n"
] | In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (... | 0 | [
{
"input": "4\n1 3 2 1",
"output": "2"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "3"
},
{
"input": "1\n10000",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "2"
},
{
"input": "4\n2 1 1 3",
"output": "3"
}... | 1,541,351,996 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 233 | 13,107,200 | import math
n = int(input())
a = [int(i) for i in input().split()]
total = res = index = 0
for i in a:
total += i
for i in range(n):
res += a[i]
if res >= math.ceil(total / 2):
index = i
break
print(index + 1)
| Title: Equator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve... | ```python
import math
n = int(input())
a = [int(i) for i in input().split()]
total = res = index = 0
for i in a:
total += i
for i in range(n):
res += a[i]
if res >= math.ceil(total / 2):
index = i
break
print(index + 1)
``` | 3 | |
743 | A | Vladik and flights | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows *n* airports. All the airports are located on a straight line. Each airport has u... | The first line contains three integers *n*, *a*, and *b* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length *n*, which consists only of characters... | Print single integer — the minimum cost Vladik has to pay to get to the olympiad. | [
"4 1 4\n1010\n",
"5 5 2\n10110\n"
] | [
"1",
"0"
] | In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to th... | 500 | [
{
"input": "4 1 4\n1010",
"output": "1"
},
{
"input": "5 5 2\n10110",
"output": "0"
},
{
"input": "10 9 5\n1011111001",
"output": "1"
},
{
"input": "7 3 7\n1110111",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 3 3\n100101101... | 1,498,030,618 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 109 | 23,859,200 | (n, a, b) = map(int, input().split())
t = input()
a -= 1
b -= 1
if t[a] == t[b]:
print(0)
else:
print(1) | Title: Vladik and flights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the o... | ```python
(n, a, b) = map(int, input().split())
t = input()
a -= 1
b -= 1
if t[a] == t[b]:
print(0)
else:
print(1)
``` | 3 | |
329 | D | The Evil Temple and the Moving Rocks | PROGRAMMING | 2,500 | [
"constructive algorithms"
] | null | null | Important: All possible tests are in the pretest, so you shouldn't hack on this problem. So, if you passed pretests, you will also pass the system test.
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak monsters, you arrived at a square room consisting of tiles forming ... | The first line will consists of two integers *n* and *x*, denoting the size of the room and the number of sounds required to open the door. There will be exactly three test cases for this problem:
- *n*<==<=5,<=*x*<==<=5; - *n*<==<=3,<=*x*<==<=2; - *n*<==<=100,<=*x*<==<=105.
All of these testcases are in pretest. | Output *n* lines. Each line consists of *n* characters — the *j*-th character of the *i*-th line represents the content of the tile at the *i*-th row and the *j*-th column, and should be one of these:
- '^', '<', '>', or 'v': a rock as described in the problem statement. - '.': an empty tile.
Then, output two... | [
"5 5\n",
"3 2\n"
] | [
">...v\nv.<..\n..^..\n>....\n..^.<\n1 1\n",
">vv\n^<.\n^.<\n1 3\n"
] | Here's a simulation of the first example, accompanied with the number of sounds produced so far.
In the picture above, the activated rock switches between the '^' rock and the '<' rock. However, no sound is produced since the '^' rock didn't move even a single tile. So, still 4 sound.
At this point, 5 sound are al... | 1,500 | [
{
"input": "5 5",
"output": ">...v\nv.<..\n..^..\n>....\n..^.<\n1 1"
},
{
"input": "3 2",
"output": ">vv\n^<.\n^.<\n1 3"
},
{
"input": "100 100000",
"output": ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>v.\n^v<.<.<.<.<.<.<.<.<.<.... | 1,692,953,930 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 122 | 0 | print("_RANDOM_GUESS_1692953930.1431353")# 1692953930.1431506 | Title: The Evil Temple and the Moving Rocks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Important: All possible tests are in the pretest, so you shouldn't hack on this problem. So, if you passed pretests, you will also pass the system test.
You are an adventurer currently journeying i... | ```python
print("_RANDOM_GUESS_1692953930.1431353")# 1692953930.1431506
``` | 0 | |
577 | A | Multiplication Table | PROGRAMMING | 1,000 | [
"implementation",
"number theory"
] | null | null | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain num... | The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. | Print a single number: the number of times *x* occurs in the table. | [
"10 5\n",
"6 12\n",
"5 13\n"
] | [
"2\n",
"4\n",
"0\n"
] | A table for the second sample test is given below. The occurrences of number 12 are marked bold. | 500 | [
{
"input": "10 5",
"output": "2"
},
{
"input": "6 12",
"output": "4"
},
{
"input": "5 13",
"output": "0"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "1 10000000... | 1,645,713,046 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 78 | 1,331,200 | #http://codeforces.com/problemset/problem/577/A
n, x = map(int, input().split())
a = 0
for i in range(1, n + 1):
if x % i == 0 and x/i <=n:
a+=1
print(a)
| Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
Y... | ```python
#http://codeforces.com/problemset/problem/577/A
n, x = map(int, input().split())
a = 0
for i in range(1, n + 1):
if x % i == 0 and x/i <=n:
a+=1
print(a)
``` | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,693,315,297 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 62 | 0 | # -*- coding: utf-8 -*-
"""
Created on Tue Aug 29 20:07:37 2023
@author: Zinc
"""
n=int(input())
for i in range(n):
word = input()
length = len(word)
if length>10:
al = str(length-2)
al_word = word[0]+al+word[-1]
print(al_word)
else:
print(word) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 29 20:07:37 2023
@author: Zinc
"""
n=int(input())
for i in range(n):
word = input()
length = len(word)
if length>10:
al = str(length-2)
al_word = word[0]+al+word[-1]
print(al_word)
else:
print(wor... | 3.969 |
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at prog... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to... | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output... | 1,682,424,990 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 61 | 0 | n = int(input())
x = list(map(int, input().split()))
a = []
b = []
c = []
for i in range(n):
if x[i] == 1:
a.append(i + 1)
elif x[i] == 2:
b.append(i + 1)
else:
c.append(i + 1)
print(min(len(a), len(b), len(c)))
for i in range(min(len(a), len(b), len(c))):
ans = []
... | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)... | ```python
n = int(input())
x = list(map(int, input().split()))
a = []
b = []
c = []
for i in range(n):
if x[i] == 1:
a.append(i + 1)
elif x[i] == 2:
b.append(i + 1)
else:
c.append(i + 1)
print(min(len(a), len(b), len(c)))
for i in range(min(len(a), len(b), len(c))):
... | 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,562,331,444 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 109 | 102,400 | n = int(input())
l= []
l.append(1)
c=0
a=1
b=1
while c<=n:
c=a+b
a=b
b=c
l.append(c)
for i in range(1,n+1):
if i in l:
print('O',end="")
else:
print('o',end="") | Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should o... | ```python
n = int(input())
l= []
l.append(1)
c=0
a=1
b=1
while c<=n:
c=a+b
a=b
b=c
l.append(c)
for i in range(1,n+1):
if i in l:
print('O',end="")
else:
print('o',end="")
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest.
V... | The first line on the input contains a single integer *n* (2<=≤<=*n*<=≤<=200<=000, *n* is even) — the number of positions available initially. The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109), giving the coordinates of the corresponding positions. | Print the distance between the warrior and the archer at the beginning of the fight, provided that both Vova and Lesha play optimally. | [
"6\n0 1 3 7 15 31\n",
"2\n73 37\n"
] | [
"7\n",
"36\n"
] | In the first sample one of the optimum behavior of the players looks like that:
1. Vova bans the position at coordinate 15; 1. Lesha bans the position at coordinate 3; 1. Vova bans the position at coordinate 31; 1. Lesha bans the position at coordinate 1.
After these actions only positions 0 and 7 will remain, an... | 0 | [
{
"input": "6\n0 1 3 7 15 31",
"output": "7"
},
{
"input": "2\n73 37",
"output": "36"
},
{
"input": "2\n0 1000000000",
"output": "1000000000"
},
{
"input": "8\n729541013 135019377 88372488 319157478 682081360 558614617 258129110 790518782",
"output": "470242129"
},
{
... | 1,447,005,831 | 5,631 | Python 3 | SKIPPED | TESTS | 0 | 46 | 0 | N = int(input())
C = [ int(c) for c in input().split() ]
C.sort()
import math
turn = 0
while len(C) > 2:
if turn == 0:
turn = 1
if C[-1]-C[1] < C[-2]-C[0]:
popped = C.pop(0)
# print("popped:", popped)
else:
popped =C.pop(-1)
# print("popped:", popped)
elif turn == 1:
turn =... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem st... | ```python
N = int(input())
C = [ int(c) for c in input().split() ]
C.sort()
import math
turn = 0
while len(C) > 2:
if turn == 0:
turn = 1
if C[-1]-C[1] < C[-2]-C[0]:
popped = C.pop(0)
# print("popped:", popped)
else:
popped =C.pop(-1)
# print("popped:", popped)
elif turn == 1:
... | -1 | |
954 | A | Diagonal Walking | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. | Print the minimum possible length of the sequence of moves after all replacements are done. | [
"5\nRUURU\n",
"17\nUUURRRRRUUURURUUU\n"
] | [
"3\n",
"13\n"
] | In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | 0 | [
{
"input": "5\nRUURU",
"output": "3"
},
{
"input": "17\nUUURRRRRUUURURUUU",
"output": "13"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "100"
},
{
"input": "100\nRRURRUUUURURRRURRRRURRRRRR... | 1,637,638,501 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
text=input()
c=0
for i in range(n-1):
if n>=1 and n<=100:
if text[i]=='R' and text[i+1]=='U':
c=c+1
elif text[i]=='U' and text[i+1]=='R':
c=c+1
else:
c=c+0
a=(n-c)+ n//c
print(a) | Title: Diagonal Walking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence movi... | ```python
n=int(input())
text=input()
c=0
for i in range(n-1):
if n>=1 and n<=100:
if text[i]=='R' and text[i+1]=='U':
c=c+1
elif text[i]=='U' and text[i+1]=='R':
c=c+1
else:
c=c+0
a=(n-c)+ n//c
print(a)
``` | -1 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.