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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,667,502,575 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n=input(); l = len(n); res=0
for i in range(l) : a=1+(int(n[i]) == 4) ;res += a * (2**(l-i-1))
print(res)
| Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
n=input(); l = len(n); res=0
for i in range(l) : a=1+(int(n[i]) == 4) ;res += a * (2**(l-i-1))
print(res)
``` | 0 | |
985 | A | Chess Placing | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | You are given a chessboard of size 1<=×<=*n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW".
Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to .
In one step you can move... | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100, *n* is even) — the size of the chessboard.
The second line of the input contains integer numbers (1<=≤<=*p**i*<=≤<=*n*) — initial positions of the pieces. It is guaranteed that all the positions are distinct. | Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color. | [
"6\n1 2 6\n",
"10\n1 2 3 4 5\n"
] | [
"2\n",
"10\n"
] | In the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3.
In the second example the possible strategy is to move... | 0 | [
{
"input": "6\n1 2 6",
"output": "2"
},
{
"input": "10\n1 2 3 4 5",
"output": "10"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "100\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 ... | 1,577,807,586 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 139 | 0 | i1=int(input())
ar=list(map(int,input().split()))
sm1=0
sm2=0
ar.sort()
for i in range(1,i1,2):
sm2+=abs(i-ar[int(i/2)])
ar.sort(reverse=True)
for i in range(0,i1,2):
sm1+=abs(i1-i-ar[int(i/2)])
print(min(sm1,sm2)) | Title: Chess Placing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a chessboard of size 1<=×<=*n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW".
Some cells of the board are occupied by the chess pieces. Each cell contains no more than... | ```python
i1=int(input())
ar=list(map(int,input().split()))
sm1=0
sm2=0
ar.sort()
for i in range(1,i1,2):
sm2+=abs(i-ar[int(i/2)])
ar.sort(reverse=True)
for i in range(0,i1,2):
sm1+=abs(i1-i-ar[int(i/2)])
print(min(sm1,sm2))
``` | 3 | |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,608,807,853 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 307,200 | n = int(input())
def total(n):
tot = 0
while n>0:
tot += n%10
n = n//10
return tot
def solve(n):
count = 0
while n>9:
n = total(n)
count += 1
return count
print(solve(n))
| Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
n = int(input())
def total(n):
tot = 0
while n>0:
tot += n%10
n = n//10
return tot
def solve(n):
count = 0
while n>9:
n = total(n)
count += 1
return count
print(solve(n))
``` | 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,574,860,847 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 34 | 109 | 0 | S = list(input())
SL = ["h", "e", "l", "l", "o"]
idex = 0
for i in S:
if i == SL[idex]:
idex += 1
if idex == 4:
break
if idex == 4:
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
S = list(input())
SL = ["h", "e", "l", "l", "o"]
idex = 0
for i in S:
if i == SL[idex]:
idex += 1
if idex == 4:
break
if idex == 4:
print("YES")
else:
print("NO")
``` | 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,578,588,778 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 280 | 0 | s1, s2, s3=map(int, input().split())
print(int(4*((s1*s2/s3)**0.5+(s1*s3/s2)**0.5+(s2*s3/s1)**0.5)))
| 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
s1, s2, s3=map(int, input().split())
print(int(4*((s1*s2/s3)**0.5+(s1*s3/s2)**0.5+(s2*s3/s1)**0.5)))
``` | 3 | |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,697,722,196 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | s = input()
n = len(n)
for i in range(1,4):
for j in range(0,n):
if(s[j]==i):
print(i,"+")
j += 1
else:
j += 1
i += 1 | Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
s = input()
n = len(n)
for i in range(1,4):
for j in range(0,n):
if(s[j]==i):
print(i,"+")
j += 1
else:
j += 1
i += 1
``` | -1 | |
0 | none | none | none | 0 | [
"none"
] | null | null | A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — then number of notes in Petya's logbook.
The second line contains *n* non-negative integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=<<=*i*) — notes in the logbook. | In the only line print a single integer — the minimum possible number of rooms in Paris catacombs. | [
"2\n0 0\n",
"5\n0 1 0 1 3\n"
] | [
"2\n",
"3\n"
] | In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2.
In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1. | 0 | [
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "5\n0 1 0 1 3",
"output": "3"
},
{
"input": "7\n0 1 0 0 0 0 0",
"output": "6"
},
{
"input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 ... | 1,510,569,468 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 140 | 14,336,000 | n = int(input())
x = list(map(int,input().split()))
#memset(x,-1,sizeof(x))
#x[0] = 1
#ans = 1
#mp = {}
#for i in range(n):
#mp[i]++
# jami bala code korta para.
#jami thaka ash vala code kora. bujha jaita hay.
#implement korta para nai :(
s = set(x)
ass = n-len(s)+1
print(ass)
'''#include <bits/stdc+... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages betw... | ```python
n = int(input())
x = list(map(int,input().split()))
#memset(x,-1,sizeof(x))
#x[0] = 1
#ans = 1
#mp = {}
#for i in range(n):
#mp[i]++
# jami bala code korta para.
#jami thaka ash vala code kora. bujha jaita hay.
#implement korta para nai :(
s = set(x)
ass = n-len(s)+1
print(ass)
'''#include <... | 3 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,686,940,450 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 62 | 0 | w=int(input())
W2= w/2
if (w % 2==0)and (W2 % 2 ==0) :
print("YES")
else:
print("NO") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
w=int(input())
W2= w/2
if (w % 2==0)and (W2 % 2 ==0) :
print("YES")
else:
print("NO")
``` | 0 |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,696,861,055 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n = int(input())
cards = list(map(int, input().split()))
# Initialize Sereja and Dima's scores to zero
sereja_score = 0
dima_score = 0
# Initialize pointers for the leftmost and rightmost cards
left = 0
right = n - 1
# Initialize a variable to keep track of whose turn it is (Sereja or Dima)
is_sereja_tur... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
n = int(input())
cards = list(map(int, input().split()))
# Initialize Sereja and Dima's scores to zero
sereja_score = 0
dima_score = 0
# Initialize pointers for the leftmost and rightmost cards
left = 0
right = n - 1
# Initialize a variable to keep track of whose turn it is (Sereja or Dima)
is_... | 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,581,748,770 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 307,200 | a=input()
t1=a.find('h')
if(a.find('e',t1+1,len(a))!=-1):
t2=a.find('e',t1+1,len(a))
#print(t2)
if(a.find('l',t2+1,len(a))!=-1):
t3=a.find('l',t2+1,len(a))
#print(t3)
if(a.find('l',t3+1,len(a))!=-1):
t4=a.find('l',t3+1,len(a))
#print(t4)
... | 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=input()
t1=a.find('h')
if(a.find('e',t1+1,len(a))!=-1):
t2=a.find('e',t1+1,len(a))
#print(t2)
if(a.find('l',t2+1,len(a))!=-1):
t3=a.find('l',t2+1,len(a))
#print(t3)
if(a.find('l',t3+1,len(a))!=-1):
t4=a.find('l',t3+1,len(a))
#print(t4)
... | 0 |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,691,068,905 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 46 | 0 | n,m=map(int,input().split())
s=0
for i in range(n):
x=input().split()
s+=x.count("C")+x.count("M")+x.count("Y")
if s>0:
print("#Color")
else:
print("#Black&White") | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
n,m=map(int,input().split())
s=0
for i in range(n):
x=input().split()
s+=x.count("C")+x.count("M")+x.count("Y")
if s>0:
print("#Color")
else:
print("#Black&White")
``` | 3 | |
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,... | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strict... | Print a single number — the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for whic... | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9... | 1,661,356,472 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | n = int(input())
l= list(map(int,input().split()))
t = []
k = 0
for i in range(1,n-1):
p = l[i]
o = l.copy()
o.remove(p)
for i in range(n-2):
k = max(k,abs(o[i]-o[i+1]))
t.append(k)
print(min(t))
| Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 fo... | ```python
n = int(input())
l= list(map(int,input().split()))
t = []
k = 0
for i in range(1,n-1):
p = l[i]
o = l.copy()
o.remove(p)
for i in range(n-2):
k = max(k,abs(o[i]-o[i+1]))
t.append(k)
print(min(t))
``` | 0 | |
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,544,856,772 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | n=int(input())
s=input().split()
s=list(set(s));d=[]
for i in range(0,n):
if s[i] is '0':
d.append(i)
for j in range(0,len(d)):
del s[d[j]-j]
print(len(s)) | 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
n=int(input())
s=input().split()
s=list(set(s));d=[]
for i in range(0,n):
if s[i] is '0':
d.append(i)
for j in range(0,len(d)):
del s[d[j]-j]
print(len(s))
``` | -1 | |
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m... | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
... | 1,659,122,658 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 140 | 1,024,000 | s = input()
t = input()
short_str = min(len(s), len(t))
j = len(s)-1
k = len(t)-1
count = 0
for i in range(short_str):
if s[j]==t[k]:
count+=1
j-=1
k-=1
else:
break
print((len(s)-count)+(len(t)-count))
| Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ... | ```python
s = input()
t = input()
short_str = min(len(s), len(t))
j = len(s)-1
k = len(t)-1
count = 0
for i in range(short_str):
if s[j]==t[k]:
count+=1
j-=1
k-=1
else:
break
print((len(s)-count)+(len(t)-count))
``` | 3 | |
1,000 | B | Light It Up | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunate... | First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed progra... | Print the only integer — maximum possible total time when the lamp is lit. | [
"3 10\n4 6 7\n",
"2 12\n1 10\n",
"2 7\n3 4\n"
] | [
"8\n",
"9\n",
"6\n"
] | In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal so... | 0 | [
{
"input": "3 10\n4 6 7",
"output": "8"
},
{
"input": "2 12\n1 10",
"output": "9"
},
{
"input": "2 7\n3 4",
"output": "6"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "5 10\n1 3 5 6 8",
"output": "6"
},
{
"input": "7 1000000000\n1 10001 10011 20... | 1,635,232,483 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 19 | 1,000 | 31,129,600 | n,m=map(int,input().split())
a=list(map(int,input().split()))
l=a[:]
l.append(0)
l.append(m)
l.sort()
q=[]
x=[]
y=[]
for i in range(1,len(l),2):
s=l[i]-l[i-1]
x.append(s)
for i in range(2,len(l),2):
s=l[i]-l[i-1]
y.append(s)
q.append(sum(x))
for i in range(0,len(x)):
if x[i]>1:
... | Title: Light It Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows y... | ```python
n,m=map(int,input().split())
a=list(map(int,input().split()))
l=a[:]
l.append(0)
l.append(m)
l.sort()
q=[]
x=[]
y=[]
for i in range(1,len(l),2):
s=l[i]-l[i-1]
x.append(s)
for i in range(2,len(l),2):
s=l[i]-l[i-1]
y.append(s)
q.append(sum(x))
for i in range(0,len(x)):
if x[... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Gerald has been selling state secrets at leisure. All the secrets cost the same: *n* marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mark, 3 marks, 9 marks, 27 marks and so on. There are no coins of o... | The single line contains a single integer *n* (1<=≤<=*n*<=≤<=1017).
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. | In a single line print an integer: the maximum number of coins the unlucky buyer could have paid with. | [
"1\n",
"4\n"
] | [
"1\n",
"2\n"
] | In the first test case, if a buyer has exactly one coin of at least 3 marks, then, to give Gerald one mark, he will have to give this coin. In this sample, the customer can not have a coin of one mark, as in this case, he will be able to give the money to Gerald without any change.
In the second test case, if the buye... | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "3",
"output": "1"
},
{
"input": "8",
"output": "3"
},
{
"input": "10",
"output": "4"
},
{
"input": "100000000000000000",
"output": "33333333333333334"
},
{
"input... | 1,374,931,641 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 92 | 0 | import math
n = int(input())
k = 0;
for i in range(1,100):
if (n % (3**i) != 0):
k = i;
break;
print(math.ceil(n / (3**k)))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has been selling state secrets at leisure. All the secrets cost the same: *n* marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that ... | ```python
import math
n = int(input())
k = 0;
for i in range(1,100):
if (n % (3**i) != 0):
k = i;
break;
print(math.ceil(n / (3**k)))
``` | 0 | |
284 | A | Cows and Primitive Roots | PROGRAMMING | 1,400 | [
"implementation",
"math",
"number theory"
] | null | null | The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is.
Unfortunately, computing primitive roots can be time consumin... | The input contains a single line containing an integer *p* (2<=≤<=*p*<=<<=2000). It is guaranteed that *p* is a prime. | Output on a single line the number of primitive roots . | [
"3\n",
"5\n"
] | [
"1\n",
"2\n"
] | The only primitive root <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3722298ba062e95b18705d1253eb4e5d31e3b2d1.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
The primitive roots <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1d85c6a17ef1c42b53cf9... | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "2"
},
{
"input": "7",
"output": "2"
},
{
"input": "11",
"output": "4"
},
{
"input": "17",
"output": "8"
},
{
"input": "19",
"output": "6"
},
{
"input": "1583",
"output": "672"
... | 1,577,447,862 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 1,558 | 307,200 | MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n=ii()
c=0
for i in range(2,n):
x=i;t=1
for j in range(n-2):
if x==1:
... | Title: Cows and Primitive Roots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 ar... | ```python
MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n=ii()
c=0
for i in range(2,n):
x=i;t=1
for j in range(n-2):
if ... | 0 | |
274 | B | Zero Tree | PROGRAMMING | 1,800 | [
"dfs and similar",
"dp",
"greedy",
"trees"
] | null | null | A tree is a graph with *n* vertices and exactly *n*<=-<=1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.
A subtree of a tree *T* is a tree with both vertices and edges as subsets of vertices and edges of *T*.
You're ... | The first line of the input contains *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*) indicating there's an edge between vertices *a**i* and *b**i*. It's guaranteed that the input graph is a tree.
The last line of the ... | Print the minimum number of operations needed to solve the task.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"3\n1 2\n1 3\n1 -1 1\n"
] | [
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 2\n1 3\n1 -1 1",
"output": "3"
},
{
"input": "5\n2 3\n4 5\n2 5\n1 3\n0 2 1 4 3",
"output": "8"
},
{
"input": "10\n5 6\n8 2\n9 3\n4 1\n6 10\n9 8\n7 10\n7 4\n5 2\n0 -6 -9 -1 -5 -4 -2 -7 -8 -3",
"output": "18"
},
{
"input": "5\n3 1\n2 4\n3 4\n2 5\n0 -3 -1 2 4",
... | 1,683,199,771 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 0 | 122 | 268,390,400 | from sys import *
input = stdin.readline
setrecursionlimit(10000000)
n=int(input())
d={i:[] for i in range(n)}
for i in range(n-1):
a,b=map(int, input().split())
a-=1
b-=1
d[a].append(b)
d[b].append(a)
l=list(map(int, input().split()))
# ans=0
v=[0 for _ in range(n)]
... | Title: Zero Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tree is a graph with *n* vertices and exactly *n*<=-<=1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.
A subtree of a tr... | ```python
from sys import *
input = stdin.readline
setrecursionlimit(10000000)
n=int(input())
d={i:[] for i in range(n)}
for i in range(n-1):
a,b=map(int, input().split())
a-=1
b-=1
d[a].append(b)
d[b].append(a)
l=list(map(int, input().split()))
# ans=0
v=[0 for _ in r... | 0 | |
412 | C | Pattern | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules.
In this task, a pattern will be a string con... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of patterns. Next *n* lines contain the patterns.
It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does no... | In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them. | [
"2\n?ab\n??b\n",
"2\na\nb\n",
"1\n?a?b\n"
] | [
"xab\n",
"?\n",
"cacb\n"
] | Consider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot of ot... | 1,500 | [
{
"input": "2\n?ab\n??b",
"output": "xab"
},
{
"input": "2\na\nb",
"output": "?"
},
{
"input": "1\n?a?b",
"output": "cacb"
},
{
"input": "1\n?",
"output": "x"
},
{
"input": "3\nabacaba\nabacaba\nabacaba",
"output": "abacaba"
},
{
"input": "3\nabc?t\n?b... | 1,470,361,139 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 187 | 9,830,400 | def main():
l = []
for col in map(set, zip(*[input() for _ in range(int(input()))])):
col.discard('?')
l.append(col.pop() if len(col) == 1 else '?' if col else 'a')
print(''.join(l))
if __name__ == '__main__':
main()
| Title: Pattern
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check wheth... | ```python
def main():
l = []
for col in map(set, zip(*[input() for _ in range(int(input()))])):
col.discard('?')
l.append(col.pop() if len(col) == 1 else '?' if col else 'a')
print(''.join(l))
if __name__ == '__main__':
main()
``` | 3 | |
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,620,492,984 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 6,758,400 | def check(n,k):
s=str(n);
c7=s.count('7');
c4=s.count('4');
if c4+c7>k:
return False
else:
return True
n,k=map(int,input().split());
l=list(map(int,input().split()));
ans=0
for i in l:
if check(i,k)==True :
ans+=1
print(ans)
| 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
def check(n,k):
s=str(n);
c7=s.count('7');
c4=s.count('4');
if c4+c7>k:
return False
else:
return True
n,k=map(int,input().split());
l=list(map(int,input().split()));
ans=0
for i in l:
if check(i,k)==True :
ans+=1
print(ans)
``` | 3 | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,649,431,971 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 46 | 0 | n = int(input())
s = input()
s1 = input()
c = 0
for i, j in zip(s, s1):
if abs(int(i)-int(j)) <= 5:
c += abs(int(i)-int(j))
else:
c += 10 - max(int(i), int(j))
c += min(int(i), int(j))
print(c) | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
n = int(input())
s = input()
s1 = input()
c = 0
for i, j in zip(s, s1):
if abs(int(i)-int(j)) <= 5:
c += abs(int(i)-int(j))
else:
c += 10 - max(int(i), int(j))
c += min(int(i), int(j))
print(c)
``` | 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,660,719,139 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,764,800 | a = int(input())
b = int(input())
c = a*b
if c % 2 == 0:
print(c/2)
else:
print((c-1)/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
a = int(input())
b = int(input())
c = a*b
if c % 2 == 0:
print(c/2)
else:
print((c-1)/2)
``` | -1 |
171 | A | Mysterious numbers - 1 | PROGRAMMING | 1,200 | [
"*special",
"constructive algorithms"
] | null | null | The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=109), separated by a single space.
Output a single integer. | The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=109), separated by a single space. | Output a single integer. | [
"3 14\n",
"27 12\n",
"100 200\n"
] | [
"44\n",
"48\n",
"102\n"
] | none | 0 | [
{
"input": "3 14",
"output": "44"
},
{
"input": "27 12",
"output": "48"
},
{
"input": "100 200",
"output": "102"
},
{
"input": "0 0",
"output": "0"
},
{
"input": "31415 92653",
"output": "67044"
},
{
"input": "1000000000 0",
"output": "1000000000"
... | 1,585,574,747 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 248 | 0 | '''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineerin College
Date:30/03/2020
'''
from math import gcd,sqrt,ceil
def ii():return int(input())
def mi():return map(int,input().split())
def li():return list(mi())
def si():return input()
def main():
... | Title: Mysterious numbers - 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=109), separated by a single space.
Output a single integer.
Input Specification:
The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=109),... | ```python
'''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineerin College
Date:30/03/2020
'''
from math import gcd,sqrt,ceil
def ii():return int(input())
def mi():return map(int,input().split())
def li():return list(mi())
def si():return input()
def main():
... | 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,618,289,181 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 0 | s=input()
stringlist=[]
checker='hello'
checker_index=0
done=False
for i in range(len(s)):
if s[i]==checker[checker_index]:
checker_index+=1
if checker_index==5:
done=True
break
print("YES") if done 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
s=input()
stringlist=[]
checker='hello'
checker_index=0
done=False
for i in range(len(s)):
if s[i]==checker[checker_index]:
checker_index+=1
if checker_index==5:
done=True
break
print("YES") if done else print("NO")
``` | 3.969 |
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (withou... | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa... | 1,675,781,147 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 249 | 0 | # LUOGU_RID: 101671098
print(sum([4, 0, 8, 20, 6, 12][ord(input()[0]) % 7]
for _ in range(int(input()))))
| Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe... | ```python
# LUOGU_RID: 101671098
print(sum([4, 0, 8, 20, 6, 12][ord(input()[0]) % 7]
for _ in range(int(input()))))
``` | 3 | |
104 | A | Blackjack | PROGRAMMING | 800 | [
"implementation"
] | A. Blackjack | 2 | 256 | One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to... | The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points. | Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. | [
"12\n",
"20\n",
"10\n"
] | [
"4",
"15",
"0"
] | In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there ... | 500 | [
{
"input": "12",
"output": "4"
},
{
"input": "20",
"output": "15"
},
{
"input": "10",
"output": "0"
},
{
"input": "11",
"output": "4"
},
{
"input": "15",
"output": "4"
},
{
"input": "18",
"output": "4"
},
{
"input": "25",
"output": "0"
... | 1,557,772,121 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 248 | 0 | x = int(input())
if x>21 or x<=10:
print(0)
elif x == 20:
print(15)
elif x <=19 or x == 21:
print(4) | Title: Blackjack
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Co... | ```python
x = int(input())
if x>21 or x<=10:
print(0)
elif x == 20:
print(15)
elif x <=19 or x == 21:
print(4)
``` | 3.938 |
864 | B | Polycarp and Letters | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"strings"
] | null | null | Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters.
Let *A* be a set of positions in the string. Let's call it pretty if following conditions are met:
- letters on positions from *A* in the string are all distinct and lowerc... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200) — length of string *s*.
The second line contains a string *s* consisting of lowercase and uppercase Latin letters. | Print maximum number of elements in pretty set of positions for string *s*. | [
"11\naaaaBaabAbA\n",
"12\nzACaAbbaazzC\n",
"3\nABC\n"
] | [
"2\n",
"3\n",
"0\n"
] | In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There... | 1,000 | [
{
"input": "11\naaaaBaabAbA",
"output": "2"
},
{
"input": "12\nzACaAbbaazzC",
"output": "3"
},
{
"input": "3\nABC",
"output": "0"
},
{
"input": "1\na",
"output": "1"
},
{
"input": "2\naz",
"output": "2"
},
{
"input": "200\nXbTJZqcbpYuZQEoUrbxlPXAPCtVLr... | 1,586,116,033 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 109 | 0 | n=int(input())
s=input()
mc,i=0,0
t=[]
c=0
while i<n:
if s[i].isupper():
t=[]
c=0
elif s[i] not in t:
t.append(s[i])
c+=1
if c>mc:
mc=c
i+=1
print(mc)
| Title: Polycarp and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters.
Let *A* be a set of positions in the string. Let's call it pretty if... | ```python
n=int(input())
s=input()
mc,i=0,0
t=[]
c=0
while i<n:
if s[i].isupper():
t=[]
c=0
elif s[i] not in t:
t.append(s[i])
c+=1
if c>mc:
mc=c
i+=1
print(mc)
``` | 3 | |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line co... | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,678,131,610 | 2,147,483,647 | PyPy 3 | OK | TESTS | 58 | 155 | 10,547,200 | n, b, d = map(int, input().split())
lst = list(map(int, input().split()))
res = 0
waste_count = 0
for i in lst:
if i > b:
continue
else:
waste_count += i
if waste_count > d:
waste_count = 0
res += 1
print(res) | Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
n, b, d = map(int, input().split())
lst = list(map(int, input().split()))
res = 0
waste_count = 0
for i in lst:
if i > b:
continue
else:
waste_count += i
if waste_count > d:
waste_count = 0
res += 1
print(res)
``` | 3 | |
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water... | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the f... | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 ... | 1,679,910,287 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | x=int(input())
l=[int(p) for p in input().split()]
l.sort(reverse=True)
summ=0
if x==0:
print(0)
else:
for i in range(12):
summ+=l[i]
if summ>=x:
print(i+1)
break | Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya open... | ```python
x=int(input())
l=[int(p) for p in input().split()]
l.sort(reverse=True)
summ=0
if x==0:
print(0)
else:
for i in range(12):
summ+=l[i]
if summ>=x:
print(i+1)
break
``` | 0 | |
594 | D | REQ | PROGRAMMING | 2,500 | [
"data structures",
"number theory"
] | null | null | Today on a math lesson the teacher told Vovochka that the Euler function of a positive integer φ(*n*) is an arithmetic function that counts the positive integers less than or equal to n that are relatively prime to n. The number 1 is coprime to all the positive integers and φ(1)<==<=1.
Now the teacher gave Vovochka an... | The first line of the input contains number *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array given to Vovochka. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106).
The third line contains integer *q* (1<=≤<=*q*<=≤<=200<=000) — the number of queries. Next *q* lines contain the... | Print *q* numbers — the value of the Euler function for each query, calculated modulo 109<=+<=7. | [
"10\n1 2 3 4 5 6 7 8 9 10\n7\n1 1\n3 8\n5 6\n4 8\n8 10\n7 9\n7 10\n",
"7\n24 63 13 52 6 10 1\n6\n3 5\n4 7\n1 7\n2 4\n3 6\n2 6\n"
] | [
"1\n4608\n8\n1536\n192\n144\n1152\n",
"1248\n768\n12939264\n11232\n9984\n539136\n"
] | In the second sample the values are calculated like that:
- φ(13·52·6) = φ(4056) = 1248 - φ(52·6·10·1) = φ(3120) = 768 - φ(24·63·13·52·6·10·1) = φ(61326720) = 12939264 - φ(63·13·52) = φ(42588) = 11232 - φ(13·52·6·10) = φ(40560) = 9984 - φ(63·13·52·6·10) = φ(2555280) = 539136 | 2,000 | [
{
"input": "10\n1 2 3 4 5 6 7 8 9 10\n7\n1 1\n3 8\n5 6\n4 8\n8 10\n7 9\n7 10",
"output": "1\n4608\n8\n1536\n192\n144\n1152"
},
{
"input": "7\n24 63 13 52 6 10 1\n6\n3 5\n4 7\n1 7\n2 4\n3 6\n2 6",
"output": "1248\n768\n12939264\n11232\n9984\n539136"
},
{
"input": "5\n2 3 4 5 6\n5\n2 5\n2 ... | 1,616,528,430 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 3,000 | 307,200 | def factorise(n:int):
res = list()
d = 2
while d**2 <= n:
if n % d != 0:
d += 1
continue
a = 0
while n % d == 0:
a += 1
n //= d
res.append((d,a))
d += 1
if n != 1:
res.append((n, 1))
return res
def phi(... | Title: REQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a math lesson the teacher told Vovochka that the Euler function of a positive integer φ(*n*) is an arithmetic function that counts the positive integers less than or equal to n that are relatively prime to n. The number 1 ... | ```python
def factorise(n:int):
res = list()
d = 2
while d**2 <= n:
if n % d != 0:
d += 1
continue
a = 0
while n % d == 0:
a += 1
n //= d
res.append((d,a))
d += 1
if n != 1:
res.append((n, 1))
return res
... | 0 | |
591 | A | Wizards' Duel | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and... | The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ... | Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer ... | [
"100\n50\n50\n",
"199\n60\n40\n"
] | [
"50\n",
"119.4\n"
] | In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | 500 | [
{
"input": "100\n50\n50",
"output": "50"
},
{
"input": "199\n60\n40",
"output": "119.4"
},
{
"input": "1\n1\n1",
"output": "0.5"
},
{
"input": "1\n1\n500",
"output": "0.001996007984"
},
{
"input": "1\n500\n1",
"output": "0.998003992"
},
{
"input": "1\n... | 1,514,146,008 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 61 | 5,529,600 | l=float(input())
p=float(input())
q=float(input())
result=(l/(p+q))*p
print(result) | Title: Wizards' Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en... | ```python
l=float(input())
p=float(input())
q=float(input())
result=(l/(p+q))*p
print(result)
``` | 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,678,709,547 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 3,000 | 14,028,800 | a = int(input())
b= list(map(int, input().split()))
for i in range(a):
ref = b[0:i]+b[i+1:]
ans = ["",0]
for j in ref:
ref1 = abs(j-b[i])
if ans[0] =="" or ref1<ans[0]:
ans[0] = ref1
if ref1 >ans[1]:
ans[1] = ref1
print(ans[0],ans[1])
| Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
a = int(input())
b= list(map(int, input().split()))
for i in range(a):
ref = b[0:i]+b[i+1:]
ans = ["",0]
for j in ref:
ref1 = abs(j-b[i])
if ans[0] =="" or ref1<ans[0]:
ans[0] = ref1
if ref1 >ans[1]:
ans[1] = ref1
print(ans[0],ans[... | 0 | |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,680,954,148 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 1,029 | 9,625,600 | n=int(input())
l=list(map(int,input().split()))
pl=[0]
for i in range(n):
pl.append(l[i]+pl[i])
l.sort()
psl=[0]
for i in range(n):
psl.append(l[i]+psl[i])
for i in range(int(input())):
type,l,r=map(int,input().split())
if type==1:
print(pl[r]-pl[l-1])
else:
print(psl[r]-psl[l-1]) | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
n=int(input())
l=list(map(int,input().split()))
pl=[0]
for i in range(n):
pl.append(l[i]+pl[i])
l.sort()
psl=[0]
for i in range(n):
psl.append(l[i]+psl[i])
for i in range(int(input())):
type,l,r=map(int,input().split())
if type==1:
print(pl[r]-pl[l-1])
else:
print(psl[r]-psl[l-1])
``` | 3 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,482,560,354 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 4,608,000 | n = int(input())
pmike = 0
pandrew = 0
ganador = ''
while n:
if pmike > pandrew:
ganador = 'mike'
else:
ganador = 'andrew'
linea = input()
nombre = linea.split(' ')[0]
if nombre == 'mike':
pmike = pmike+int(linea.split(' ')[1])
else:
pandrew = pandre... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
n = int(input())
pmike = 0
pandrew = 0
ganador = ''
while n:
if pmike > pandrew:
ganador = 'mike'
else:
ganador = 'andrew'
linea = input()
nombre = linea.split(' ')[0]
if nombre == 'mike':
pmike = pmike+int(linea.split(' ')[1])
else:
pandre... | 0 |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,685,005,582 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 140 | 15,360,000 | import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
############ --... | Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
#####... | 3 | |
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,585,367,205 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 7,987,200 | def value(s, f):
return s*7 + f*4
n = int(input())
s = n // 7
f = (n % 7) // 4
diff = n - value(s, f)
if diff == 3:
s += 1
f -= 1
elif diff == 2:
f += 4
s -= 2
elif diff == 1:
s -= 1
f += 2
if s < 0 or f < 0:
print(-1)
else:
print(int(''.join(f * ['4'] + s * ['7'])))
... | 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
def value(s, f):
return s*7 + f*4
n = int(input())
s = n // 7
f = (n % 7) // 4
diff = n - value(s, f)
if diff == 3:
s += 1
f -= 1
elif diff == 2:
f += 4
s -= 2
elif diff == 1:
s -= 1
f += 2
if s < 0 or f < 0:
print(-1)
else:
print(int(''.join(f * ['4'] + s * ['7'])))
... | 0 |
912 | B | New Year's Eve | PROGRAMMING | 1,300 | [
"bitmasks",
"constructive algorithms",
"number theory"
] | null | null | Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a d... | The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018). | Output one number — the largest possible xor-sum. | [
"4 3\n",
"6 6\n"
] | [
"7\n",
"7\n"
] | In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.
In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7. | 1,000 | [
{
"input": "4 3",
"output": "7"
},
{
"input": "6 6",
"output": "7"
},
{
"input": "2 2",
"output": "3"
},
{
"input": "1022 10",
"output": "1023"
},
{
"input": "415853337373441 52",
"output": "562949953421311"
},
{
"input": "75 12",
"output": "127"
... | 1,660,168,514 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long x, y, i, suma=0;
unsigned long long pot[1000];
cin >> x >> y;
if(y == 1){
cout << x;
return 0;
}
long long c=log2(x);
pot[0]=1;
for(i=0; i<=c; i++)
{
pot[i+1]=2*pot[i];
}
if(pot[c] >... | Title: New Year's Eve
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* co... | ```python
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long x, y, i, suma=0;
unsigned long long pot[1000];
cin >> x >> y;
if(y == 1){
cout << x;
return 0;
}
long long c=log2(x);
pot[0]=1;
for(i=0; i<=c; i++)
{
pot[i+1]=2*pot[i];
}
i... | -1 | |
839 | A | Arya and Bran | PROGRAMMING | 900 | [
"implementation"
] | null | null | Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of ... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000).
The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | If it is impossible for Arya to give Bran *k* candies within *n* days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. | [
"2 3\n1 2\n",
"3 17\n10 10 10\n",
"1 9\n10\n"
] | [
"2",
"3",
"-1"
] | In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies with... | 500 | [
{
"input": "2 3\n1 2",
"output": "2"
},
{
"input": "3 17\n10 10 10",
"output": "3"
},
{
"input": "1 9\n10",
"output": "-1"
},
{
"input": "10 70\n6 5 2 3 3 2 1 4 3 2",
"output": "-1"
},
{
"input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99",... | 1,584,786,706 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 139 | 0 | a,b= input().split()
a=int(a)
b=int(b)
li= list(map(int, input().split()))
i=0
ans=0
c=0
extra=0
test=0
count=0
while i<len(li):
if int(li[i])>8:
extra= li[i]-8
add=8
else:
if extra!=0:
c= 8-li[i]
add=8
extra= extra-c
else:
... | Title: Arya and Bran
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**... | ```python
a,b= input().split()
a=int(a)
b=int(b)
li= list(map(int, input().split()))
i=0
ans=0
c=0
extra=0
test=0
count=0
while i<len(li):
if int(li[i])>8:
extra= li[i]-8
add=8
else:
if extra!=0:
c= 8-li[i]
add=8
extra= extra-c
... | 0 | |
787 | A | The Monster | PROGRAMMING | 1,200 | [
"brute force",
"math",
"number theory"
] | null | null | A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams at times *d*,<=*d*<=+<=*c*,<=*d*<=+<=2*c*,<=*d*<=+<=3*c*,<=....
The Monster will catch them if a... | The first line of input contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100).
The second line contains two integers *c* and *d* (1<=≤<=*c*,<=*d*<=≤<=100). | Print the first time Rick and Morty will scream at the same time, or <=-<=1 if they will never scream at the same time. | [
"20 2\n9 19\n",
"2 1\n16 12\n"
] | [
"82\n",
"-1\n"
] | In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time. | 500 | [
{
"input": "20 2\n9 19",
"output": "82"
},
{
"input": "2 1\n16 12",
"output": "-1"
},
{
"input": "39 52\n88 78",
"output": "1222"
},
{
"input": "59 96\n34 48",
"output": "1748"
},
{
"input": "87 37\n91 29",
"output": "211"
},
{
"input": "11 81\n49 7",
... | 1,563,685,852 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 124 | 0 |
# http://codeforces.com/problemset/problem/787/A
a, b = map(int, input().split())
c, d = map(int, input().split())
n = 0
m = 0
while (n < 10000) and (m < 10000):
abn = b + a*n
cdm = d + c*m
if (abn < cdm):
n += 1
elif (abn > cdm):
m += 1
else:
break
if (abn == cdm):
print(abn)
... | Title: The Monster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams a... | ```python
# http://codeforces.com/problemset/problem/787/A
a, b = map(int, input().split())
c, d = map(int, input().split())
n = 0
m = 0
while (n < 10000) and (m < 10000):
abn = b + a*n
cdm = d + c*m
if (abn < cdm):
n += 1
elif (abn > cdm):
m += 1
else:
break
if (abn == cdm):
p... | 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,682,026,540 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 | inp = input()
inp = list(inp)
hello = "hello"
hello = list(hello)
c = 0
for i in inp:
if i == hello[c]:
hello[c] = ""
c = c + 1
if c == len(hello):
break
if hello == ['','','','','']:
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
inp = input()
inp = list(inp)
hello = "hello"
hello = list(hello)
c = 0
for i in inp:
if i == hello[c]:
hello[c] = ""
c = c + 1
if c == len(hello):
break
if hello == ['','','','','']:
print("YES")
else:
print("NO")
``` | 3.9455 |
235 | A | LCM Challenge | PROGRAMMING | 1,600 | [
"number theory"
] | null | null | Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement. | Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*. | [
"9\n",
"7\n"
] | [
"504\n",
"210\n"
] | The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is ... | 500 | [
{
"input": "9",
"output": "504"
},
{
"input": "7",
"output": "210"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "60"
},
{
"input": "33",
"output": "32736"
},
{
"input": "21",
"output": ... | 1,571,734,712 | 2,147,483,647 | PyPy 3 | OK | TESTS | 87 | 436 | 3,276,800 | import math
def lcm(a, b):
return a * b // math.gcd(a, b)
n = int(input())
if n == 1:
print(1)
elif n == 2:
print(2)
else:
if n % 2 == 1:
print(n * (n - 1) * (n - 2))
else:
res = 0
for i in range(max(n - 50, 3), n + 1):
for j in range(max(n - 5... | Title: LCM Challenge
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive... | ```python
import math
def lcm(a, b):
return a * b // math.gcd(a, b)
n = int(input())
if n == 1:
print(1)
elif n == 2:
print(2)
else:
if n % 2 == 1:
print(n * (n - 1) * (n - 2))
else:
res = 0
for i in range(max(n - 50, 3), n + 1):
for j in range... | 3 | |
408 | A | Line to Cashier | PROGRAMMING | 900 | [
"implementation"
] | null | null | Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i*... | Print a single integer — the minimum number of seconds Vasya needs to get to the cashier. | [
"1\n1\n1\n",
"4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n"
] | [
"20\n",
"100\n"
] | In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou... | 500 | [
{
"input": "1\n1\n1",
"output": "20"
},
{
"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8",
"output": "100"
},
{
"input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3",
"output": "100"
},
{
"input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3"... | 1,530,187,943 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 93 | 0 | from math import inf
n = int(input().strip())
cus_num = list(map(int, input().strip().split()))
min_time = inf
for i in range(n):
lst = list(map(int, input().strip().split()))
time = cus_num[i] * 15 + sum(lst) * 5
min_time = min(min_time, time)
print(min_time) | Title: Line to Cashier
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* c... | ```python
from math import inf
n = int(input().strip())
cus_num = list(map(int, input().strip().split()))
min_time = inf
for i in range(n):
lst = list(map(int, input().strip().split()))
time = cus_num[i] * 15 + sum(lst) * 5
min_time = min(min_time, time)
print(min_time)
``` | 3 | |
1 | B | Spreadsheet | PROGRAMMING | 1,600 | [
"implementation",
"math"
] | B. Spreadsheets | 10 | 64 | In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow th... | The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=105), the number of coordinates in the test. Then there follow *n* lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 . | Write *n* lines, each line should contain a cell coordinates in the other numeration system. | [
"2\nR23C55\nBC23\n"
] | [
"BC23\nR23C55\n"
] | none | 0 | [
{
"input": "2\nR23C55\nBC23",
"output": "BC23\nR23C55"
},
{
"input": "1\nA1",
"output": "R1C1"
},
{
"input": "5\nR8C3\nD1\nR7C2\nR8C9\nR8C9",
"output": "C8\nR1C4\nB7\nI8\nI8"
},
{
"input": "4\nR4C25\nR90C35\nAP55\nX83",
"output": "Y4\nAI90\nR55C42\nR83C24"
},
{
"i... | 1,682,508,220 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 5 | 124 | 409,600 | import re
def number_to_string(num):
base = 26
result = ''
while num > 0:
char_code = (num - 1) % base
result = chr(char_code + ord('A')) + result
num = (num - 1) // base
return result
def from_base_26(s):
result = 0
for i, c in enumerate(reversed(s)):
... | Title: Spreadsheet
Time Limit: 10 seconds
Memory Limit: 64 megabytes
Problem Description:
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter n... | ```python
import re
def number_to_string(num):
base = 26
result = ''
while num > 0:
char_code = (num - 1) % base
result = chr(char_code + ord('A')) + result
num = (num - 1) // base
return result
def from_base_26(s):
result = 0
for i, c in enumerate(reversed... | -1 |
351 | E | Jeff and Permutation | PROGRAMMING | 2,200 | [
"greedy"
] | null | null | Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence *p*1,<=*p*2,<=...,<=*p**n* for his birthday.
Jeff hates inversions in sequences. An inversion in sequence *a*1,<=*a*2,<=...,<=*a**n* is a pair of indexes *i*,<=*j* (1<=≤<=*i*<=<<=*j*<=≤<=*n*), such... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000). The next line contains *n* integers — sequence *p*1, *p*2, ..., *p**n* (|*p**i*|<=≤<=105). The numbers are separated by spaces. | In a single line print the answer to the problem — the minimum number of inversions Jeff can get. | [
"2\n2 1\n",
"9\n-2 0 -1 0 -1 2 1 0 -1\n"
] | [
"0\n",
"6\n"
] | none | 2,000 | [
{
"input": "2\n2 1",
"output": "0"
},
{
"input": "9\n-2 0 -1 0 -1 2 1 0 -1",
"output": "6"
},
{
"input": "9\n0 0 1 1 0 0 1 0 1",
"output": "5"
},
{
"input": "8\n0 1 2 -1 -2 1 -2 2",
"output": "3"
},
{
"input": "24\n-1 -1 2 2 0 -2 2 -1 0 0 2 -2 3 0 2 -3 0 -3 -1 1 0... | 1,438,498,394 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n = int(input())
inp = input()
seq = inp.split(' ')
seq = [ abs(int(x)) for x in seq ]
Max = max(seq)
nxt = [0] * n
cnt = [0] * n
pos = [n] * (Max+1)
for i in range(n-1, -1, -1):
nxt[i] = pos[seq[i]]
pos[seq[i]] = i
for i in range(0, Max+1):
j = pos[i]
while(j<n):
front = sum(cnt[0:j])
b... | Title: Jeff and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence *p*1,<=*p*2,<=...,<=*p**n* for his birthday.
Jeff hates inversions in sequences. An inversion ... | ```python
n = int(input())
inp = input()
seq = inp.split(' ')
seq = [ abs(int(x)) for x in seq ]
Max = max(seq)
nxt = [0] * n
cnt = [0] * n
pos = [n] * (Max+1)
for i in range(n-1, -1, -1):
nxt[i] = pos[seq[i]]
pos[seq[i]] = i
for i in range(0, Max+1):
j = pos[i]
while(j<n):
front = sum(cnt[0:j])... | 0 | |
460 | A | Vasya and Socks | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la... | The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. | Print a single integer — the answer to the problem. | [
"2 2\n",
"9 3\n"
] | [
"3\n",
"13\n"
] | In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on... | 500 | [
{
"input": "2 2",
"output": "3"
},
{
"input": "9 3",
"output": "13"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "1 99",
"output": "1"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "10 2",
"outp... | 1,669,987,150 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 46 | 0 | n,m = map(int,input().split())
count = 0
while n > 0:
n -= 1
count += 1
if count%m == 0:
n +=1
print(count) | Title: Vasya and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th... | ```python
n,m = map(int,input().split())
count = 0
while n > 0:
n -= 1
count += 1
if count%m == 0:
n +=1
print(count)
``` | 3 | |
787 | A | The Monster | PROGRAMMING | 1,200 | [
"brute force",
"math",
"number theory"
] | null | null | A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams at times *d*,<=*d*<=+<=*c*,<=*d*<=+<=2*c*,<=*d*<=+<=3*c*,<=....
The Monster will catch them if a... | The first line of input contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100).
The second line contains two integers *c* and *d* (1<=≤<=*c*,<=*d*<=≤<=100). | Print the first time Rick and Morty will scream at the same time, or <=-<=1 if they will never scream at the same time. | [
"20 2\n9 19\n",
"2 1\n16 12\n"
] | [
"82\n",
"-1\n"
] | In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time. | 500 | [
{
"input": "20 2\n9 19",
"output": "82"
},
{
"input": "2 1\n16 12",
"output": "-1"
},
{
"input": "39 52\n88 78",
"output": "1222"
},
{
"input": "59 96\n34 48",
"output": "1748"
},
{
"input": "87 37\n91 29",
"output": "211"
},
{
"input": "11 81\n49 7",
... | 1,490,319,748 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 4,608,000 | '''input
2 1
16 12
'''
a, b = map(int, input().split())
c, d = map(int, input().split())
if (b % 2 != d % 2 and a % 2 == c % 2):
print(-1)
else:
for x in range(100):
for y in range(100):
if b + x*a == d + y*c:
print(b + x*a)
quit()
| Title: The Monster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams a... | ```python
'''input
2 1
16 12
'''
a, b = map(int, input().split())
c, d = map(int, input().split())
if (b % 2 != d % 2 and a % 2 == c % 2):
print(-1)
else:
for x in range(100):
for y in range(100):
if b + x*a == d + y*c:
print(b + x*a)
quit()
``` | 0 | |
604 | B | More Cowbell | PROGRAMMING | 1,400 | [
"binary search",
"greedy"
] | null | null | Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a sin... | The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=2·*k*<=≤<=100<=000), denoting the number of cowbells and the number of boxes, respectively.
The next line contains *n* space-separated integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s*1<=≤<=*s*2<=≤<=...<=≤<=*s**n*<=≤<=1<=000<=000... | Print a single integer, the smallest *s* for which it is possible for Kevin to put all of his cowbells into *k* boxes of size *s*. | [
"2 1\n2 5\n",
"4 3\n2 3 5 9\n",
"3 2\n3 5 7\n"
] | [
"7\n",
"9\n",
"8\n"
] | In the first sample, Kevin must pack his two cowbells into the same box.
In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}.
In the third sample, the optimal solution is {3, 5} and {7}. | 1,000 | [
{
"input": "2 1\n2 5",
"output": "7"
},
{
"input": "4 3\n2 3 5 9",
"output": "9"
},
{
"input": "3 2\n3 5 7",
"output": "8"
},
{
"input": "20 11\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10 10\n3 15 31 61 63 63 68 94 98 100",
"outp... | 1,557,152,471 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 155 | 7,782,400 | n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
x = max(n-k, 0)
if x == 0:
print(arr[-1])
exit()
res = arr[-1]
for i in range(x):
res = max(res, arr[i] + arr[2*x-i-1])
print(res)
| Title: More Cowbell
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order t... | ```python
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
x = max(n-k, 0)
if x == 0:
print(arr[-1])
exit()
res = arr[-1]
for i in range(x):
res = max(res, arr[i] + arr[2*x-i-1])
print(res)
``` | 3 | |
585 | A | Gennady the Dentist | PROGRAMMING | 1,800 | [
"brute force",
"implementation"
] | null | null | Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office.
All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to *n* in the order they go in the line. Every child is associated ... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=4000) — the number of kids in the line.
Next *n* lines contain three integers each *v**i*,<=*d**i*,<=*p**i* (1<=≤<=*v**i*,<=*d**i*,<=*p**i*<=≤<=106) — the volume of the cry in the doctor's office, the volume of the cry in the hall and the conf... | In the first line print number *k* — the number of children whose teeth Gennady will cure.
In the second line print *k* integers — the numbers of the children who will make it to the end of the line in the increasing order. | [
"5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n",
"5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n"
] | [
"2\n1 3 ",
"4\n1 2 4 5 "
] | In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to... | 500 | [
{
"input": "5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2",
"output": "2\n1 3 "
},
{
"input": "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9",
"output": "4\n1 2 4 5 "
},
{
"input": "10\n10 7 10\n3 6 11\n8 4 10\n10 1 11\n7 3 13\n7 2 13\n7 6 14\n3 4 17\n9 4 20\n5 2 24",
"output": "3\n1 2 5 "
},
{
... | 1,453,519,222 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 46 | 0 | def main():
n, res, vv, dd, pp = int(input()), [], [], [], []
for i in range(n):
v, d, p = map(int, input().split())
vv.append(v)
dd.append(d)
pp.append(p)
for i, v, d, p in zip(range(1, n + 1), vv, dd, pp):
if p < 0:
for j in range(i, n):
... | Title: Gennady the Dentist
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office.
All children love to cry loudly at the reception at the dentist. We enumer... | ```python
def main():
n, res, vv, dd, pp = int(input()), [], [], [], []
for i in range(n):
v, d, p = map(int, input().split())
vv.append(v)
dd.append(d)
pp.append(p)
for i, v, d, p in zip(range(1, n + 1), vv, dd, pp):
if p < 0:
for j in range(i, n):
... | 0 | |
65 | B | Harry Potter and the History of Magic | PROGRAMMING | 1,700 | [
"brute force",
"greedy",
"implementation"
] | B. Harry Potter and the History of Magic | 1 | 256 | The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has ... | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=1000). It represents the number of dates in Harry's notes. Next *n* lines contain the actual dates *y*1, *y*2, ..., *y**n*, each line contains a date. Each date is a four-digit integer (1000<=≤<=*y**i*<=≤<=9999). | Print *n* numbers *z*1, *z*2, ..., *z**n* (1000<=≤<=*z**i*<=≤<=2011). They are Ron's resulting dates. Print each number on a single line. Numbers *z**i* must form the non-decreasing sequence. Each number *z**i* should differ from the corresponding date *y**i* in no more than one digit. It is not allowed to change the f... | [
"3\n1875\n1936\n1721\n",
"4\n9999\n2000\n3000\n3011\n",
"3\n1999\n5055\n2000\n"
] | [
"1835\n1836\n1921\n",
"1999\n2000\n2000\n2011\n",
"No solution\n"
] | none | 1,000 | [
{
"input": "3\n1875\n1936\n1721",
"output": "1075\n1136\n1221"
},
{
"input": "4\n9999\n2000\n3000\n3011",
"output": "1999\n2000\n2000\n2011"
},
{
"input": "3\n1999\n5055\n2000",
"output": "No solution"
},
{
"input": "2\n2037\n2025",
"output": "1037\n2005"
},
{
"in... | 1,600,524,311 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 307,200 | def myfunc(x):
if x==x%10:
return x
elif x==x%100:
return (x//10)*10
elif x==x%1000:
return (x//100)*100
elif x==x%10000:
return (x//1000)*1000
n=int(input())
a=[]
for i in range(n):
x=int(input())
a.append(x)
prev=1000
z=1
for i in range(n):
... | Title: Harry Potter and the History of Magic
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectur... | ```python
def myfunc(x):
if x==x%10:
return x
elif x==x%100:
return (x//10)*10
elif x==x%1000:
return (x//100)*100
elif x==x%10000:
return (x//1000)*1000
n=int(input())
a=[]
for i in range(n):
x=int(input())
a.append(x)
prev=1000
z=1
for i in ran... | 0 |
246 | D | Colorful Graph | PROGRAMMING | 1,600 | [
"brute force",
"dfs and similar",
"graphs"
] | null | null | You've got an undirected graph, consisting of *n* vertices and *m* edges. We will consider the graph's vertices numbered with integers from 1 to *n*. Each vertex of the graph has a color. The color of the *i*-th vertex is an integer *c**i*.
Let's consider all vertices of the graph, that are painted some color *k*. Let... | The first line contains two space-separated integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of vertices end edges of the graph, correspondingly. The second line contains a sequence of integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105) — the colors of the graph vertices. The numbers on the line are sep... | Print the number of the color which has the set of neighbours with the maximum cardinality. It there are multiple optimal colors, print the color with the minimum number. Please note, that you want to find such color, that the graph has at least one vertex with such color. | [
"6 6\n1 1 2 3 5 8\n1 2\n3 2\n1 4\n4 3\n4 5\n4 6\n",
"5 6\n4 2 5 2 4\n1 2\n2 3\n3 1\n5 3\n5 4\n3 4\n"
] | [
"3\n",
"2\n"
] | none | 2,000 | [
{
"input": "6 6\n1 1 2 3 5 8\n1 2\n3 2\n1 4\n4 3\n4 5\n4 6",
"output": "3"
},
{
"input": "5 6\n4 2 5 2 4\n1 2\n2 3\n3 1\n5 3\n5 4\n3 4",
"output": "2"
},
{
"input": "3 1\n13 13 4\n1 2",
"output": "4"
},
{
"input": "2 1\n500 300\n1 2",
"output": "300"
},
{
"input":... | 1,605,594,749 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 1,152 | 18,432,000 | #parsea una línea
def parser():
return [int(x) for x in input().split()]
#Recibiendo n y m
n,m=parser()
#Recibiendo los colores de los vertices
colors_vertices=parser()
#Hallando el mayor de los colores
upper=max(colors_vertices)
#Se crean una cantidad de sets igual al numero mayor
adjacents_sets=[set() f... | Title: Colorful Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an undirected graph, consisting of *n* vertices and *m* edges. We will consider the graph's vertices numbered with integers from 1 to *n*. Each vertex of the graph has a color. The color of the *i*-th vertex i... | ```python
#parsea una línea
def parser():
return [int(x) for x in input().split()]
#Recibiendo n y m
n,m=parser()
#Recibiendo los colores de los vertices
colors_vertices=parser()
#Hallando el mayor de los colores
upper=max(colors_vertices)
#Se crean una cantidad de sets igual al numero mayor
adjacents_set... | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,684,043,754 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n = int(input())
fingers = sum(list(map(int, input().split())))
for x in range(1, 6):
if (fingers+x)%(n+1)!=1:
break
print(x) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n = int(input())
fingers = sum(list(map(int, input().split())))
for x in range(1, 6):
if (fingers+x)%(n+1)!=1:
break
print(x)
``` | 0 | |
250 | A | Paper Work | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know that the main information in a day report is value *a**i*, the company's profit on the *i*-th day. ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), *n* is the number of days. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=100), where *a**i* means the company profit on the *i*-th day. It is possible that the company has no days with the negative *a**i*. | Print an integer *k* — the required minimum number of folders. In the second line print a sequence of integers *b*1, *b*2, ..., *b**k*, where *b**j* is the number of day reports in the *j*-th folder.
If there are multiple ways to sort the reports into *k* days, print any of them. | [
"11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\n",
"5\n0 -1 100 -1 0\n"
] | [
"3\n5 3 3 ",
"1\n5 "
] | Here goes a way to sort the reports from the first sample into three folders:
In the second sample you can put all five reports in one folder. | 500 | [
{
"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6",
"output": "3\n5 3 3 "
},
{
"input": "5\n0 -1 100 -1 0",
"output": "1\n5 "
},
{
"input": "1\n0",
"output": "1\n1 "
},
{
"input": "1\n-1",
"output": "1\n1 "
},
{
"input": "2\n0 0",
"output": "1\n2 "
},
{
"inp... | 1,693,495,179 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | num = int(input())
reports = list(map(int, input().split(' ')))
count = 0
negative = 0
k = []
for r in reports:
if r < 0:
negative += 1
if negative == 3:
k.append(count)
count = 0
negative = 1
count += 1
k.append(count)
for i in range(len(k)):
print(k[i], end = ''... | Title: Paper Work
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know tha... | ```python
num = int(input())
reports = list(map(int, input().split(' ')))
count = 0
negative = 0
k = []
for r in reports:
if r < 0:
negative += 1
if negative == 3:
k.append(count)
count = 0
negative = 1
count += 1
k.append(count)
for i in range(len(k)):
print(k[i]... | 0 | |
998 | B | Cutting | PROGRAMMING | 1,200 | [
"dp",
"greedy",
"sortings"
] | null | null | There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulti... | First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have.
Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal... | Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins. | [
"6 4\n1 2 5 10 15 20\n",
"4 10\n1 3 2 4\n",
"6 100\n1 2 3 4 5 6\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins.
In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.
In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$.... | 1,000 | [
{
"input": "6 4\n1 2 5 10 15 20",
"output": "1"
},
{
"input": "4 10\n1 3 2 4",
"output": "0"
},
{
"input": "6 100\n1 2 3 4 5 6",
"output": "2"
},
{
"input": "2 100\n13 78",
"output": "0"
},
{
"input": "10 1\n56 56 98 2 11 64 97 41 95 53",
"output": "0"
},
... | 1,616,141,116 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 17 | 78 | 307,200 | ar=list(map(int,input().split()))
n=ar[0]
b=ar[1]
a=list(map(int,input().split()))
def yep(n,b,a):
g=0
k=[]
for i in range(n):
if a[i]%2==0:
g+=1
else:
g-=1
if g==0 and i<n-1:
k.append(abs(a[i]-a[i... | Title: Cutting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Gi... | ```python
ar=list(map(int,input().split()))
n=ar[0]
b=ar[1]
a=list(map(int,input().split()))
def yep(n,b,a):
g=0
k=[]
for i in range(n):
if a[i]%2==0:
g+=1
else:
g-=1
if g==0 and i<n-1:
k.append(ab... | 0 | |
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should cons... | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letter... | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcde... | 1,641,075,197 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 124 | 2,048,000 | import string
alphabet = string.ascii_lowercase
n, k = map(int, input().split())
password = ['' for _ in range(n)]
candidates = alphabet[:k]
curr = 0
for i in range(n):
password[i] = candidates[curr%k]
curr += 1
print(''.join(password))
| Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the foll... | ```python
import string
alphabet = string.ascii_lowercase
n, k = map(int, input().split())
password = ['' for _ in range(n)]
candidates = alphabet[:k]
curr = 0
for i in range(n):
password[i] = candidates[curr%k]
curr += 1
print(''.join(password))
``` | 3 | |
388 | A | Fox and Box Accumulation | PROGRAMMING | 1,400 | [
"greedy",
"sortings"
] | null | null | Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100). | Output a single integer — the minimal possible number of piles. | [
"3\n0 0 10\n",
"5\n0 1 2 3 4\n",
"4\n0 0 0 0\n",
"9\n0 1 0 2 0 1 1 2 10\n"
] | [
"2\n",
"1\n",
"4\n",
"3\n"
] | In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). | 500 | [
{
"input": "3\n0 0 10",
"output": "2"
},
{
"input": "5\n0 1 2 3 4",
"output": "1"
},
{
"input": "4\n0 0 0 0",
"output": "4"
},
{
"input": "9\n0 1 0 2 0 1 1 2 10",
"output": "3"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "2\n0 0",
"output": "... | 1,605,358,366 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 124 | 409,600 | from collections import Counter as cs
n=int(input())
ls=[int(a) for a in input().split()]
ls.sort()
ls1=dict(cs(ls))
ctr1,ctr2=1,0
for i in range(n):
if ls1[ls[i]]:
ls1[ls[i]]-=1
for j in range(i,n):
if i!=j and ls[j]>=ctr1 and ls1[ls[j]]:
ctr1+=1
... | Title: Fox and Box Accumulation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box... | ```python
from collections import Counter as cs
n=int(input())
ls=[int(a) for a in input().split()]
ls.sort()
ls1=dict(cs(ls))
ctr1,ctr2=1,0
for i in range(n):
if ls1[ls[i]]:
ls1[ls[i]]-=1
for j in range(i,n):
if i!=j and ls[j]>=ctr1 and ls1[ls[j]]:
ctr1+=1
... | 3 | |
319 | B | Psychos in a Line | PROGRAMMING | 1,900 | [
"data structures",
"implementation"
] | null | null | There are *n* psychos standing in a line. Each psycho is assigned a unique integer from 1 to *n*. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and get killed at the same step.
You're given the initial arran... | The first line of input contains integer *n* denoting the number of psychos, (1<=≤<=*n*<=≤<=105). In the second line there will be a list of *n* space separated distinct integers each in range 1 to *n*, inclusive — ids of the psychos in the line from left to right. | Print the number of steps, so that the line remains the same afterward. | [
"10\n10 9 7 8 6 5 3 4 2 1\n",
"6\n1 2 3 4 5 6\n"
] | [
"2\n",
"0\n"
] | In the first sample line of the psychos transforms as follows: [10 9 7 8 6 5 3 4 2 1] → [10 8 4] → [10]. So, there are two steps. | 1,000 | [
{
"input": "10\n10 9 7 8 6 5 3 4 2 1",
"output": "2"
},
{
"input": "6\n1 2 3 4 5 6",
"output": "0"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "1"
},
{
"input": "10\n10 7 4 2 5 8 9 6 3 1",
"output": "4"
},
{
"input": "15\n15 9 5 10 7 11 14 6 2 3 12 1 8 13 4",
"o... | 1,598,986,507 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 307,200 | n = int(input())
a = list(map(int,input().split()))
b = [0]; curr = a[0];
for i in range(1,len(a)):
if a[i-1]>a[i]:
continue
if a[i-1]<=a[i]:
if a[i]<curr:
b[-1] += 1
else:
curr = a[i]
b.append(1)
c = max(b)
if c == 1:
print(0)
elif c == 0:
pr... | Title: Psychos in a Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* psychos standing in a line. Each psycho is assigned a unique integer from 1 to *n*. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in th... | ```python
n = int(input())
a = list(map(int,input().split()))
b = [0]; curr = a[0];
for i in range(1,len(a)):
if a[i-1]>a[i]:
continue
if a[i-1]<=a[i]:
if a[i]<curr:
b[-1] += 1
else:
curr = a[i]
b.append(1)
c = max(b)
if c == 1:
print(0)
elif c ==... | 0 | |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,699,079,030 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 9,318,400 | n = int(input()) # number of magnets
magnets = [input() for _ in range(n)] # read the magnets
groups = 1 # at least one group is there
for i in range(1, n):
if magnets[i] != magnets[i - 1]: # if the current magnet doesn't stick to the previous one
groups += 1
print(groups)
| Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
n = int(input()) # number of magnets
magnets = [input() for _ in range(n)] # read the magnets
groups = 1 # at least one group is there
for i in range(1, n):
if magnets[i] != magnets[i - 1]: # if the current magnet doesn't stick to the previous one
groups += 1
print(groups)
``` | 0 | |
659 | A | Round House | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th... | The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. | Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n"
] | [
"3\n",
"4\n",
"3\n"
] | The first example is illustrated by the picture in the statements. | 500 | [
{
"input": "6 2 -5",
"output": "3"
},
{
"input": "5 1 3",
"output": "4"
},
{
"input": "3 2 7",
"output": "3"
},
{
"input": "1 1 0",
"output": "1"
},
{
"input": "1 1 -1",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 ... | 1,653,716,902 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | n, a, b = map(int, input().split())
k = abs(a + b - b//n*n) if b > 0 else abs(a + b + abs(b)//n*n)
print(k) | Title: Round House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in e... | ```python
n, a, b = map(int, input().split())
k = abs(a + b - b//n*n) if b > 0 else abs(a + b + abs(b)//n*n)
print(k)
``` | 0 | |
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,618,082,886 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 61 | 0 | n,k=map(int,input().split())
l=list(map(int,input().split()))
for i in range(len(l)):
left=86400-l[i]
if left>=k:
print(i+1)
else:
k=k-left
| Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of ... | ```python
n,k=map(int,input().split())
l=list(map(int,input().split()))
for i in range(len(l)):
left=86400-l[i]
if left>=k:
print(i+1)
else:
k=k-left
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | In some country live wizards. They love to ride trolleybuses.
A city in this country has a trolleybus depot with *n* trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final station is at a distance of *d* meters from the depot. We know for the *i*-th trolleybus that ... | The first input line contains three space-separated integers *n*, *a*, *d* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*d*<=≤<=106) — the number of trolleybuses, their maximum acceleration and the distance from the depot to the final station, correspondingly.
Next *n* lines contain pairs of integers *t**i* *v**i* (0<=≤<=*t*1<=<... | For each trolleybus print a single line the time it arrives to the final station. Print the times for the trolleybuses in the order in which the trolleybuses are given in the input. The answer will be accepted if the absolute or relative error doesn't exceed 10<=-<=4. | [
"3 10 10000\n0 10\n5 11\n1000 1\n",
"1 2 26\n28 29\n"
] | [
"1000.5000000000\n1000.5000000000\n11000.0500000000\n",
"33.0990195136\n"
] | In the first sample the second trolleybus will catch up with the first one, that will happen at distance 510.5 meters from the depot. The trolleybuses will go the remaining 9489.5 meters together at speed 10 meters per second. As a result, both trolleybuses will arrive to the final station by the moment of time 1000.5 ... | 0 | [
{
"input": "3 10 10000\n0 10\n5 11\n1000 1",
"output": "1000.5000000000\n1000.5000000000\n11000.0500000000"
},
{
"input": "1 2 26\n28 29",
"output": "33.0990195136"
},
{
"input": "7 8 3\n1 3\n5 26\n7 3\n10 15\n18 7\n21 17\n23 21",
"output": "2.1875000000\n5.8660254038\n8.1875000000\n... | 1,627,485,511 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 14 | 1,000 | 6,963,200 | n,a,d=map(int,input().split())
old=0
for i in range(n):
t,v=map(int,input().split())
if d<=(v**2)/2/a: # все время разгон
t1=t+(2*d/a)**0.5
else:
t1=t+v/a+(d-(v**2)/2/a)/v
old=max(t1,old)
print(old)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some country live wizards. They love to ride trolleybuses.
A city in this country has a trolleybus depot with *n* trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final stat... | ```python
n,a,d=map(int,input().split())
old=0
for i in range(n):
t,v=map(int,input().split())
if d<=(v**2)/2/a: # все время разгон
t1=t+(2*d/a)**0.5
else:
t1=t+v/a+(d-(v**2)/2/a)/v
old=max(t1,old)
print(old)
``` | 0 | |
688 | B | Lovely Palindromes | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). | Print the *n*-th even-length palindrome number. | [
"1\n",
"10\n"
] | [
"11\n",
"1001\n"
] | The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001. | 1,000 | [
{
"input": "1",
"output": "11"
},
{
"input": "10",
"output": "1001"
},
{
"input": "11",
"output": "1111"
},
{
"input": "12",
"output": "1221"
},
{
"input": "100",
"output": "100001"
},
{
"input": "1321",
"output": "13211231"
},
{
"input": "... | 1,586,000,323 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 614,400 | t=input()
s=t[::-1]
print(int(t+s)) | Title: Lovely Palindromes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is tr... | ```python
t=input()
s=t[::-1]
print(int(t+s))
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are st... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=1018) — the number of players to participate in the tournament. | Print the maximum number of games in which the winner of the tournament can take part. | [
"2\n",
"3\n",
"4\n",
"10\n"
] | [
"1\n",
"2\n",
"2\n",
"4\n"
] | In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't p... | 0 | [
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "1000",
"output": "14"
},
{
"input": "2500",
"output": "15"
},
{
"input": "690000",
"output"... | 1,485,466,911 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 4,608,000 | n = int(input())
for i in range(9999999999):
if 2**i >= n:
print(i)
break
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That me... | ```python
n = int(input())
for i in range(9999999999):
if 2**i >= n:
print(i)
break
``` | 0 | |
227 | A | Where do I Turn? | PROGRAMMING | 1,300 | [
"geometry"
] | null | null | Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point *C* and began to terrorize the residents of the surrounding villages.
A brave hero decided to put an end to the dragon. He moved from point *A* to fight with Gorynych. The hero rode from point *A* along a straight... | The first input line contains two space-separated integers *x**a*,<=*y**a* (|*x**a*|,<=|*y**a*|<=≤<=109) — the coordinates of point *A*. The second line contains the coordinates of point *B* in the same form, the third line contains the coordinates of point *C*.
It is guaranteed that all points are pairwise different.... | Print a single line. If a hero must turn left, print "LEFT" (without the quotes); If he must go straight ahead, print "TOWARDS" (without the quotes); if he should turn right, print "RIGHT" (without the quotes). | [
"0 0\n0 1\n1 1\n",
"-1 -1\n-3 -3\n-4 -4\n",
"-4 -6\n-3 -7\n-2 -6\n"
] | [
"RIGHT\n",
"TOWARDS\n",
"LEFT\n"
] | The picture to the first sample:
The red color shows points A, B and C. The blue arrow shows the hero's direction. The green color shows the hero's trajectory.
The picture to the second sample: | 500 | [
{
"input": "0 0\n0 1\n1 1",
"output": "RIGHT"
},
{
"input": "-1 -1\n-3 -3\n-4 -4",
"output": "TOWARDS"
},
{
"input": "-4 -6\n-3 -7\n-2 -6",
"output": "LEFT"
},
{
"input": "-44 57\n-118 -41\n-216 33",
"output": "RIGHT"
},
{
"input": "39 100\n90 85\n105 136",
"o... | 1,676,216,861 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | import math
coordenadas_a = [int(x) for x in input().split()]
ponto_a_x, ponto_a_y = coordenadas_a
coordenadas_b = [int(x) for x in input().split()]
ponto_b_x, ponto_b_y = coordenadas_b
coordenadas_c = [int(x) for x in input().split()]
ponto_c_x, ponto_c_y = coordenadas_c
resultado = (ponto_b_x - ponto_a_x) * (pont... | Title: Where do I Turn?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point *C* and began to terrorize the residents of the surrounding villages.
A brave hero decided to put an end to the... | ```python
import math
coordenadas_a = [int(x) for x in input().split()]
ponto_a_x, ponto_a_y = coordenadas_a
coordenadas_b = [int(x) for x in input().split()]
ponto_b_x, ponto_b_y = coordenadas_b
coordenadas_c = [int(x) for x in input().split()]
ponto_c_x, ponto_c_y = coordenadas_c
resultado = (ponto_b_x - ponto_a_... | 0 | |
858 | B | Which floor? | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are o... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=100), where *n* is the number of the flat you need to restore floor for, and *m* is the number of flats in Polycarp's memory.
*m* lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers *k**i*,<=*... | Print the number of the floor in which the *n*-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. | [
"10 3\n6 2\n2 1\n7 3\n",
"8 4\n3 1\n6 2\n5 2\n2 1\n"
] | [
"4\n",
"-1\n"
] | In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-... | 750 | [
{
"input": "10 3\n6 2\n2 1\n7 3",
"output": "4"
},
{
"input": "8 4\n3 1\n6 2\n5 2\n2 1",
"output": "-1"
},
{
"input": "8 3\n7 2\n6 2\n1 1",
"output": "2"
},
{
"input": "4 2\n8 3\n3 1",
"output": "2"
},
{
"input": "11 4\n16 4\n11 3\n10 3\n15 4",
"output": "3"
... | 1,560,094,213 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 124 | 0 | l = input()
n, m = (int(s) for s in l.split())
h = []
v = None
for i in range(m):
vo = set()
a, b = (int(s) for s in input().split())
if b-1==0:
continue
n1 = (a-1)//(b-1)
if n1!=0:
while (a-1)//n1==b-1:
vo.add(n1)
n1-=1
if n1==0:
... | Title: Which floor?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to u... | ```python
l = input()
n, m = (int(s) for s in l.split())
h = []
v = None
for i in range(m):
vo = set()
a, b = (int(s) for s in input().split())
if b-1==0:
continue
n1 = (a-1)//(b-1)
if n1!=0:
while (a-1)//n1==b-1:
vo.add(n1)
n1-=1
if n1==0:
... | -1 | |
459 | A | Pashmak and Garden | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al... | The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct. | If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<... | [
"0 0 0 1\n",
"0 0 1 1\n",
"0 0 1 2\n"
] | [
"1 0 1 1\n",
"0 1 1 0\n",
"-1\n"
] | none | 500 | [
{
"input": "0 0 0 1",
"output": "1 0 1 1"
},
{
"input": "0 0 1 1",
"output": "0 1 1 0"
},
{
"input": "0 0 1 2",
"output": "-1"
},
{
"input": "-100 -100 100 100",
"output": "-100 100 100 -100"
},
{
"input": "-100 -100 99 100",
"output": "-1"
},
{
"input... | 1,670,665,212 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 46 | 0 | x,y,x1,y1 = map(int,input().split())
if x-y == x1-y1 : d = abs(x-x1) ;print(x+d,y,x1-d,y1)
elif x == x1 :d = abs(y-y1); print(x+d,y,x1+d,y1)
elif y == y1 :d = abs(x-x1); print(x,y+d,x1,y1+d)
else : print(-1)
| Title: Pashmak and Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is... | ```python
x,y,x1,y1 = map(int,input().split())
if x-y == x1-y1 : d = abs(x-x1) ;print(x+d,y,x1-d,y1)
elif x == x1 :d = abs(y-y1); print(x+d,y,x1+d,y1)
elif y == y1 :d = abs(x-x1); print(x,y+d,x1,y1+d)
else : print(-1)
``` | 0 | |
306 | A | Candies | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *... | The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends. | Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value. | [
"12 3\n",
"15 4\n",
"18 7\n"
] | [
"4 4 4 ",
"3 4 4 4 ",
"2 2 2 3 3 3 3 "
] | Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces. | 500 | [
{
"input": "12 4",
"output": "3 3 3 3 "
},
{
"input": "15 6",
"output": "2 2 2 3 3 3 "
},
{
"input": "18 8",
"output": "2 2 2 2 2 2 3 3 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "2 1",
"output": "2 "
},
{
"input": "100 1",
"output": "100 ... | 1,628,967,476 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 124 | 6,758,400 | n,m= map(int,input().split())
a=[n//m for i in range(m)]
for i in range(n%m):
a[i]+=1
for i in range(m):
print(a[i],end= " ")
| Title: Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most ... | ```python
n,m= map(int,input().split())
a=[n//m for i in range(m)]
for i in range(n%m):
a[i]+=1
for i in range(m):
print(a[i],end= " ")
``` | 3 | |
673 | A | Bear and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order. | Print the number of minutes Limak will watch the game. | [
"3\n7 20 88\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"9\n15 20 30 40 50 60 70 80 90\n"
] | [
"35\n",
"15\n",
"90\n"
] | In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the w... | 500 | [
{
"input": "3\n7 20 88",
"output": "35"
},
{
"input": "9\n16 20 30 40 50 60 70 80 90",
"output": "15"
},
{
"input": "9\n15 20 30 40 50 60 70 80 90",
"output": "90"
},
{
"input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88",
... | 1,555,495,958 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 108 | 0 | n = int(input())
interest = list(map(int, input().split()))
minute = 15
if interest[0] > 15:
print(minute)
exit()
if n == 0:
print(minute)
exit()
else:
for i in range(0, n):
if interest[i] <= minute:
minute = interest[i] + 15
else:
break
if minute > 90:
pr... | Title: Bear and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Lim... | ```python
n = int(input())
interest = list(map(int, input().split()))
minute = 15
if interest[0] > 15:
print(minute)
exit()
if n == 0:
print(minute)
exit()
else:
for i in range(0, n):
if interest[i] <= minute:
minute = interest[i] + 15
else:
break
if minute > ... | 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,632,350,429 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 61 | 6,758,400 | x=input()
if x.index('h')<x.index('e')<x.index('ll')<x.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
x=input()
if x.index('h')<x.index('e')<x.index('ll')<x.index('o'):
print(" YES")
else:print("NO")
``` | -1 |
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,688,573,041 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n=int(input())
for i in range(n):
a=input()
l=len(a)
if(l<10):
print(a)
else:
print("%c%d%c\n"%(a[0],l-2,a[l-1])) | 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
n=int(input())
for i in range(n):
a=input()
l=len(a)
if(l<10):
print(a)
else:
print("%c%d%c\n"%(a[0],l-2,a[l-1]))
``` | 0 |
525 | B | Pasha and String | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"math",
"strings"
] | null | null | Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha ... | The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<... | In the first line of the output print what Pasha's string *s* will look like after *m* days. | [
"abcdef\n1\n2\n",
"vwxyz\n2\n2 2\n",
"abcdef\n3\n1 2 3\n"
] | [
"aedcbf\n",
"vwxyz\n",
"fbdcea\n"
] | none | 750 | [
{
"input": "abcdef\n1\n2",
"output": "aedcbf"
},
{
"input": "vwxyz\n2\n2 2",
"output": "vwxyz"
},
{
"input": "abcdef\n3\n1 2 3",
"output": "fbdcea"
},
{
"input": "jc\n5\n1 1 1 1 1",
"output": "cj"
},
{
"input": "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3",
"out... | 1,541,572,310 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 2,000 | 7,270,400 | x=input()
m=int(input())
a1=[int(i) for i in input().split()]
ll=len(x)
for i in range(m):
a=''
a+=x[:a1[i]-1]
z=list(x[a1[i]-1:ll-a1[i]+1])
z.reverse()
for j in z:
a+=j
a+=x[ll-a1[i]+1:]
x=a
print(x)
| Title: Pasha and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given ... | ```python
x=input()
m=int(input())
a1=[int(i) for i in input().split()]
ll=len(x)
for i in range(m):
a=''
a+=x[:a1[i]-1]
z=list(x[a1[i]-1:ll-a1[i]+1])
z.reverse()
for j in z:
a+=j
a+=x[ll-a1[i]+1:]
x=a
print(x)
``` | 0 | |
573 | A | Bear and Poker | PROGRAMMING | 1,300 | [
"implementation",
"math",
"number theory"
] | null | null | Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any nu... | First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players. | Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. | [
"4\n75 150 75 50\n",
"3\n100 150 250\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | 500 | [
{
"input": "4\n75 150 75 50",
"output": "Yes"
},
{
"input": "3\n100 150 250",
"output": "No"
},
{
"input": "7\n34 34 68 34 34 68 34",
"output": "Yes"
},
{
"input": "10\n72 96 12 18 81 20 6 2 54 1",
"output": "No"
},
{
"input": "20\n958692492 954966768 77387000 724... | 1,672,579,924 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 498 | 10,137,600 | n = int(input())
x_list = input().split()
a_list = [int(item) for item in x_list]
j = 1
num_list = [0 for n in range(n)]
for i in range(n):
num = a_list[i]
while num % 2 == 0 :
num = num / 2
while num % 3 == 0:
num = num / 3
num_list[i] = num
if i>0:
... | Title: Bear and Poker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid wit... | ```python
n = int(input())
x_list = input().split()
a_list = [int(item) for item in x_list]
j = 1
num_list = [0 for n in range(n)]
for i in range(n):
num = a_list[i]
while num % 2 == 0 :
num = num / 2
while num % 3 == 0:
num = num / 3
num_list[i] = num
if ... | 3 | |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,681,676,940 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 280 | 204,800 | a1, a2, a3, a4 = map(int, input().split())
s = input()
count= 0
for i in s:
if int(i) == 1: count += a1
if int(i) == 2: count += a2
if int(i) == 3: count += a3
if int(i) == 4: count += a4
print(count) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
a1, a2, a3, a4 = map(int, input().split())
s = input()
count= 0
for i in s:
if int(i) == 1: count += a1
if int(i) == 2: count += a2
if int(i) == 3: count += a3
if int(i) == 4: count += a4
print(count)
``` | 3 | |
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output"... | 1,609,767,472 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 218 | 0 | n=int(input())
l=list(map(int,input().split()))
print(l.index(min(l))+1,end=" ")
l.remove(min(l))
print(l.index(min(l))+2) | Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So... | ```python
n=int(input())
l=list(map(int,input().split()))
print(l.index(min(l))+1,end=" ")
l.remove(min(l))
print(l.index(min(l))+2)
``` | 0 |
799 | A | Carrot Cakes | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady... | The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. | If it is reasonable to build the second oven, print "YES". Otherwise print "NO". | [
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] | In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whe... | 500 | [
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"... | 1,677,934,645 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | import math
n, t, k , d= map(lambda x:int(x), input().split(" "))
tos=math.ceil(n*1.0/t)
# if(tos-d<=0):
# print("NO")
maxtime=tos-1
cakes=((maxtime//t)+(maxtime-d)//t)*k
if(cakes>=n):
print("YES")
else:
print("NO")
| Title: Carrot Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu... | ```python
import math
n, t, k , d= map(lambda x:int(x), input().split(" "))
tos=math.ceil(n*1.0/t)
# if(tos-d<=0):
# print("NO")
maxtime=tos-1
cakes=((maxtime//t)+(maxtime-d)//t)*k
if(cakes>=n):
print("YES")
else:
print("NO")
``` | 0 | |
129 | B | Students and Shoelaces | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the f... | The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*... | Print the single number — the number of groups of students that will be kicked out from the club. | [
"3 3\n1 2\n2 3\n3 1\n",
"6 3\n1 2\n2 3\n3 4\n",
"6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two ... | 1,000 | [
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "0"
},
{
"input": "6 3\n1 2\n2 3\n3 4",
"output": "2"
},
{
"input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4",
"output": "1"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "0"
},
... | 1,606,705,028 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 218 | 307,200 | #Inpirado em:
#https://zhuanlan.zhihu.com/p/103796326
n, m = tuple([int(x) for x in input().split(' ')])
P = [[int(x) for x in input().split(' ')] for i in range(m)]
G = [[0]*n]*n
N = [0]*n
count = 0
for i in range(m):
G[P[i][0]-1][P[i][1]-1] = 1
G[P[i][1]-1][P[i][0]-1] = 1
N[P[i][0]-1] += 1
N[P[i][... | Title: Students and Shoelaces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifica... | ```python
#Inpirado em:
#https://zhuanlan.zhihu.com/p/103796326
n, m = tuple([int(x) for x in input().split(' ')])
P = [[int(x) for x in input().split(' ')] for i in range(m)]
G = [[0]*n]*n
N = [0]*n
count = 0
for i in range(m):
G[P[i][0]-1][P[i][1]-1] = 1
G[P[i][1]-1][P[i][0]-1] = 1
N[P[i][0]-1] += 1
... | 0 | |
522 | A | Reposts | PROGRAMMING | 1,200 | [
"*special",
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the n... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and ... | Print a single integer — the maximum length of a repost chain. | [
"5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n",
"6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n",
"1\nSoMeStRaNgEgUe repos... | [
"6\n",
"2\n",
"2\n"
] | none | 500 | [
{
"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya",
"output": "6"
},
{
"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforc... | 1,567,826,006 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 109 | 0 | n=int(input())
l='polycarp'
x=1
for i in range(n):
s = input().lower().split()
if s[0] not in l and s[2] in l:
l=s[0]
x+=1
print(x)
| Title: Reposts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
... | ```python
n=int(input())
l='polycarp'
x=1
for i in range(n):
s = input().lower().split()
if s[0] not in l and s[2] in l:
l=s[0]
x+=1
print(x)
``` | 0 | |
478 | B | Random Teams | PROGRAMMING | 1,300 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that coul... | The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively. | The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. | [
"5 1\n",
"3 2\n",
"6 3\n"
] | [
"10 10\n",
"1 1\n",
"3 6\n"
] | In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
... | 1,000 | [
{
"input": "5 1",
"output": "10 10"
},
{
"input": "3 2",
"output": "1 1"
},
{
"input": "6 3",
"output": "3 6"
},
{
"input": "5 3",
"output": "2 3"
},
{
"input": "10 2",
"output": "20 36"
},
{
"input": "10 6",
"output": "4 10"
},
{
"input": ... | 1,656,158,202 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 92 | 0 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = n//m
b = n%m
c = n-m+1
if b == 0:
print(m*a*(a-1)//2, c*(c-1)//2)
else:
print(b*(a+1)*a//2 + (m-b)*a*(a-1)//2, c*(c-1)//2) | Title: Random Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is ... | ```python
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = n//m
b = n%m
c = n-m+1
if b == 0:
print(m*a*(a-1)//2, c*(c-1)//2)
else:
print(b*(a+1)*a//2 + (m-b)*a*(a-1)//2, c*(c-1)//2)
``` | 3 | |
598 | D | Igor In the Museum | PROGRAMMING | 1,700 | [
"dfs and similar",
"graphs",
"shortest paths"
] | null | null | Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one i... | First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process.
Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that ... | Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position. | [
"5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n",
"4 4 1\n****\n*..*\n*.**\n****\n3 2\n"
] | [
"6\n4\n10\n",
"8\n"
] | none | 0 | [
{
"input": "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3",
"output": "6\n4\n10"
},
{
"input": "4 4 1\n****\n*..*\n*.**\n****\n3 2",
"output": "8"
},
{
"input": "3 3 1\n***\n*.*\n***\n2 2",
"output": "4"
},
{
"input": "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\... | 1,627,922,893 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 32 | 1,000 | 87,244,800 | import sys
input=sys.stdin.readline
def dfs(i,j,f):
q[i][j]=g
z=[(i,j)]
c=0
while z:
i,j=z.pop()
for x,y in (i-1,j),(i,j+1),(i+1,j),(i,j-1):
if q[x][y]=='*': c+=1
elif q[x][y]=='.':
q[x][y]=f
z.append((x,y))
w[f]=c
... | Title: Igor In the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.'... | ```python
import sys
input=sys.stdin.readline
def dfs(i,j,f):
q[i][j]=g
z=[(i,j)]
c=0
while z:
i,j=z.pop()
for x,y in (i-1,j),(i,j+1),(i+1,j),(i,j-1):
if q[x][y]=='*': c+=1
elif q[x][y]=='.':
q[x][y]=f
z.append((x,y))
... | 0 | |
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string — the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht... | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n100000... | 1,632,212,613 | 2,147,483,647 | PyPy 3 | OK | TESTS | 14 | 93 | 20,172,800 | n, s = int(input()), input()
if len(s) == 1: print(s)
else:
dem = 0
for x in s:
if x == '0': dem += 1
print('1' + '0' * dem) | Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two... | ```python
n, s = int(input()), input()
if len(s) == 1: print(s)
else:
dem = 0
for x in s:
if x == '0': dem += 1
print('1' + '0' * dem)
``` | 3 | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,681,403,498 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 154 | 0 | t = int(input())
r = [int(i) for i in input().split()]
minr = r[0]
maxr = r[0]
res = 0
for i in r[1::]:
if i > maxr:
res += 1
maxr = i
elif i < minr:
res += 1
minr = i
print(res) | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
t = int(input())
r = [int(i) for i in input().split()]
minr = r[0]
maxr = r[0]
res = 0
for i in r[1::]:
if i > maxr:
res += 1
maxr = i
elif i < minr:
res += 1
minr = i
print(res)
``` | 3 | |
600 | B | Queries about less or equal elements | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | 0 | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -77918754... | 1,653,321,146 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 2,000 | 19,558,400 | def binarysearch1(target,a):
l=0
r=len(a)-1
ind=0
while(l<=r):
m=int(l+(r-l)/2)
if(a[m]<=target):
ind=m+1
l=m+1
else:
r=m-1
return ind
l=list(map(int,input().split()))
n=l[0]
m=l[1]
a=list(map(int,input().split()))
a.sort()
b=list(map(... | Title: Queries about less or equal elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
In... | ```python
def binarysearch1(target,a):
l=0
r=len(a)-1
ind=0
while(l<=r):
m=int(l+(r-l)/2)
if(a[m]<=target):
ind=m+1
l=m+1
else:
r=m-1
return ind
l=list(map(int,input().split()))
n=l[0]
m=l[1]
a=list(map(int,input().split()))
a.sort()
b... | 0 | |
964 | A | Splits | PROGRAMMING | 800 | [
"math"
] | null | null | Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$.
Th... | The first line contains one integer $n$ ($1 \leq n \leq 10^9$). | Output one integer — the answer to the problem. | [
"7\n",
"8\n",
"9\n"
] | [
"4\n",
"5\n",
"5\n"
] | In the first sample, there are following possible weights of splits of $7$:
Weight 1: [$\textbf 7$]
Weight 2: [$\textbf 3$, $\textbf 3$, 1]
Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1]
Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$] | 500 | [
{
"input": "7",
"output": "4"
},
{
"input": "8",
"output": "5"
},
{
"input": "9",
"output": "5"
},
{
"input": "1",
"output": "1"
},
{
"input": "286",
"output": "144"
},
{
"input": "48",
"output": "25"
},
{
"input": "941",
"output": "471... | 1,524,858,473 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 93 | 7,065,600 | n = int(input())
print(1+n//2)
| Title: Splits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The foll... | ```python
n = int(input())
print(1+n//2)
``` | 3 | |
681 | A | A Good Contest | PROGRAMMING | 800 | [
"implementation"
] | null | null | Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of hi... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*be... | Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise. | [
"3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n",
"3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n"
] | [
"YES",
"NO"
] | In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before... | 500 | [
{
"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "NO"
},
{
"input": "1\nDb -3373 3591",
"output": "NO"
},
{
"input": "5\nQ2bz 960 2342... | 1,587,807,685 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 109 | 0 | for _ in range(int(input())):
l=input().split()
if int(l[1])>=2400:
if int(l[2])>int(l[1]):
print('YES')
exit()
print('NO') | Title: A Good Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part ... | ```python
for _ in range(int(input())):
l=input().split()
if int(l[1])>=2400:
if int(l[2])>int(l[1]):
print('YES')
exit()
print('NO')
``` | 3 | |
274 | A | k-Multiple Free Set | PROGRAMMING | 1,500 | [
"binary search",
"greedy",
"sortings"
] | null | null | A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<==<=*x*·*k*.
You're given a set of *n* distinct positive integers. Your task is to find th... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
All the numbers in the lines are separated by single spaces. | On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}. | [
"6 2\n2 3 6 5 4 10\n"
] | [
"3\n"
] | In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | 500 | [
{
"input": "6 2\n2 3 6 5 4 10",
"output": "3"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "6"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 1... | 1,525,103,858 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 404 | 15,155,200 | n,k = map(int,input().split())
arr = list(map(int,input().split()))
arr.sort()
ans = set()
for i in arr:
if i%k: ans.add(i)
elif i//k not in ans: ans.add(i)
print(len(ans)) | Title: k-Multiple Free Set
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, ... | ```python
n,k = map(int,input().split())
arr = list(map(int,input().split()))
arr.sort()
ans = set()
for i in arr:
if i%k: ans.add(i)
elif i//k not in ans: ans.add(i)
print(len(ans))
``` | 3 | |
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* ... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182... | 1,620,715,237 | 2,147,483,647 | PyPy 3 | OK | TESTS | 76 | 248 | 21,913,600 | from collections import defaultdict
n = int(input())
g = defaultdict(lambda: [])
a = [tuple(map(int, input().split())) for _ in range(n)]
for i in range(n):
for j in range(i + 1, n):
x1, y1, x2, y2 = *a[i], *a[j]
if x1 == x2 or y1 == y2:
g[(x1, y1)].append((x2, y2))
... | Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha... | ```python
from collections import defaultdict
n = int(input())
g = defaultdict(lambda: [])
a = [tuple(map(int, input().split())) for _ in range(n)]
for i in range(n):
for j in range(i + 1, n):
x1, y1, x2, y2 = *a[i], *a[j]
if x1 == x2 or y1 == y2:
g[(x1, y1)].append((x2, y2))... | 3 | |
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,668,917,457 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 6,041,600 | input()
a = [int(x) for x in input().split()]
dic = {}
for x in range(1,max(a)+1):
dic[x] = a.count(x)
m = max(dic)
dp = [0]*(m+1)
dp[1] = dic[1]
dp[2] = max(dp[1],2*dic[2])
for i in range(3,m+1):
dp[i] = max(dp[i-2] + i*dic[i], dp[i-1])
print(dp[-1]) | 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
input()
a = [int(x) for x in input().split()]
dic = {}
for x in range(1,max(a)+1):
dic[x] = a.count(x)
m = max(dic)
dp = [0]*(m+1)
dp[1] = dic[1]
dp[2] = max(dp[1],2*dic[2])
for i in range(3,m+1):
dp[i] = max(dp[i-2] + i*dic[i], dp[i-1])
print(dp[-1])
``` | 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,592,042,411 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 108 | 0 | s = input()
s = s.replace('h', '', s.count('h')-1).replace('e', '', s.count('e')-1).replace('l', '', s.count('l')-2).replace('o', '', s.count('o')-1)
if 'hello' in s:
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
s = input()
s = s.replace('h', '', s.count('h')-1).replace('e', '', s.count('e')-1).replace('l', '', s.count('l')-2).replace('o', '', s.count('o')-1)
if 'hello' in s:
print('YES')
else:
print('NO')
``` | 0 |
294 | A | Shaass and Oskols | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*... | The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100).
The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i... | On the *i*-th line of the output print the number of birds on the *i*-th wire. | [
"5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n",
"3\n2 4 1\n1\n2 2\n"
] | [
"0\n12\n5\n0\n16\n",
"3\n0\n3\n"
] | none | 500 | [
{
"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6",
"output": "0\n12\n5\n0\n16"
},
{
"input": "3\n2 4 1\n1\n2 2",
"output": "3\n0\n3"
},
{
"input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43",
"output": "0\n66\n57\n7\n0"
},
{
"input": "10\n48 53 10 28 91 56 8... | 1,662,205,455 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 26 | 92 | 0 | def separate(num, shoted):
down = num - shoted
up = shoted - 1
if shoted > num:
down = num
return down, up
wires = int(input())
Oskols = list(map(int, input().split()))
shots = int(input())
for i in range(shots):
w, pos = map(int, input().split())
D, U = separate(Oskols[w-1], pos)
if w == 1... | Title: Shaass and Oskols
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each... | ```python
def separate(num, shoted):
down = num - shoted
up = shoted - 1
if shoted > num:
down = num
return down, up
wires = int(input())
Oskols = list(map(int, input().split()))
shots = int(input())
for i in range(shots):
w, pos = map(int, input().split())
D, U = separate(Oskols[w-1], pos)
... | -1 | |
227 | A | Where do I Turn? | PROGRAMMING | 1,300 | [
"geometry"
] | null | null | Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point *C* and began to terrorize the residents of the surrounding villages.
A brave hero decided to put an end to the dragon. He moved from point *A* to fight with Gorynych. The hero rode from point *A* along a straight... | The first input line contains two space-separated integers *x**a*,<=*y**a* (|*x**a*|,<=|*y**a*|<=≤<=109) — the coordinates of point *A*. The second line contains the coordinates of point *B* in the same form, the third line contains the coordinates of point *C*.
It is guaranteed that all points are pairwise different.... | Print a single line. If a hero must turn left, print "LEFT" (without the quotes); If he must go straight ahead, print "TOWARDS" (without the quotes); if he should turn right, print "RIGHT" (without the quotes). | [
"0 0\n0 1\n1 1\n",
"-1 -1\n-3 -3\n-4 -4\n",
"-4 -6\n-3 -7\n-2 -6\n"
] | [
"RIGHT\n",
"TOWARDS\n",
"LEFT\n"
] | The picture to the first sample:
The red color shows points A, B and C. The blue arrow shows the hero's direction. The green color shows the hero's trajectory.
The picture to the second sample: | 500 | [
{
"input": "0 0\n0 1\n1 1",
"output": "RIGHT"
},
{
"input": "-1 -1\n-3 -3\n-4 -4",
"output": "TOWARDS"
},
{
"input": "-4 -6\n-3 -7\n-2 -6",
"output": "LEFT"
},
{
"input": "-44 57\n-118 -41\n-216 33",
"output": "RIGHT"
},
{
"input": "39 100\n90 85\n105 136",
"o... | 1,630,769,601 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 154 | 6,656,000 | xa, ya = map(int, input().split())
xb, yb = map(int, input().split())
xc, yc = map(int, input().split())
calculate = ((xb-xa)*(yc-yb)) - ((yb-ya)*(xc))
if calculate == 0:
print ("TOWARDS")
elif calculate > 0:
print ("LEFT")
else:
print ("RIGHT")
| Title: Where do I Turn?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point *C* and began to terrorize the residents of the surrounding villages.
A brave hero decided to put an end to the... | ```python
xa, ya = map(int, input().split())
xb, yb = map(int, input().split())
xc, yc = map(int, input().split())
calculate = ((xb-xa)*(yc-yb)) - ((yb-ya)*(xc))
if calculate == 0:
print ("TOWARDS")
elif calculate > 0:
print ("LEFT")
else:
print ("RIGHT")
``` | 0 | |
404 | C | Restore Graph | PROGRAMMING | 1,800 | [
"dfs and similar",
"graphs",
"sortings"
] | null | null | Valera had an undirected connected graph without self-loops and multiple edges consisting of *n* vertices. The graph had an interesting property: there were at most *k* edges adjacent to each of its vertices. For convenience, we will assume that the graph vertices were indexed by integers from 1 to *n*.
One day Valera... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=<<=*n*<=≤<=105). Number *n* shows the number of vertices in the original graph. Number *k* shows that at most *k* edges were adjacent to each vertex in the original graph.
The second line contains space-separated integers *d*[1],<=*d*[2],<... | If Valera made a mistake in his notes and the required graph doesn't exist, print in the first line number -1. Otherwise, in the first line print integer *m* (0<=≤<=*m*<=≤<=106) — the number of edges in the found graph.
In each of the next *m* lines print two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=... | [
"3 2\n0 1 1\n",
"4 2\n2 0 1 3\n",
"3 1\n0 0 0\n"
] | [
"3\n1 2\n1 3\n3 2\n",
"3\n1 3\n1 4\n2 3\n",
"-1\n"
] | none | 1,500 | [
{
"input": "3 2\n0 1 1",
"output": "2\n1 2\n1 3"
},
{
"input": "4 2\n2 0 1 3",
"output": "3\n1 3\n1 4\n2 3"
},
{
"input": "3 1\n0 0 0",
"output": "-1"
},
{
"input": "5 3\n0 2 1 2 1",
"output": "4\n1 3\n1 5\n2 5\n4 5"
},
{
"input": "7 3\n2 2 0 1 3 2 1",
"output... | 1,682,601,584 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 77 | 0 | def ss(n,k,l):
t=[0 for _ in range(n)]
for i in l:
t[i]+=1
if t[0]!=1:
print(-1)
return
t.append(0)
q=[0]
i=1
ans=[]
# print(t)
lst = 1
count = [0 for _ in range(n)]
while t[i]!=0:
# print(i)
q1=[]
... | Title: Restore Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had an undirected connected graph without self-loops and multiple edges consisting of *n* vertices. The graph had an interesting property: there were at most *k* edges adjacent to each of its vertices. For convenie... | ```python
def ss(n,k,l):
t=[0 for _ in range(n)]
for i in l:
t[i]+=1
if t[0]!=1:
print(-1)
return
t.append(0)
q=[0]
i=1
ans=[]
# print(t)
lst = 1
count = [0 for _ in range(n)]
while t[i]!=0:
# print(i)
q1=[]... | 0 | |
252 | A | Little Xor | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that.
... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230. | Print a single integer — the required maximal *xor* of a segment of consecutive elements. | [
"5\n1 2 1 1 2\n",
"3\n1 2 7\n",
"4\n4 2 4 8\n"
] | [
"3\n",
"7\n",
"14\n"
] | In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one.
The second sample contains only one optimal segment, which contains exactly one array element (element with index three). | 500 | [
{
"input": "5\n1 2 1 1 2",
"output": "3"
},
{
"input": "3\n1 2 7",
"output": "7"
},
{
"input": "4\n4 2 4 8",
"output": "14"
},
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
"output": "15"
},
{
"inpu... | 1,593,131,123 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 248 | 6,758,400 | n=int(input())
l=list(map(int,input().split()))
l.insert(0 , 0)
for i in range(n):l[i+1]^=l[i]
print(max(i^j for i in l for j in l)) | Title: Little Xor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, ... | ```python
n=int(input())
l=list(map(int,input().split()))
l.insert(0 , 0)
for i in range(n):l[i+1]^=l[i]
print(max(i^j for i in l for j in l))
``` | 3 | |
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmos... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where ... | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You... | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7... | 1,629,637,841 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 77 | 20,172,800 | n,m = [int(i) for i in input().split()]
lis = []
for i in range(n):
lis.append([int(i) for i in input().split()])
flag = True
if lis[0][0]>0:
flag = False
for i in range(n-1):
if lis[i+1][0]-lis[i][1]>0:
flag = False
if lis[-1][1]-m <0:
flag = False
if flag:
print('YES')
else:
... | Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain ... | ```python
n,m = [int(i) for i in input().split()]
lis = []
for i in range(n):
lis.append([int(i) for i in input().split()])
flag = True
if lis[0][0]>0:
flag = False
for i in range(n-1):
if lis[i+1][0]-lis[i][1]>0:
flag = False
if lis[-1][1]-m <0:
flag = False
if flag:
print('YES... | 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,622,563,838 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 186 | 0 | def findgcd(a, b):
if(b == 0):
return a;
else:
return findgcd(b, a % b)
y,w=map(int,input().split())
if y>w:
x=y
else:
x=w
if x==6:
print('1/1')
else:
x=x-1
x=6-x
lcm=(x*6)//findgcd(x,6)
print(lcm//6,end="")
print("/",e... | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
def findgcd(a, b):
if(b == 0):
return a;
else:
return findgcd(b, a % b)
y,w=map(int,input().split())
if y>w:
x=y
else:
x=w
if x==6:
print('1/1')
else:
x=x-1
x=6-x
lcm=(x*6)//findgcd(x,6)
print(lcm//6,end="")
p... | 0 |
967 | B | Watering System | PROGRAMMING | 1,000 | [
"math",
"sortings"
] | null | null | Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After... | The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$)... | Print a single integer — the number of holes Arkady should block. | [
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] | [
"1\n",
"0\n",
"4\n"
] | In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not les... | 1,000 | [
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 ... | 1,571,410,691 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | n, A, B = map(int, input().split())
x = list(map(int, input().split()))
init = x[0]
del x[0]
x.sort(reverse=True)
ans = 0
S = sum(x) + init
for i in range(n - 1):
if x[i] * A / S < B:
ans += 1
S -= x[i]
if i == n - 2:
print(ans)
else:
print(ans)
exit()
| Title: Watering System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the fi... | ```python
n, A, B = map(int, input().split())
x = list(map(int, input().split()))
init = x[0]
del x[0]
x.sort(reverse=True)
ans = 0
S = sum(x) + init
for i in range(n - 1):
if x[i] * A / S < B:
ans += 1
S -= x[i]
if i == n - 2:
print(ans)
else:
print(ans)
exit... | 0 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,672,221,857 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | [d1, d2, d3]= map(int, input().split(" "))
[d1, d2] = [max(d1, d2), min(d1, d2)]
result = 0
result += d2
if d1 + d2 > d3:
result += d3
if d1 + d3 > d2:
result += d2
else:
result += d1 + d3
else:
result += d1 + d2 + d1
print(result) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
[d1, d2, d3]= map(int, input().split(" "))
[d1, d2] = [max(d1, d2), min(d1, d2)]
result = 0
result += d2
if d1 + d2 > d3:
result += d3
if d1 + d3 > d2:
result += d2
else:
result += d1 + d3
else:
result += d1 + d2 + d1
print(result)
``` | 0 | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,520,872,152 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 216 | 6,144,000 | from collections import defaultdict
N = int(input())
size = input()
size = size.split()
ukuran = defaultdict(list)
for i in size:
ukuran[i].append(1)
max = 0
for key in ukuran:
if len(ukuran[key]) > max:
max = len(ukuran[key])
print(max,len(ukuran)) | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
from collections import defaultdict
N = int(input())
size = input()
size = size.split()
ukuran = defaultdict(list)
for i in size:
ukuran[i].append(1)
max = 0
for key in ukuran:
if len(ukuran[key]) > max:
max = len(ukuran[key])
print(max,len(ukuran))
``` | 3.934556 |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,651,415,878 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | n=input()
s = input().split()
v = [int(x) for x in s]
maxv=0
for x in v:
if (x>maxv):
maxv=x
res=0
for x in v:
res=res+maxv-x
print (res) | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
n=input()
s = input().split()
v = [int(x) for x in s]
maxv=0
for x in v:
if (x>maxv):
maxv=x
res=0
for x in v:
res=res+maxv-x
print (res)
``` | 3 | |
887 | A | Div. 64 | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisi... | In the only line given a non-empty binary string *s* with length up to 100. | Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise. | [
"100010001\n",
"100\n"
] | [
"yes",
"no"
] | In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system) | 500 | [
{
"input": "100010001",
"output": "yes"
},
{
"input": "100",
"output": "no"
},
{
"input": "0000001000000",
"output": "yes"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "no"
},
{
"in... | 1,625,212,746 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | s=input()
if len(s)>7:
if "0" and "1" in s:
print("yes")
else:
print("no") | Title: Div. 64
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some dig... | ```python
s=input()
if len(s)>7:
if "0" and "1" in s:
print("yes")
else:
print("no")
``` | 0 | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,694,572,182 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | import sympy
n,m = map(int,input().split())
nlist = list(sympy.primerange(n,m+1))
if len(nlist) < 2 :
print("NO")
exit()
if n == nlist[0] and m == nlist[1] :
print("YES")
else:
print("NO") | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
import sympy
n,m = map(int,input().split())
nlist = list(sympy.primerange(n,m+1))
if len(nlist) < 2 :
print("NO")
exit()
if n == nlist[0] and m == nlist[1] :
print("YES")
else:
print("NO")
``` | -1 |
63 | A | Sinking Ship | PROGRAMMING | 900 | [
"implementation",
"sortings",
"strings"
] | A. Sinking Ship | 2 | 256 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a stri... | The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spa... | Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. | [
"6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n"
] | [
"Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n"
] | none | 500 | [
{
"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"
},
{
"input": "1\nA captain",
"output": "A"
},
{
"input": "1\nAbcdefjhij captain",
"output": "Abcdefjhij"
},
{
"input": "5\nA captain... | 1,624,294,320 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | r=[]
w=[]
m=[]
cap=[]
for i in range(int(input())):
l,k=input().split()
if k=="rat":
r.append(l)
elif k=="woman" or k=="child":
w.append(l)
elif k=="man":
m.append(l)
else:
cap.append(l)
print(r+w+m+cap)
| Title: Sinking Ship
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to ... | ```python
r=[]
w=[]
m=[]
cap=[]
for i in range(int(input())):
l,k=input().split()
if k=="rat":
r.append(l)
elif k=="woman" or k=="child":
w.append(l)
elif k=="man":
m.append(l)
else:
cap.append(l)
print(r+w+m+cap)
... | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.