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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
888 | D | Almost Identity Permutations | PROGRAMMING | 1,600 | [
"combinatorics",
"dp",
"math"
] | null | null | A permutation *p* of size *n* is an array such that every integer from 1 to *n* occurs exactly once in this array.
Let's call a permutation an almost identity permutation iff there exist at least *n*<=-<=*k* indices *i* (1<=≤<=*i*<=≤<=*n*) such that *p**i*<==<=*i*.
Your task is to count the number of almost identity ... | The first line contains two integers *n* and *k* (4<=≤<=*n*<=≤<=1000, 1<=≤<=*k*<=≤<=4). | Print the number of almost identity permutations for given *n* and *k*. | [
"4 1\n",
"4 2\n",
"5 3\n",
"5 4\n"
] | [
"1\n",
"7\n",
"31\n",
"76\n"
] | none | 0 | [
{
"input": "4 1",
"output": "1"
},
{
"input": "4 2",
"output": "7"
},
{
"input": "5 3",
"output": "31"
},
{
"input": "5 4",
"output": "76"
},
{
"input": "200 1",
"output": "1"
},
{
"input": "200 2",
"output": "19901"
},
{
"input": "200 3",
... | 1,618,232,440 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | from sys import stdin,stdout
import math
nmbr = lambda: int(input())
lst = lambda:list(map(int,input().split()))
def ncr(n,r):
lim=min(r,n-r)
num,den=5,1
nn=dd=1
for i in range(lim):
nn*=num
dd*=den
num-=1
den+=1
return nn//dd
for _ in range(1):#nmbr():
... | Title: Almost Identity Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation *p* of size *n* is an array such that every integer from 1 to *n* occurs exactly once in this array.
Let's call a permutation an almost identity permutation iff there exist at least *n*<=-<=*... | ```python
from sys import stdin,stdout
import math
nmbr = lambda: int(input())
lst = lambda:list(map(int,input().split()))
def ncr(n,r):
lim=min(r,n-r)
num,den=5,1
nn=dd=1
for i in range(lim):
nn*=num
dd*=den
num-=1
den+=1
return nn//dd
for _ in range(1)... | 0 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,677,190,056 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | num=input()
list=[int(i) for i in num]
x=0
for i in range(len(list[:-1])):
if list[i]==list[i+1]:
x+=1
if x>=7:
q=True
else:
x=0
print("YES" if q else "NO") | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
num=input()
list=[int(i) for i in num]
x=0
for i in range(len(list[:-1])):
if list[i]==list[i+1]:
x+=1
if x>=7:
q=True
else:
x=0
print("YES" if q else "NO")
``` | -1 |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,623,671,598 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 124 | 0 | n = int(input())
sp = list(map(int, input().split()))
if (sp[0] % 2 + sp[1] % 2 + sp[2] % 2) <= 1:
ind = 0
else:
ind = -1
norm = sorted(sp, key=lambda x: x % 2 == 0)
print(sp.index(norm[ind]) + 1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
sp = list(map(int, input().split()))
if (sp[0] % 2 + sp[1] % 2 + sp[2] % 2) <= 1:
ind = 0
else:
ind = -1
norm = sorted(sp, key=lambda x: x % 2 == 0)
print(sp.index(norm[ind]) + 1)
``` | 3.969 |
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,692,294,623 | 2,147,483,647 | PyPy 3 | OK | TESTS | 70 | 312 | 3,481,600 | n , m = [int(x) for x in input().split()]
students = [i for i in range(n)]
adj = [[] for i in range(n)]
for i in range(m):
s1 , s2 = [int(x) - 1 for x in input().split()]
adj[s1].append(s2)
adj[s2].append(s1)
def dfs(s):
global visited
global out
visited[s] = True
if len(adj... | 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
n , m = [int(x) for x in input().split()]
students = [i for i in range(n)]
adj = [[] for i in range(n)]
for i in range(m):
s1 , s2 = [int(x) - 1 for x in input().split()]
adj[s1].append(s2)
adj[s2].append(s1)
def dfs(s):
global visited
global out
visited[s] = True
... | 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,951,890 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 186 | 7,065,600 | input()
nums=[int(x) for x in input().split( )]
count=[0]+[0]*max(nums)
dp=[0]+[0]*max(nums)
for a in nums:
count[a]+=1
dp[1]=count[1]*1
for b in range(1,max(nums)+1):
dp[b]=max(dp[b-1],dp[b-2]+count[b]*b)
print(max(dp)) | 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()
nums=[int(x) for x in input().split( )]
count=[0]+[0]*max(nums)
dp=[0]+[0]*max(nums)
for a in nums:
count[a]+=1
dp[1]=count[1]*1
for b in range(1,max(nums)+1):
dp[b]=max(dp[b-1],dp[b-2]+count[b]*b)
print(max(dp))
``` | 3 | |
895 | C | Square Subsets | PROGRAMMING | 2,000 | [
"bitmasks",
"combinatorics",
"dp",
"math"
] | null | null | Petya was late for the lesson too. The teacher gave him an additional task. For some array *a* Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their product is equal to a square of some integer.
Two ways are considered different if sets of indexes of ele... | First line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array.
Second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=70) — the elements of the array. | Print one integer — the number of different ways to choose some elements so that their product is a square of a certain integer modulo 109<=+<=7. | [
"4\n1 1 1 1\n",
"4\n2 2 2 2\n",
"5\n1 2 4 5 8\n"
] | [
"15\n",
"7\n",
"7\n"
] | In first sample product of elements chosen by any way is 1 and 1 = 1<sup class="upper-index">2</sup>. So the answer is 2<sup class="upper-index">4</sup> - 1 = 15.
In second sample there are six different ways to choose elements so that their product is 4, and only one way so that their product is 16. So the answer is ... | 1,750 | [
{
"input": "4\n1 1 1 1",
"output": "15"
},
{
"input": "4\n2 2 2 2",
"output": "7"
},
{
"input": "5\n1 2 4 5 8",
"output": "7"
},
{
"input": "1\n64",
"output": "1"
},
{
"input": "5\n2 2 2 2 2",
"output": "15"
},
{
"input": "6\n1 2 3 4 5 6",
"output"... | 1,568,655,722 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 0 | 1,294 | 268,390,400 | n = int(input())
arr = [ int(i) for i in input().split() ]
MOD = 10**9+7
num_ways = [ [1,0] for i in range(71) ]
primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67]
def get_mask(i):
new = 0
for ind,j in enumerate(primes):
cnt = 0
if (i % j) == 0:
while( (i % j) == 0 ):
... | Title: Square Subsets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya was late for the lesson too. The teacher gave him an additional task. For some array *a* Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their produc... | ```python
n = int(input())
arr = [ int(i) for i in input().split() ]
MOD = 10**9+7
num_ways = [ [1,0] for i in range(71) ]
primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67]
def get_mask(i):
new = 0
for ind,j in enumerate(primes):
cnt = 0
if (i % j) == 0:
while( (i % j) ... | 0 | |
821 | C | Okabe and Boxes | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"trees"
] | null | null | Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack.
Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the sta... | The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of boxes.
Each of the next 2*n* lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer *x* (1<=≤<=*x*<=≤<=*n*) follows, indicating that Daru should add the box with number *x* to the top of... | Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. | [
"3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n",
"7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n"
] | [
"1\n",
"2\n"
] | In the first sample, Daru should reorder the boxes after adding box 3 to the stack.
In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack. | 1,500 | [
{
"input": "3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove",
"output": "1"
},
{
"input": "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove",
"output": "2"
},
{
"input": "4\nadd 1\nadd 3\nremove\nadd 4\nadd 2\nremove\nremove\nremov... | 1,565,595,744 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 124 | 0 | n = int(input())
h = []
g = 0
sa = 0
for i in range(n * 2):
s = input()
if s[:3] == "add":
sa += 1
else:
if sa >= 2:
g += 1
sa = 0
print(g)
| Title: Okabe and Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack.
Okabe, being a control freak, gives Daru 2*n* commands: *n* of which a... | ```python
n = int(input())
h = []
g = 0
sa = 0
for i in range(n * 2):
s = input()
if s[:3] == "add":
sa += 1
else:
if sa >= 2:
g += 1
sa = 0
print(g)
``` | 0 | |
60 | A | Where Are My Flakes? | PROGRAMMING | 1,300 | [
"implementation",
"two pointers"
] | A. Where Are My Flakes? | 2 | 256 | One morning the Cereal Guy found out that all his cereal flakes were gone. He found a note instead of them. It turned out that his smart roommate hid the flakes in one of *n* boxes. The boxes stand in one row, they are numbered from 1 to *n* from the left to the right. The roommate left hints like "Hidden to the left o... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000,<=0<=≤<=*m*<=≤<=1000) which represent the number of boxes and the number of hints correspondingly. Next *m* lines contain hints like "To the left of *i*" and "To the right of *i*", where *i* is integer (1<=≤<=*i*<=≤<=*n*). The hints may coincide. | The answer should contain exactly one integer — the number of boxes that should necessarily be checked or "-1" if the hints are contradictory. | [
"2 1\nTo the left of 2\n",
"3 2\nTo the right of 1\nTo the right of 2\n",
"3 1\nTo the left of 3\n",
"3 2\nTo the left of 2\nTo the right of 1\n"
] | [
"1\n",
"1\n",
"2\n",
"-1\n"
] | none | 500 | [
{
"input": "2 1\nTo the left of 2",
"output": "1"
},
{
"input": "3 2\nTo the right of 1\nTo the right of 2",
"output": "1"
},
{
"input": "3 1\nTo the left of 3",
"output": "2"
},
{
"input": "3 2\nTo the left of 2\nTo the right of 1",
"output": "-1"
},
{
"input": "... | 1,672,900,006 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 154 | 1,740,800 | n,m=list(map(int,input().split()))
i,j=1,n
right=[]
left=[]
for k in range(m):
x=input()
#print(x)
if x.find("To the left of ")!=-1:
#print(x.find("2"))
left.append(int(x[15::]))
else:
#print(x[16::])
right.append(int(x[16::]))
#print(left,right)
if (right!=... | Title: Where Are My Flakes?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One morning the Cereal Guy found out that all his cereal flakes were gone. He found a note instead of them. It turned out that his smart roommate hid the flakes in one of *n* boxes. The boxes stand in one row, they are... | ```python
n,m=list(map(int,input().split()))
i,j=1,n
right=[]
left=[]
for k in range(m):
x=input()
#print(x)
if x.find("To the left of ")!=-1:
#print(x.find("2"))
left.append(int(x[15::]))
else:
#print(x[16::])
right.append(int(x[16::]))
#print(left,right)
i... | 3.958258 |
570 | A | Elections | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in ... | The first line of the input contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of candidates and of cities, respectively.
Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*j*<=≤<=*n*, 1<=≤<=*i*<=≤<=*m*, 0<=≤<=*a**ij*<=≤<=109) denotes ... | Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. | [
"3 3\n1 2 3\n2 3 1\n1 2 1\n",
"3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n"
] | [
"2",
"1"
] | Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm... | 500 | [
{
"input": "3 3\n1 2 3\n2 3 1\n1 2 1",
"output": "2"
},
{
"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7",
"output": "1"
},
{
"input": "1 3\n5\n3\n2",
"output": "1"
},
{
"input": "3 1\n1 2 3",
"output": "3"
},
{
"input": "3 1\n100 100 100",
"output": "1"
},
{... | 1,629,741,531 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 78 | 6,963,200 | import sys
def input(): return sys.stdin.readline().rstrip("\r\n")
def maps():return [int(i) for i in input().split()]
def func():
n , m = maps()
if n > m +1 or m > 2*(n +1) :
print(-1)
else:
if n == m : #self - explanatory
print('10'*n)
elif n... | Title: Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusu... | ```python
import sys
def input(): return sys.stdin.readline().rstrip("\r\n")
def maps():return [int(i) for i in input().split()]
def func():
n , m = maps()
if n > m +1 or m > 2*(n +1) :
print(-1)
else:
if n == m : #self - explanatory
print('10'*n)
... | 0 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,639,731,642 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | st1 = input()
st2 = input()
print(st1 == st2[::-1]) | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
st1 = input()
st2 = input()
print(st1 == st2[::-1])
``` | 0 |
950 | A | Left-handers, Right-handers and Ambidexters | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and ... | The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. | Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. | [
"1 4 2\n",
"5 5 5\n",
"0 2 0\n"
] | [
"6\n",
"14\n",
"0\n"
] | In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five l... | 500 | [
{
"input": "1 4 2",
"output": "6"
},
{
"input": "5 5 5",
"output": "14"
},
{
"input": "0 2 0",
"output": "0"
},
{
"input": "30 70 34",
"output": "128"
},
{
"input": "89 32 24",
"output": "112"
},
{
"input": "89 44 77",
"output": "210"
},
{
... | 1,573,501,401 | 2,147,483,647 | PyPy 3 | OK | TESTS | 79 | 140 | 0 | # cf 950 A 900
l, r, a = map(int, input().split())
if l < r:
d = r - l
d = min(a, d)
l += d
a -= d
else:
d = l - r
d = min(a, d)
r += d
a -= d
print(2 * (min(l, r) + a // 2))
| Title: Left-handers, Right-handers and Ambidexters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.... | ```python
# cf 950 A 900
l, r, a = map(int, input().split())
if l < r:
d = r - l
d = min(a, d)
l += d
a -= d
else:
d = l - r
d = min(a, d)
r += d
a -= d
print(2 * (min(l, r) + a // 2))
``` | 3 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,695,292,277 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | y,w = map(int,input().split())
if y>w:
y = 6-y+1
elif w>y:
w = 6-w+1
else:
y = 6
print(str(y)+"/"+str(6)) | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
y,w = map(int,input().split())
if y>w:
y = 6-y+1
elif w>y:
w = 6-w+1
else:
y = 6
print(str(y)+"/"+str(6))
``` | 0 |
407 | A | Triangle | PROGRAMMING | 1,600 | [
"brute force",
"geometry",
"implementation",
"math"
] | null | null | There is a right triangle with legs of length *a* and *b*. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the... | The first line contains two integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=1000), separated by a single space. | In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute valu... | [
"1 1\n",
"5 5\n",
"5 10\n"
] | [
"NO\n",
"YES\n2 1\n5 5\n-2 4\n",
"YES\n-10 4\n-2 -2\n1 2\n"
] | none | 500 | [
{
"input": "1 1",
"output": "NO"
},
{
"input": "5 5",
"output": "YES\n2 1\n5 5\n-2 4"
},
{
"input": "5 10",
"output": "YES\n-10 4\n-2 -2\n1 2"
},
{
"input": "2 2",
"output": "NO"
},
{
"input": "5 6",
"output": "NO"
},
{
"input": "5 11",
"output": "... | 1,634,231,639 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | import math
a, b = map(int, input().split())
for x in range(1, a):
y = math.sqrt(a * a - x * x)
if(int(y) == y):
deg = math.atan2(y, x) + math.pi / 2.0
x2 = b * math.cos(deg)
y2 = b * math.sin(deg)
if(x2 == int(x2) and y2 == int(y2) and y2 != y):
print("yEs... | Title: Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a right triangle with legs of length *a* and *b*. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the v... | ```python
import math
a, b = map(int, input().split())
for x in range(1, a):
y = math.sqrt(a * a - x * x)
if(int(y) == y):
deg = math.atan2(y, x) + math.pi / 2.0
x2 = b * math.cos(deg)
y2 = b * math.sin(deg)
if(x2 == int(x2) and y2 == int(y2) and y2 != y):
... | 0 | |
289 | B | Polo the Penguin and Matrix | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation",
"sortings",
"ternary search"
] | null | null | Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add ... | The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). | In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). | [
"2 2 2\n2 4\n6 8\n",
"1 2 7\n6 7\n"
] | [
"4\n",
"-1\n"
] | none | 1,000 | [
{
"input": "2 2 2\n2 4\n6 8",
"output": "4"
},
{
"input": "1 2 7\n6 7",
"output": "-1"
},
{
"input": "3 2 1\n5 7\n1 2\n5 100",
"output": "104"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 2",
"output": "12"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 3",
"outpu... | 1,580,824,957 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 310 | 1,740,800 | n, m, d = list(map(int, input().rstrip().split()))
mat=[]
for _ in range(n):
mat += list(map(int, input().rstrip().split()))
mat.sort()
if n * m == 1:
print(0)
else:
flag = 1
for i in range(n * m - 1):
if (mat[i + 1] - mat[i]) % d != 0:
flag = 0
break
if flag == 0:
... | Title: Polo the Penguin and Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represe... | ```python
n, m, d = list(map(int, input().rstrip().split()))
mat=[]
for _ in range(n):
mat += list(map(int, input().rstrip().split()))
mat.sort()
if n * m == 1:
print(0)
else:
flag = 1
for i in range(n * m - 1):
if (mat[i + 1] - mat[i]) % d != 0:
flag = 0
break
if fla... | 3 | |
920 | C | Swap Adjacent Elements | PROGRAMMING | 1,400 | [
"dfs and similar",
"greedy",
"math",
"sortings",
"two pointers"
] | null | null | You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<=1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. T... | The first line contains one integer *n* (2<=≤<=*n*<=≤<=200000) — the number of elements in the array.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=200000) — the elements of the array. Each integer from 1 to *n* appears exactly once.
The third line contains a string of *n*<=-<=1 char... | If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print YES. Otherwise, print NO. | [
"6\n1 2 5 3 4 6\n01110\n",
"6\n1 2 5 3 4 6\n01010\n"
] | [
"YES\n",
"NO\n"
] | In the first example you may swap *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, and then swap *a*<sub class="lower-index">4</sub> and *a*<sub class="lower-index">5</sub>. | 0 | [
{
"input": "6\n1 2 5 3 4 6\n01110",
"output": "YES"
},
{
"input": "6\n1 2 5 3 4 6\n01010",
"output": "NO"
},
{
"input": "6\n1 6 3 4 5 2\n01101",
"output": "NO"
},
{
"input": "6\n2 3 1 4 5 6\n01111",
"output": "NO"
},
{
"input": "4\n2 3 1 4\n011",
"output": "NO... | 1,617,948,180 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 93 | 13,107,200 | n = int(input())
l = list(map(int,input().split()))
s = input()
ll = sorted(l)
ans = []
f = 0
for i in range(n):
if l[i]!=ll[i]:
if f==0:
f = 1
ans.append(i)
elif f==1:
ans.pop(-1)
ok = 1
for i in ans:
if s[i]=='0':
print("NO")
... | Title: Swap Adjacent Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<... | ```python
n = int(input())
l = list(map(int,input().split()))
s = input()
ll = sorted(l)
ans = []
f = 0
for i in range(n):
if l[i]!=ll[i]:
if f==0:
f = 1
ans.append(i)
elif f==1:
ans.pop(-1)
ok = 1
for i in ans:
if s[i]=='0':
print("NO"... | -1 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,605,013,404 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 109 | 0 | a1=input()
a=list(a1)
a2=input()
b=list(a2)
s=[]
for i in range(len(a)):
if a[i]==b[i]:
list.append(s,'0')
else:
list.append(s,'1')
print(''.join(s)) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
a1=input()
a=list(a1)
a2=input()
b=list(a2)
s=[]
for i in range(len(a)):
if a[i]==b[i]:
list.append(s,'0')
else:
list.append(s,'1')
print(''.join(s))
``` | 3.97275 |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,622,094,493 | 2,147,483,647 | PyPy 3 | OK | TESTS | 58 | 109 | 0 | n = input()
h = n.find('h')
e = n.find('e',h+1)
i = n.find('i',e+1)
d = n.find('d',i+1)
i2 = n.find('i',d+1)
if h < e < i < d < i2:
print('YES')
else :
print('NO')
| Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
n = input()
h = n.find('h')
e = n.find('e',h+1)
i = n.find('i',e+1)
d = n.find('d',i+1)
i2 = n.find('i',d+1)
if h < e < i < d < i2:
print('YES')
else :
print('NO')
``` | 3 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,667,663,372 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | def is_Dangerous(s):
newS = s
i = 0
while len(newS) > 0:
if (1 - newS[0]) in newS:
if (newS[0: newS.index( 1-newS[0] ) ].count(newS[0])) >= 7: return "YES"
newS = s[i + 1:]
i += 1
return "NO"
if __name__ == '__main__':
s = "001001"
l = list("".jo... | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
def is_Dangerous(s):
newS = s
i = 0
while len(newS) > 0:
if (1 - newS[0]) in newS:
if (newS[0: newS.index( 1-newS[0] ) ].count(newS[0])) >= 7: return "YES"
newS = s[i + 1:]
i += 1
return "NO"
if __name__ == '__main__':
s = "001001"
l = ... | 0 |
633 | A | Ebony and Ivory | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of ... | The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. | Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. | [
"4 6 15\n",
"3 2 7\n",
"6 11 6\n"
] | [
"No\n",
"Yes\n",
"Yes\n"
] | In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. | 250 | [
{
"input": "4 6 15",
"output": "No"
},
{
"input": "3 2 7",
"output": "Yes"
},
{
"input": "6 11 6",
"output": "Yes"
},
{
"input": "3 12 15",
"output": "Yes"
},
{
"input": "5 5 10",
"output": "Yes"
},
{
"input": "6 6 7",
"output": "No"
},
{
"... | 1,456,507,885 | 985 | Python 3 | CHALLENGED | CHALLENGES | 11 | 62 | 0 | A, B, C = map(int, input().split())
op = False
for a in range(1, C//A+1):
if (C-A*a)%B==0:
op = True
if op == True:
print("Yes")
else:
print("No")
| Title: Ebony and Ivory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
F... | ```python
A, B, C = map(int, input().split())
op = False
for a in range(1, C//A+1):
if (C-A*a)%B==0:
op = True
if op == True:
print("Yes")
else:
print("No")
``` | -1 | |
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the en... | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18... | 1,686,527,216 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 0 | import math
n,d=map(int,input().split())
c=list(map(int,input().split()))
maxi=0
for i in range(len(c)):
if math.ceil(c[i]/d)>=maxi:
maxi=math.ceil(c[i]/d)
id=i
print(id+1)
| Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line ... | ```python
import math
n,d=map(int,input().split())
c=list(map(int,input().split()))
maxi=0
for i in range(len(c)):
if math.ceil(c[i]/d)>=maxi:
maxi=math.ceil(c[i]/d)
id=i
print(id+1)
``` | 3 | |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479"... | 1,641,659,122 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 8,601,600 | a1, b, n = [int(x) for x in input().split()]
a = a1
for i in range(n):
for j in range(10):
if(10*a+j)%b==0:
a = 10*a + j
break
if a==a1:
print(-1)
else:
print(a)
| Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
a1, b, n = [int(x) for x in input().split()]
a = a1
for i in range(n):
for j in range(10):
if(10*a+j)%b==0:
a = 10*a + j
break
if a==a1:
print(-1)
else:
print(a)
``` | 0 | |
23 | B | Party | PROGRAMMING | 1,600 | [
"constructive algorithms",
"graphs",
"math"
] | B. Party | 2 | 256 | *n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among those who stayed by the moment of their leaving, did the same.
What is the maximum amo... | The first input line contains one number *t* — amount of tests (1<=≤<=*t*<=≤<=105). Each of the following *t* lines contains one integer number *n* (1<=≤<=*n*<=≤<=105). | For each test output in a separate line one number — the maximum amount of people that could stay in the end. | [
"1\n3\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "1\n3",
"output": "1"
}
] | 1,468,904,179 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(raw_input())
for i in range(n):
k=int(raw_input())
print k-2
| Title: Party
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among ... | ```python
n=int(raw_input())
for i in range(n):
k=int(raw_input())
print k-2
``` | -1 |
667 | A | Pouring Rain | PROGRAMMING | 1,100 | [
"geometry",
"math"
] | null | null | A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything ... | The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where:
- *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth ... | If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is... | [
"1 2 3 100\n",
"1 1 1 1\n"
] | [
"NO\n",
"YES\n3.659792366325\n"
] | In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we ca... | 500 | [
{
"input": "1 2 3 100",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "YES\n3.659792366325"
},
{
"input": "48 7946 7992 72",
"output": "NO"
},
{
"input": "72 6791 8546 46",
"output": "NO"
},
{
"input": "100 5635 9099 23",
"output": "NO"
},
{
"input... | 1,462,255,354 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 4,608,000 | import math
a = input()
a= a.split()
d = int(a[0])
h = int(a[1])
v = int(a[2])
e = int(a[3])
t = (math.pi*d*d)/(4*d-math.pi*d*d*e)
if(t > 10000):
print('NO')
elif(t<0):
print('NO')
else:
print('YES')
print(t) | Title: Pouring Rain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, cont... | ```python
import math
a = input()
a= a.split()
d = int(a[0])
h = int(a[1])
v = int(a[2])
e = int(a[3])
t = (math.pi*d*d)/(4*d-math.pi*d*d*e)
if(t > 10000):
print('NO')
elif(t<0):
print('NO')
else:
print('YES')
print(t)
``` | 0 | |
719 | B | Anatoly and Cockroaches | PROGRAMMING | 1,400 | [
"greedy"
] | null | null | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectio... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cockroaches.
The second line contains a string of length *n*, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively. | Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate. | [
"5\nrbbrr\n",
"5\nbbbbb\n",
"3\nrbr\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer ... | 1,000 | [
{
"input": "5\nrbbrr",
"output": "1"
},
{
"input": "5\nbbbbb",
"output": "2"
},
{
"input": "3\nrbr",
"output": "0"
},
{
"input": "13\nrbbbrbrrbrrbb",
"output": "3"
},
{
"input": "18\nrrrrrrrrrrrrrrrrrb",
"output": "8"
},
{
"input": "100\nbrbbbrrrbbrbrb... | 1,479,592,862 | 1,262 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MAX 110
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<... | Title: Anatoly and Cockroaches
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches... | ```python
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MAX 110
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typed... | -1 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,650,133,591 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 154 | 0 | word = input()
new_word = list(word)
low = 0
up = 0
for i in new_word:
if i >= 'A' or i <= 'Z':
up += 1
else:
low += 1
if low > up:
word = word.upper()
print(word)
else:
word = word.lower()
print(word) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
word = input()
new_word = list(word)
low = 0
up = 0
for i in new_word:
if i >= 'A' or i <= 'Z':
up += 1
else:
low += 1
if low > up:
word = word.upper()
print(word)
else:
word = word.lower()
print(word)
``` | 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,585,126,644 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 204,800 | import sys
a = str(input())
mass = []
for i in range (0, len(a)):
if a[i] == 'h':
mass.append('h')
break
else:
print ('NO')
sys.exit()
if a[i] == 'e':
mass.append('e')
break
else:
print ('NO')
sys.exit()
if a[i] == 'l':
mass.app... | 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
import sys
a = str(input())
mass = []
for i in range (0, len(a)):
if a[i] == 'h':
mass.append('h')
break
else:
print ('NO')
sys.exit()
if a[i] == 'e':
mass.append('e')
break
else:
print ('NO')
sys.exit()
if a[i] == 'l':
... | 0 |
794 | A | Bank Robbery | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe f... | The first line of input contains three space-separated integers, *a*, *b* and *c* (1<=≤<=*b*<=<<=*a*<=<<=*c*<=≤<=109), denoting the positions of Oleg, the first security guard and the second security guard, respectively.
The next line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the numbe... | Output a single integer: the maximum number of banknotes Oleg can take. | [
"5 3 7\n8\n4 7 5 5 3 6 2 8\n",
"6 5 7\n5\n1 5 7 92 3\n"
] | [
"4\n",
"0\n"
] | In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first se... | 500 | [
{
"input": "5 3 7\n8\n4 7 5 5 3 6 2 8",
"output": "4"
},
{
"input": "6 5 7\n5\n1 5 7 92 3",
"output": "0"
},
{
"input": "3 2 4\n1\n3",
"output": "1"
},
{
"input": "5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6",
"output": "8"
},
{
"input": "7 3 10\n5\n3 3 3 3 3",
"output... | 1,682,520,495 | 195 | PyPy 3 | OK | TESTS | 46 | 186 | 9,420,800 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
a, b, c = map(int, input().split())
n = int(input())
x = list(map(int, input().split()))
ans = 0
for i in x:
if b < i < c:
ans += 1
print(ans) | Title: Bank Robbery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and... | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
a, b, c = map(int, input().split())
n = int(input())
x = list(map(int, input().split()))
ans = 0
for i in x:
if b < i < c:
ans += 1
print(ans)
``` | 3 | |
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* woode... | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal... | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ... | 1,595,306,323 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 248 | 7,168,000 | import sys
def input(): return sys.stdin.readline().strip()
def iinput(): return int(input())
def rinput(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
n=iinput()
col1 = []
col2 = []
for i in range (n):
tem... | Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long... | ```python
import sys
def input(): return sys.stdin.readline().strip()
def iinput(): return int(input())
def rinput(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
n=iinput()
col1 = []
col2 = []
for i in range (n)... | 3 | |
560 | A | Currency System in Geraldion | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea... | The first line contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of values of the banknotes that used in Geraldion.
The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the values of the banknotes. | Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1. | [
"5\n1 2 3 4 5\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 4 5",
"output": "-1"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837",
"output": "-1"
},
{
"input": "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264",
"o... | 1,629,489,116 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 62 | 6,963,200 | n = int(input())
a = input().split()
ans = -1
if not '1' in a:
ans = 1
print(ans)
| Title: Currency System in Geraldion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cann... | ```python
n = int(input())
a = input().split()
ans = -1
if not '1' in a:
ans = 1
print(ans)
``` | 3 | |
152 | C | Pocket Book | PROGRAMMING | 1,400 | [
"combinatorics"
] | null | null | One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers *i*, *j*, *k* (1<=... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of names and the length of each name, correspondingly. Then *n* lines contain names, each name consists of exactly *m* uppercase Latin letters. | Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109<=+<=7). | [
"2 3\nAAB\nBAA\n",
"4 5\nABABA\nBCGDG\nAAAAA\nYABSA\n"
] | [
"4\n",
"216\n"
] | In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB". | 1,500 | [
{
"input": "2 3\nAAB\nBAA",
"output": "4"
},
{
"input": "4 5\nABABA\nBCGDG\nAAAAA\nYABSA",
"output": "216"
},
{
"input": "1 1\nE",
"output": "1"
},
{
"input": "2 2\nNS\nPD",
"output": "4"
},
{
"input": "3 4\nPJKD\nNFJX\nFGFK",
"output": "81"
},
{
"inpu... | 1,622,825,696 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 248 | 0 | # find the unique set of string for all prefix length
n, m = list(map(int, input().split()))
names = []
for _ in range(n):
names.append(input())
mod = int(1e9+7)
ans = 1
for l in range(m):
uniques = set()
for name in names:
uniques.add(name[l])
ans = (ans%mod * len(uniques)%mod)%mod
print(ans) | Title: Pocket Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written.
... | ```python
# find the unique set of string for all prefix length
n, m = list(map(int, input().split()))
names = []
for _ in range(n):
names.append(input())
mod = int(1e9+7)
ans = 1
for l in range(m):
uniques = set()
for name in names:
uniques.add(name[l])
ans = (ans%mod * len(uniques)%mod)%mod
... | 3 | |
772 | A | Voltage Keepsake | PROGRAMMING | 1,800 | [
"binary search",
"math"
] | null | null | You have *n* devices that you want to use simultaneously.
The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-th device currently has *b**i* units of power stored. All devices can store an arbitrary amount of pow... | The first line contains two integers, *n* and *p* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*p*<=≤<=109) — the number of devices and the power of the charger.
This is followed by *n* lines which contain two integers each. Line *i* contains the integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100<=000) — the power of the dev... | If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4.
Namely, let's assume that your answer is *a* and the answer of the jury is *b*. The chec... | [
"2 1\n2 2\n2 1000\n",
"1 100\n1 1\n",
"3 5\n4 3\n5 2\n6 1\n"
] | [
"2.0000000000",
"-1\n",
"0.5000000000"
] | In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to char... | 500 | [
{
"input": "2 1\n2 2\n2 1000",
"output": "2.0000000000"
},
{
"input": "1 100\n1 1",
"output": "-1"
},
{
"input": "3 5\n4 3\n5 2\n6 1",
"output": "0.5000000000"
},
{
"input": "1 1\n1 87",
"output": "-1"
},
{
"input": "1 1\n100 77",
"output": "0.7777777778"
},... | 1,692,205,979 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 20 | 2,000 | 11,980,800 | def can_last_time(t, devices, p):
power_needed = 0
for a, b in devices:
power_used = a * t
if power_used > b:
power_needed += power_used - b
remaining_power = p * t - power_needed
return remaining_power >= 0
def binary_search(n, p, devices):
left, right = 0, 10**18
w... | Title: Voltage Keepsake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *n* devices that you want to use simultaneously.
The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-... | ```python
def can_last_time(t, devices, p):
power_needed = 0
for a, b in devices:
power_used = a * t
if power_used > b:
power_needed += power_used - b
remaining_power = p * t - power_needed
return remaining_power >= 0
def binary_search(n, p, devices):
left, right = 0, 10... | 0 | |
110 | A | Nearly Lucky Number | PROGRAMMING | 800 | [
"implementation"
] | A. Nearly Lucky Number | 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.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d... | The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). | [
"40047\n",
"7747774\n",
"1000000000000000000\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | 500 | [
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
... | 1,696,348,589 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 921,600 | import sys
import math
import bisect
import heapq
import itertools
from sys import stdin,stdout
from math import gcd,floor,sqrt,log
from collections import defaultdict, Counter, deque
from bisect import bisect_left,bisect_right, insort_left, insort_right
import re
mod=1000000007
def get_ints(): return ma... | Title: Nearly Lucky Number
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
import sys
import math
import bisect
import heapq
import itertools
from sys import stdin,stdout
from math import gcd,floor,sqrt,log
from collections import defaultdict, Counter, deque
from bisect import bisect_left,bisect_right, insort_left, insort_right
import re
mod=1000000007
def get_ints():... | 3.967283 |
1,005 | A | Tanya and Stairways | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $1$ to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains $3$ steps, and the second contains $4$ ... | The first line contains $n$ ($1 \le n \le 1000$) — the total number of numbers pronounced by Tanya.
The second line contains integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1000$) — all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway wit... | In the first line, output $t$ — the number of stairways that Tanya climbed. In the second line, output $t$ numbers — the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways. | [
"7\n1 2 3 1 2 3 4\n",
"4\n1 1 1 1\n",
"5\n1 2 3 4 5\n",
"5\n1 2 1 2 1\n"
] | [
"2\n3 4 ",
"4\n1 1 1 1 ",
"1\n5 ",
"3\n2 2 1 "
] | none | 0 | [
{
"input": "7\n1 2 3 1 2 3 4",
"output": "2\n3 4 "
},
{
"input": "4\n1 1 1 1",
"output": "4\n1 1 1 1 "
},
{
"input": "5\n1 2 3 4 5",
"output": "1\n5 "
},
{
"input": "5\n1 2 1 2 1",
"output": "3\n2 2 1 "
},
{
"input": "1\n1",
"output": "1\n1 "
},
{
"inp... | 1,640,243,253 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 62 | 0 | n=int(input())
stairs=input().split()
stairs_int=[]
count=0
stairs_climbed=[]
for i in stairs:
stairs_int.append(int(i))
for i in range(0,len(stairs_int)):
if stairs_int[i]==1:
count+=1
for i in range(1,len(stairs_int)):
if stairs_int[i]==1:
stairs_climbed.append(stairs_int[i... | Title: Tanya and Stairways
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $1$ to the number of steps in this stairway. She speaks every number aloud. For ... | ```python
n=int(input())
stairs=input().split()
stairs_int=[]
count=0
stairs_climbed=[]
for i in stairs:
stairs_int.append(int(i))
for i in range(0,len(stairs_int)):
if stairs_int[i]==1:
count+=1
for i in range(1,len(stairs_int)):
if stairs_int[i]==1:
stairs_climbed.append(st... | 3 | |
245 | A | System Administrator | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x... | In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format. | [
"2\n1 5 5\n2 6 4\n",
"3\n1 0 10\n2 0 10\n1 10 0\n"
] | [
"LIVE\nLIVE\n",
"LIVE\nDEAD\n"
] | Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to t... | 0 | [
{
"input": "2\n1 5 5\n2 6 4",
"output": "LIVE\nLIVE"
},
{
"input": "3\n1 0 10\n2 0 10\n1 10 0",
"output": "LIVE\nDEAD"
},
{
"input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9",
"output": "DEAD\nLIVE"
},
{
"input": "11\n1 8 2\n1 6 4\n1 9 1\n1... | 1,542,794,430 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 216 | 0 | n = int(input())
d = 0
g = 0
h = 0
j = 0
for i in range(n):
a,b,c = map(int,input().split())
if a == 1:
if b > 0:
d += 1
elif a == 2:
j += 1
if c > 0:
g += 1
if d > 0 and g >= j:
print("LIVE")
print("LIVE")
elif d > h and g == j:
... | Title: System Administrator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping co... | ```python
n = int(input())
d = 0
g = 0
h = 0
j = 0
for i in range(n):
a,b,c = map(int,input().split())
if a == 1:
if b > 0:
d += 1
elif a == 2:
j += 1
if c > 0:
g += 1
if d > 0 and g >= j:
print("LIVE")
print("LIVE")
elif d > h and... | 0 | |
38 | A | Army | PROGRAMMING | 800 | [
"implementation"
] | A. Army | 2 | 256 | The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is... | The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=*n*). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. | [
"3\n5 6\n1 2\n",
"3\n5 6\n1 3\n"
] | [
"5\n",
"11\n"
] | none | 0 | [
{
"input": "3\n5 6\n1 2",
"output": "5"
},
{
"input": "3\n5 6\n1 3",
"output": "11"
},
{
"input": "2\n55\n1 2",
"output": "55"
},
{
"input": "3\n85 78\n1 3",
"output": "163"
},
{
"input": "4\n63 4 49\n2 3",
"output": "4"
},
{
"input": "5\n93 83 42 56\n... | 1,509,279,971 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 124 | 0 | n=int(input())
t=list(map(int,input().split()))
a,b=map(int,input().split())
d=0
for i in range(a,b):
d+=t[i-1]
print(d) | Title: Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<... | ```python
n=int(input())
t=list(map(int,input().split()))
a,b=map(int,input().split())
d=0
for i in range(a,b):
d+=t[i-1]
print(d)
``` | 3.969 |
629 | A | Far Relative’s Birthday Cake | PROGRAMMING | 800 | [
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null | Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta... | In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. | Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. | [
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] | [
"4\n",
"9\n"
] | If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3) | 500 | [
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},... | 1,554,206,228 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | n = int(input())
a = []
h = 0
for i in range(n):
b = [i for i in input().split("")]
b.append(".")
a.append(b)
a.append(["."] * (n +1))
for i in range(n):
for j in range(n):
if a[i][j] == "C" and (a[i +1][j] == "C" or a[i][j + 1] == "C"):
h += 1
print(h) | Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with s... | ```python
n = int(input())
a = []
h = 0
for i in range(n):
b = [i for i in input().split("")]
b.append(".")
a.append(b)
a.append(["."] * (n +1))
for i in range(n):
for j in range(n):
if a[i][j] == "C" and (a[i +1][j] == "C" or a[i][j + 1] == "C"):
h += 1
pri... | -1 | |
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,482,880,730 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 4,608,000 | n=int(input())
t=list(map(int,input().split()))
h=len(set(t))
t.sort()
a=1
b=0
for i in range(n-1):
if t[i]==t[i+1]:
a+=1
else:
b=a
a=1
b=max(b,a)
print(b,h) | 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
n=int(input())
t=list(map(int,input().split()))
h=len(set(t))
t.sort()
a=1
b=0
for i in range(n-1):
if t[i]==t[i+1]:
a+=1
else:
b=a
a=1
b=max(b,a)
print(b,h)
``` | 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,370,891 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | # import sys
# sys.stdout = open('DSA/Stacks/output.txt', 'w')
# sys.stdin = open('DSA/Stacks/input.txt', 'r')
alphs = [chr(i) for i in range(97,123)]
n, k = map(int, input().split())
ss = ""
for i in range(k):
ss+=alphs[i]
i = 1
while i<n-k:
ss+=ss[len(ss)%(i)]
i+=1
if len(ss)!=n:
ss... | 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 sys
# sys.stdout = open('DSA/Stacks/output.txt', 'w')
# sys.stdin = open('DSA/Stacks/input.txt', 'r')
alphs = [chr(i) for i in range(97,123)]
n, k = map(int, input().split())
ss = ""
for i in range(k):
ss+=alphs[i]
i = 1
while i<n-k:
ss+=ss[len(ss)%(i)]
i+=1
if len(ss)!=... | 0 | |
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "Y... | 1,626,363,541 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 6,963,200 | def swap_check():
global flag
global genome_1, genome_2
local_flag = 1
i = 0
while i < len(genome_1)-1:
print(i)
if genome_1[i]+genome_1[i+1] != genome_2[i]+genome_2[i+1]:
if genome_1[i]+genome_1[i+1] != genome_2[i+1]+genome_2[i]:
loca... | Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ... | ```python
def swap_check():
global flag
global genome_1, genome_2
local_flag = 1
i = 0
while i < len(genome_1)-1:
print(i)
if genome_1[i]+genome_1[i+1] != genome_2[i]+genome_2[i+1]:
if genome_1[i]+genome_1[i+1] != genome_2[i+1]+genome_2[i]:
... | 0 | |
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor... | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input"... | 1,589,102,770 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 280 | 20,172,800 | check = {}
count = 0
for i in range(int(input())):
species, colour = map(str, input().split())
if species not in check:
check[species] = []
if colour not in check[species]:
check[species].append(colour)
count = count +1
print(count) | Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the specie... | ```python
check = {}
count = 0
for i in range(int(input())):
species, colour = map(str, input().split())
if species not in check:
check[species] = []
if colour not in check[species]:
check[species].append(colour)
count = count +1
print(count)
``` | 3.892425 |
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number ... | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25"... | 1,485,971,376 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 77 | 4,608,000 | a,b=(int(z) for z in input().split())
if a-b in [0,1,-1] and a+b>0 and a>=0 and b>=0:
print("YES")
else:
print("NO") | Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has so... | ```python
a,b=(int(z) for z in input().split())
if a-b in [0,1,-1] and a+b>0 and a>=0 and b>=0:
print("YES")
else:
print("NO")
``` | 3 | |
600 | D | Area of Two Circles' Intersection | PROGRAMMING | 2,000 | [
"geometry"
] | null | null | You are given two circles. Find the area of their intersection. | The first line contains three integers *x*1,<=*y*1,<=*r*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109,<=1<=≤<=*r*1<=≤<=109) — the position of the center and the radius of the first circle.
The second line contains three integers *x*2,<=*y*2,<=*r*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109,<=1<=≤<=*r*2<=≤<=109) — the position of the cen... | Print the area of the intersection of the circles. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"0 0 4\n6 0 4\n",
"0 0 5\n11 0 5\n"
] | [
"7.25298806364175601379\n",
"0.00000000000000000000\n"
] | none | 0 | [
{
"input": "0 0 4\n6 0 4",
"output": "7.25298806364175601379"
},
{
"input": "0 0 5\n11 0 5",
"output": "0.00000000000000000000"
},
{
"input": "0 0 10\n9 0 1",
"output": "3.14159265358979311600"
},
{
"input": "0 0 2\n2 2 2",
"output": "2.28318530717958647659"
},
{
... | 1,698,341,339 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 35 | 61 | 0 | from math import pi, acos, sin
import sys
x1, y1, r1 = [int(x) for x in input().split()]
x2, y2, r2 = [int(x) for x in input().split()]
if (x1, y1) == (x2, y2):
print(pi*min(r1, r2)**2)
sys.exit(0)
x2 -= x1
y2 -= y1
AC = abs(x2+y2*(1j))
r1, r2 = max(r1, r2), min(r1, r2)
EPS = 1e-9
if AC + r2 < r1 ... | Title: Area of Two Circles' Intersection
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two circles. Find the area of their intersection.
Input Specification:
The first line contains three integers *x*1,<=*y*1,<=*r*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109,<=1<=≤<=*r*1<=≤<=109) —... | ```python
from math import pi, acos, sin
import sys
x1, y1, r1 = [int(x) for x in input().split()]
x2, y2, r2 = [int(x) for x in input().split()]
if (x1, y1) == (x2, y2):
print(pi*min(r1, r2)**2)
sys.exit(0)
x2 -= x1
y2 -= y1
AC = abs(x2+y2*(1j))
r1, r2 = max(r1, r2), min(r1, r2)
EPS = 1e-9
if AC ... | 0 | |
463 | B | Caisa and Pylons | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=><=0) has height *h**i*. The goal of the game is ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | [
"5\n3 4 3 2 4\n",
"3\n4 4 4\n"
] | [
"4\n",
"4\n"
] | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | 1,000 | [
{
"input": "5\n3 4 3 2 4",
"output": "4"
},
{
"input": "3\n4 4 4",
"output": "4"
},
{
"input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 20... | 1,666,165,344 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 134,860,800 | import sys
import threading
from functools import lru_cache
from bisect import bisect_left
from collections import defaultdict, deque
from heapq import *
def main():
n = int(input())
h = [int(i) for i in input().split()]
ans = h[0]
cur = 0
for index in range(n-1):
if h[index] ... | Title: Caisa and Pylons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0... | ```python
import sys
import threading
from functools import lru_cache
from bisect import bisect_left
from collections import defaultdict, deque
from heapq import *
def main():
n = int(input())
h = [int(i) for i in input().split()]
ans = h[0]
cur = 0
for index in range(n-1):
if... | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,659,519,500 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | numbers = int(input())
array = [int(x) for x in input().split(' ')
even = 0
odd = 0
tab = []
for i in range(number):
if x % 2 == 0:
if odd > 1:
print(i + 1)
else:
even += 1
else:
if even > 1:
print(i + 1)
else:
odd +=... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
numbers = int(input())
array = [int(x) for x in input().split(' ')
even = 0
odd = 0
tab = []
for i in range(number):
if x % 2 == 0:
if odd > 1:
print(i + 1)
else:
even += 1
else:
if even > 1:
print(i + 1)
else:
... | -1 |
637 | A | Voting for Photos | PROGRAMMING | 1,000 | [
"*special",
"constructive algorithms",
"implementation"
] | null | null | After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the win... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the total likes to the published photoes.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000), where *a**i* is the identifier of the photo which got the *i*-th like. | Print the identifier of the photo which won the elections. | [
"5\n1 3 2 2 1\n",
"9\n100 200 300 200 100 300 300 100 200\n"
] | [
"2\n",
"300\n"
] | In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second).
Thus, the winner is the photo with identifier 2, as it got:
- more likes than the photo with id 3; - as many likes as the photo with id 1, but t... | 500 | [
{
"input": "5\n1 3 2 2 1",
"output": "2"
},
{
"input": "9\n100 200 300 200 100 300 300 100 200",
"output": "300"
},
{
"input": "1\n5",
"output": "5"
},
{
"input": "1\n1000000",
"output": "1000000"
},
{
"input": "5\n1 3 4 2 2",
"output": "2"
},
{
"input... | 1,611,406,550 | 2,147,483,647 | Python 3 | OK | TESTS | 65 | 93 | 307,200 | a = int(input())
b = list(map(int,input().split()))
d = []
e = []
c = 0
for x in b:
if b.count(x) > c:
c = b.count(x)
for x in b:
if b.count(x) == c:
d.append(x)
for x in range(len(d)):
a = 0
if d.count(d[a]) != 1:
d.pop(d.index(d[a]))
else:
a += 1
print(d[0]) | Title: Voting for Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rule... | ```python
a = int(input())
b = list(map(int,input().split()))
d = []
e = []
c = 0
for x in b:
if b.count(x) > c:
c = b.count(x)
for x in b:
if b.count(x) == c:
d.append(x)
for x in range(len(d)):
a = 0
if d.count(d[a]) != 1:
d.pop(d.index(d[a]))
else:
a += 1
print(d[0])
``` | 3 | |
739 | B | Alyona and a tree | PROGRAMMING | 1,900 | [
"binary search",
"data structures",
"dfs and similar",
"graphs",
"trees"
] | null | null | Alyona has a tree with *n* vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex *i* she wrote *a**i*. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, different integers on different edges).
Let's define *dist*(*v*,<=*u*) as the ... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105).
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the integers written in the vertices.
The next (*n*<=-<=1) lines contain two integers each. The *i*-th of these lines contains integers *p**i* and *w**i* (1<=≤<=*... | Print *n* integers — the *i*-th of these numbers should be equal to the number of vertices that the *i*-th vertex controls. | [
"5\n2 5 1 4 6\n1 7\n1 1\n3 5\n3 6\n",
"5\n9 7 8 6 5\n1 1\n2 1\n3 1\n4 1\n"
] | [
"1 0 1 0 0\n",
"4 3 2 1 0\n"
] | In the example test case the vertex 1 controls the vertex 3, the vertex 3 controls the vertex 5 (note that is doesn't mean the vertex 1 controls the vertex 5). | 1,000 | [
{
"input": "5\n2 5 1 4 6\n1 7\n1 1\n3 5\n3 6",
"output": "1 0 1 0 0"
},
{
"input": "5\n9 7 8 6 5\n1 1\n2 1\n3 1\n4 1",
"output": "4 3 2 1 0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 1\n1 1",
"output": "1 0"
},
{
"input": "10\n40 77 65 14 86 16 2 51 ... | 1,692,609,043 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | print("_RANDOM_GUESS_1692609043.635667")# 1692609043.6356852 | Title: Alyona and a tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alyona has a tree with *n* vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex *i* she wrote *a**i*. Moreover, the girl wrote a positive integer to every edge... | ```python
print("_RANDOM_GUESS_1692609043.635667")# 1692609043.6356852
``` | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,693,734,798 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 15 | 0 | (l,b,a)=map(int,input().split())
c=0
if(b%a==0):
c=b//a
else:
c=b//a+1
if(l%a==0):
c=c+l//a
else:
c=c+l//a+1
print(c) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
(l,b,a)=map(int,input().split())
c=0
if(b%a==0):
c=b//a
else:
c=b//a+1
if(l%a==0):
c=c+l//a
else:
c=c+l//a+1
print(c)
``` | 0 |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th... | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar... | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
... | 1,682,686,385 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 46 | 0 | a, b = map(int, input().split())
muxs = 240 - b
sum1 = 0
f = False
for i in range(1, a + 1):
if muxs - (5 * i) == 0:
sum1 += 1
break
elif muxs - (5 * i) < 0:
print(sum1)
f = True
break
else:
muxs -= 5 * i
sum1 += 1
if f is False:
pr... | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem... | ```python
a, b = map(int, input().split())
muxs = 240 - b
sum1 = 0
f = False
for i in range(1, a + 1):
if muxs - (5 * i) == 0:
sum1 += 1
break
elif muxs - (5 * i) < 0:
print(sum1)
f = True
break
else:
muxs -= 5 * i
sum1 += 1
if f is Fals... | 3 | |
814 | C | An impassioned circulation of affection | PROGRAMMING | 1,600 | [
"brute force",
"dp",
"strings",
"two pointers"
] | null | null | Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it!
Still unsatisfied with the garland, Nadeko decided to polish it again. The garland has *n* pieces numbered from 1 to *n* fro... | The first line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=500) — the length of the garland.
The second line contains *n* lowercase English letters *s*1*s*2... *s**n* as a string — the initial colours of paper pieces on the garland.
The third line contains a positive integer *q* (1<=≤<=*q*<=≤<=200<=000... | Output *q* lines: for each work plan, output one line containing an integer — the largest Koyomity achievable after repainting the garland according to it. | [
"6\nkoyomi\n3\n1 o\n4 o\n4 m\n",
"15\nyamatonadeshiko\n10\n1 a\n2 a\n3 a\n4 a\n5 a\n1 b\n2 b\n3 b\n4 b\n5 b\n",
"10\naaaaaaaaaa\n2\n10 b\n10 z\n"
] | [
"3\n6\n5\n",
"3\n4\n5\n7\n8\n1\n2\n3\n4\n5\n",
"10\n10\n"
] | In the first sample, there are three plans:
- In the first plan, at most 1 piece can be repainted. Repainting the "y" piece to become "o" results in "kooomi", whose Koyomity of 3 is the best achievable; - In the second plan, at most 4 pieces can be repainted, and "oooooo" results in a Koyomity of 6; - In the third... | 1,750 | [
{
"input": "6\nkoyomi\n3\n1 o\n4 o\n4 m",
"output": "3\n6\n5"
},
{
"input": "15\nyamatonadeshiko\n10\n1 a\n2 a\n3 a\n4 a\n5 a\n1 b\n2 b\n3 b\n4 b\n5 b",
"output": "3\n4\n5\n7\n8\n1\n2\n3\n4\n5"
},
{
"input": "10\naaaaaaaaaa\n2\n10 b\n10 z",
"output": "10\n10"
},
{
"input": "1... | 1,615,302,682 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 1,684 | 14,233,600 | import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline
def getCons(string, m, c):
n = len(string)
ans = 0
st, end = 0, 0
while end < n:
if string[end] == c:
end += 1
elif m:
m... | Title: An impassioned circulation of affection
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it!
... | ```python
import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline
def getCons(string, m, c):
n = len(string)
ans = 0
st, end = 0, 0
while end < n:
if string[end] == c:
end += 1
elif m:
... | 3 | |
171 | B | Star | PROGRAMMING | 1,300 | [
"*special",
"combinatorics"
] | null | null | The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257). | Print a single integer *output* (1<=≤<=*output*<=≤<=2·109). | [
"2\n"
] | [
"13"
] | none | 0 | [
{
"input": "2",
"output": "13"
},
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "37"
},
{
"input": "4",
"output": "73"
},
{
"input": "5",
"output": "121"
},
{
"input": "6",
"output": "181"
},
{
"input": "7",
"output": "253"... | 1,585,568,773 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 0 | a = input()
s = []
for i in a:
s.append(i-1,i+1)
z = ''.join(s)
print(z) | Title: Star
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257).
Output Specification:
Print a single integer *output* (1<=≤<=*output*<=≤<=2·109).
Demo Input:
['2\n']
Demo Output:
['13']
Note:
none | ```python
a = input()
s = []
for i in a:
s.append(i-1,i+1)
z = ''.join(s)
print(z)
``` | -1 | ||
0 | none | none | none | 0 | [
"none"
] | null | null | International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where *y* stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string *y* that has never been used before.... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of abbreviations to process.
Then *n* lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. | For each abbreviation given in the input, find the year of the corresponding Olympiad. | [
"5\nIAO'15\nIAO'2015\nIAO'1\nIAO'9\nIAO'0\n",
"4\nIAO'9\nIAO'99\nIAO'999\nIAO'9999\n"
] | [
"2015\n12015\n1991\n1989\n1990\n",
"1989\n1999\n2999\n9999\n"
] | none | 0 | [
{
"input": "5\nIAO'15\nIAO'2015\nIAO'1\nIAO'9\nIAO'0",
"output": "2015\n12015\n1991\n1989\n1990"
},
{
"input": "4\nIAO'9\nIAO'99\nIAO'999\nIAO'9999",
"output": "1989\n1999\n2999\n9999"
},
{
"input": "1\nIAO'111110",
"output": "1111110"
},
{
"input": "2\nIAO'0\nIAO'00",
"o... | 1,460,958,559 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 77 | 5,120,000 | tn=[0]*10000
ts=[0]*10000
a=1989
tn[1]=1989
ts[1]=9
for i in range(1,12):
a=a+(10**i)
tn[i+1]=a
ts[i+1]=int(str(a)[-i-1:])
noc=int(input())
for fk in range(noc):
a=input()[4:]
temp=len(a)
a=int(a)
print((a-ts[temp])%(10**temp)+tn[temp])
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where *y* stands for some number of consequent last digits of the current year. Organiz... | ```python
tn=[0]*10000
ts=[0]*10000
a=1989
tn[1]=1989
ts[1]=9
for i in range(1,12):
a=a+(10**i)
tn[i+1]=a
ts[i+1]=int(str(a)[-i-1:])
noc=int(input())
for fk in range(noc):
a=input()[4:]
temp=len(a)
a=int(a)
print((a-ts[temp])%(10**temp)+tn[temp])
``` | 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,589,478,392 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 6,963,200 | import sys
def data():
return sys.stdin.readline().strip()
def sp(): return map(int, data().split())
def l(): return list(sp())
n=int(data())
temp=l()
res=[]
for i in temp[1:-1]:
res.append(temp.remove(i))
ans=0
for i,val in enumerate(res):
for x in range(1,le... | 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
import sys
def data():
return sys.stdin.readline().strip()
def sp(): return map(int, data().split())
def l(): return list(sp())
n=int(data())
temp=l()
res=[]
for i in temp[1:-1]:
res.append(temp.remove(i))
ans=0
for i,val in enumerate(res):
for x in ... | -1 | |
2 | B | The least round way | PROGRAMMING | 2,000 | [
"dp",
"math"
] | B. The least round way | 2 | 64 | There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all... | The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | [
"3\n1 2 3\n4 5 6\n7 8 9\n"
] | [
"0\nDDRR\n"
] | none | 0 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "0\nDDRR"
},
{
"input": "2\n7 6\n3 8",
"output": "0\nDR"
},
{
"input": "3\n4 10 5\n10 9 4\n6 5 3",
"output": "1\nDRRD"
},
{
"input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5",
"output": "0\nDDDRRR"
},
{
"input": "5\n8 3... | 1,690,105,073 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | def cntn(a):
a1 = str(a)
for i in range(-1, -(len(str(a)) + 1), -1):
if a1[i] != '0':
return -(i + 1)
return 1 if a == 0 else 0
n = int(input())
field = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * n for i in range(n)]
dps = [[''] * n for i in range(n)]
d... | Title: The least round way
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down fro... | ```python
def cntn(a):
a1 = str(a)
for i in range(-1, -(len(str(a)) + 1), -1):
if a1[i] != '0':
return -(i + 1)
return 1 if a == 0 else 0
n = int(input())
field = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * n for i in range(n)]
dps = [[''] * n for i in ra... | 0 |
463 | B | Caisa and Pylons | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=><=0) has height *h**i*. The goal of the game is ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | [
"5\n3 4 3 2 4\n",
"3\n4 4 4\n"
] | [
"4\n",
"4\n"
] | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | 1,000 | [
{
"input": "5\n3 4 3 2 4",
"output": "4"
},
{
"input": "3\n4 4 4",
"output": "4"
},
{
"input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 20... | 1,643,419,024 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 155 | 12,390,400 | #For fast I/O
import sys
input = lambda: sys.stdin.readline().strip()
n = int(input())
l = [int(i) for i in input().split()]
print(max(l))
| Title: Caisa and Pylons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0... | ```python
#For fast I/O
import sys
input = lambda: sys.stdin.readline().strip()
n = int(input())
l = [int(i) for i in input().split()]
print(max(l))
``` | 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,634,041,985 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | m,n=map(int,input().split())
if m==1andn==1:
print(0)
else:
print(int(m*n0//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
m,n=map(int,input().split())
if m==1andn==1:
print(0)
else:
print(int(m*n0//2)
``` | -1 |
471 | A | MUH and Sticks | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
-... | The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. | If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). | [
"4 2 5 4 4 4\n",
"4 4 5 4 4 5\n",
"1 2 3 4 5 6\n"
] | [
"Bear",
"Elephant",
"Alien"
] | If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | 500 | [
{
"input": "4 2 5 4 4 4",
"output": "Bear"
},
{
"input": "4 4 5 4 4 5",
"output": "Elephant"
},
{
"input": "1 2 3 4 5 6",
"output": "Alien"
},
{
"input": "5 5 5 5 5 5",
"output": "Elephant"
},
{
"input": "1 1 1 2 3 5",
"output": "Alien"
},
{
"input": "... | 1,411,749,408 | 4,008 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 31 | 409,600 | #!/usr/bin/env python3
from collections import Counter
sticks = Counter([int(number) for number in input("Sticks: ").split(" ")])
have_legs = False
legs_lenght = 0
for key in sticks:
if sticks[key] >= 4:
have_legs = True
legs_lenght = key
legs = Counter({legs_lenght:4})
rest = sticks -... | Title: MUH and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an... | ```python
#!/usr/bin/env python3
from collections import Counter
sticks = Counter([int(number) for number in input("Sticks: ").split(" ")])
have_legs = False
legs_lenght = 0
for key in sticks:
if sticks[key] >= 4:
have_legs = True
legs_lenght = key
legs = Counter({legs_lenght:4})
rest ... | 0 | |
898 | E | Squares and not squares | PROGRAMMING | 1,600 | [
"constructive algorithms",
"greedy"
] | null | null | Ann and Borya have *n* piles with candies and *n* is even number. There are *a**i* candies in pile with number *i*.
Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this can... | First line contains one even integer *n* (2<=≤<=*n*<=≤<=200<=000) — number of piles with candies.
Second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — amounts of candies in each pile. | Output minimal number of steps required to make exactly *n*<=/<=2 piles contain number of candies that is a square of some integer and exactly *n*<=/<=2 piles contain number of candies that is not a square of any integer. If condition is already satisfied output 0. | [
"4\n12 14 30 4\n",
"6\n0 0 0 0 0 0\n",
"6\n120 110 23 34 25 45\n",
"10\n121 56 78 81 45 100 1 0 54 78\n"
] | [
"2\n",
"6\n",
"3\n",
"0\n"
] | In first example you can satisfy condition in two moves. During each move you should add one candy to second pile. After it size of second pile becomes 16. After that Borya and Ann will have two piles with number of candies which is a square of integer (second and fourth pile) and two piles with number of candies which... | 2,000 | [
{
"input": "4\n12 14 30 4",
"output": "2"
},
{
"input": "6\n0 0 0 0 0 0",
"output": "6"
},
{
"input": "6\n120 110 23 34 25 45",
"output": "3"
},
{
"input": "10\n121 56 78 81 45 100 1 0 54 78",
"output": "0"
},
{
"input": "10\n0 675178538 310440616 608075179 0 0 0 ... | 1,615,241,037 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 17,305,600 | sqrs =[-1] + [i*i for i in range(31625)]
from bisect import bisect_left, insort
n = int(input())
na, nb, A, B = 0, 0, list(), list()
for v in map(int, input().split()):
i = bisect_left(sqrs, v)
dist = min(v-sqrs[i-1], sqrs[i]-v)
if dist == 0:
na += 1
dist = (2 if v==0 else 1)
insort(... | Title: Squares and not squares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann and Borya have *n* piles with candies and *n* is even number. There are *a**i* candies in pile with number *i*.
Ann likes numbers which are square of some integer and Borya doesn't like numbers which are sq... | ```python
sqrs =[-1] + [i*i for i in range(31625)]
from bisect import bisect_left, insort
n = int(input())
na, nb, A, B = 0, 0, list(), list()
for v in map(int, input().split()):
i = bisect_left(sqrs, v)
dist = min(v-sqrs[i-1], sqrs[i]-v)
if dist == 0:
na += 1
dist = (2 if v==0 else 1)
... | 0 | |
171 | B | Star | PROGRAMMING | 1,300 | [
"*special",
"combinatorics"
] | null | null | The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257). | Print a single integer *output* (1<=≤<=*output*<=≤<=2·109). | [
"2\n"
] | [
"13"
] | none | 0 | [
{
"input": "2",
"output": "13"
},
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "37"
},
{
"input": "4",
"output": "73"
},
{
"input": "5",
"output": "121"
},
{
"input": "6",
"output": "181"
},
{
"input": "7",
"output": "253"... | 1,669,448,291 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 124 | 1,331,200 | a = int(input())
ans = 1
z = 12
for i in range(a-1):
ans += z
z += 12
print(ans)
| Title: Star
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257).
Output Specification:
Print a single integer *output* (1<=≤<=*output*<=≤<=2·109).
Demo Input:
['2\n']
Demo Output:
['13']
Note:
none | ```python
a = int(input())
ans = 1
z = 12
for i in range(a-1):
ans += z
z += 12
print(ans)
``` | 3 | ||
817 | A | Treasure Hunt | PROGRAMMING | 1,200 | [
"implementation",
"math",
"number theory"
] | null | null | Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values *x* and *y* written on it. These values define four moves which can be perfo... | The first line contains four integer numbers *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=105<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=105) — positions of Captain Bill the Hummingbird and treasure respectively.
The second line contains two integer numbers *x*,<=*y* (1<=≤<=*x*,<=*y*<=≤<=105) — values on the potion bottle. | Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes). | [
"0 0 0 6\n2 3\n",
"1 1 3 6\n1 5\n"
] | [
"YES\n",
"NO\n"
] | In the first example there exists such sequence of moves:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c939890fb4ed35688177327dac981bfa9216c00.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the first type of move 1. <img align="middle" class="tex-formula" src="https://espr... | 0 | [
{
"input": "0 0 0 6\n2 3",
"output": "YES"
},
{
"input": "1 1 3 6\n1 5",
"output": "NO"
},
{
"input": "5 4 6 -10\n1 1",
"output": "NO"
},
{
"input": "6 -3 -7 -7\n1 2",
"output": "NO"
},
{
"input": "2 -5 -8 8\n2 1",
"output": "YES"
},
{
"input": "70 -81... | 1,667,942,601 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | x1, y1, x2, y2 = map(int, input().strip().split())
dx, dy = map(int, input().strip().split())
delta_x, delta_y = x2-x1, y2-y1
if delta_x == 0 and delta_y == 0:
print("YES")
return
if delta_x == 0:
print("YES\n" if delta_y % dy == 0 else "NO\n")
return
elif delta_y == 0:
print("YES\n... | Title: Treasure Hunt
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with... | ```python
x1, y1, x2, y2 = map(int, input().strip().split())
dx, dy = map(int, input().strip().split())
delta_x, delta_y = x2-x1, y2-y1
if delta_x == 0 and delta_y == 0:
print("YES")
return
if delta_x == 0:
print("YES\n" if delta_y % dy == 0 else "NO\n")
return
elif delta_y == 0:
pr... | -1 | |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,688,112,444 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = int(input())
schedule = list(map(int, input().split(" ")))
d = [[0 for i in range(3)] for j in range(n+1)]
# first row both
# second row it
# third row gym
for i, v in enumerate(schedule):
if v == 1 or v == 3:
d[i+1][1] = max(d[i][0] + 1, d[i][2] + 1)
if v == 2 or v == 3:
... | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int... | ```python
n = int(input())
schedule = list(map(int, input().split(" ")))
d = [[0 for i in range(3)] for j in range(n+1)]
# first row both
# second row it
# third row gym
for i, v in enumerate(schedule):
if v == 1 or v == 3:
d[i+1][1] = max(d[i][0] + 1, d[i][2] + 1)
if v == 2 or v == 3:... | -1 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,690,521,894 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 62 | 0 | import sys
input = sys.stdin.readline
letters = set()
s = input().strip()
for c in s:
if c in " ,{}":
continue
letters.add(c)
print(len(letters)) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
import sys
input = sys.stdin.readline
letters = set()
s = input().strip()
for c in s:
if c in " ,{}":
continue
letters.add(c)
print(len(letters))
``` | 3 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,695,061,638 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | w = int(input())
c=0
for i in range(2, w+1, 2):
if ((w-i)%2==0):
c = c + 1
if ((w-i)==0):
c = c + 1
if c>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())
c=0
for i in range(2, w+1, 2):
if ((w-i)%2==0):
c = c + 1
if ((w-i)==0):
c = c + 1
if c>0:
print("YES")
else:
print("NO")
``` | 0 |
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* woode... | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal... | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ... | 1,630,517,101 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 186 | 7,577,600 | n = int(input())
arr = []
l,r =0,0
for i in range(n):
v = list(map(int,input().split()))
arr.append(v)
for i in range(n):
if arr[i][0] == 1:
l += 1
if arr[i][1] == 1:
r += 1
print(min(l,n-l)+min(r,n-r))
| Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long... | ```python
n = int(input())
arr = []
l,r =0,0
for i in range(n):
v = list(map(int,input().split()))
arr.append(v)
for i in range(n):
if arr[i][0] == 1:
l += 1
if arr[i][1] == 1:
r += 1
print(min(l,n-l)+min(r,n-r))
``` | 3 | |
727 | D | T-shirts Distribution | PROGRAMMING | 1,800 | [
"constructive algorithms",
"flows",
"greedy"
] | null | null | The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this si... | The first line of the input contains six non-negative integers — the number of t-shirts of each size. The numbers are given for the sizes S, M, L, XL, XXL, XXXL, respectively. The total number of t-shirts doesn't exceed 100<=000.
The second line contains positive integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of pa... | If it is not possible to present a t-shirt to each participant, print «NO» (without quotes).
Otherwise, print *n*<=+<=1 lines. In the first line print «YES» (without quotes). In the following *n* lines print the t-shirt sizes the orginizers should give to participants, one per line. The order of the participants shoul... | [
"0 1 0 1 1 0\n3\nXL\nS,M\nXL,XXL\n",
"1 1 2 0 1 1\n5\nS\nM\nS,M\nXXL,XXXL\nXL,XXL\n"
] | [
"YES\nXL\nM\nXXL\n",
"NO\n"
] | none | 1,500 | [
{
"input": "0 1 0 1 1 0\n3\nXL\nS,M\nXL,XXL",
"output": "YES\nXL\nM\nXXL"
},
{
"input": "1 1 2 0 1 1\n5\nS\nM\nS,M\nXXL,XXXL\nXL,XXL",
"output": "NO"
},
{
"input": "1 2 4 4 1 1\n10\nXL\nXL\nS,M\nL\nM,L\nL\nS,M\nM\nXL,XXL\nXL",
"output": "YES\nXL\nXL\nS\nL\nL\nL\nM\nM\nXL\nXL"
},
... | 1,656,838,544 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 125 | 483 | 20,889,600 | from bisect import *
from collections import *
import sys
import io, os
import math
import random
from heapq import *
gcd = math.gcd
sqrt = math.sqrt
maxint=10**21
def ceil(a, b):
if(b==0):
return maxint
a = -a
k = a // b
k = -k
return k
# arr=list(map(int, input().split()))... | Title: T-shirts Distribution
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The ... | ```python
from bisect import *
from collections import *
import sys
import io, os
import math
import random
from heapq import *
gcd = math.gcd
sqrt = math.sqrt
maxint=10**21
def ceil(a, b):
if(b==0):
return maxint
a = -a
k = a // b
k = -k
return k
# arr=list(map(int, input()... | 3 | |
735 | A | Ostap and Grasshopper | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The gr... | The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the correspondi... | If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes). | [
"5 2\n#G#T#\n",
"6 1\nT....G\n",
"7 3\nT..#..G\n",
"6 2\n..GT..\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a sin... | 500 | [
{
"input": "5 2\n#G#T#",
"output": "YES"
},
{
"input": "6 1\nT....G",
"output": "YES"
},
{
"input": "7 3\nT..#..G",
"output": "NO"
},
{
"input": "6 2\n..GT..",
"output": "NO"
},
{
"input": "2 1\nGT",
"output": "YES"
},
{
"input": "100 5\nG####.####.###... | 1,485,083,652 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 109 | 4,608,000 | def solve(s, k):
i = min(s.index('G'), s.index('T')) + k
while i < len(s):
if s[i] == '#': return "NO"
if s[i] in ['G', 'T']: return "YES"
i += k
return "NO"
n, k = map(int, input().split())
print(solve(input(), k))
| Title: Ostap and Grasshopper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles.... | ```python
def solve(s, k):
i = min(s.index('G'), s.index('T')) + k
while i < len(s):
if s[i] == '#': return "NO"
if s[i] in ['G', 'T']: return "YES"
i += k
return "NO"
n, k = map(int, input().split())
print(solve(input(), k))
``` | 3 | |
55 | B | Smallest number | PROGRAMMING | 1,600 | [
"brute force"
] | B. Smallest number | 2 | 256 | Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced... | First line contains four integers separated by space: 0<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) | Output one integer number — the minimal result which can be obtained.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). | [
"1 1 1 1\n+ + *\n",
"2 2 2 2\n* * +\n",
"1 2 3 4\n* + +\n"
] | [
"3\n",
"8\n",
"9\n"
] | none | 1,000 | [
{
"input": "1 1 1 1\n+ + *",
"output": "3"
},
{
"input": "2 2 2 2\n* * +",
"output": "8"
},
{
"input": "1 2 3 4\n* + +",
"output": "9"
},
{
"input": "15 1 3 1\n* * +",
"output": "18"
},
{
"input": "8 1 7 14\n+ + +",
"output": "30"
},
{
"input": "7 17 3... | 1,667,125,294 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 122 | 0 |
l = [int(i) for i in input().split()]
o = [i for i in input().split()]
def smallnumber(l,o):
if(len(l)<=1 or len(o)<1):
return l[0]
if(o[0] == "+"):
res = l[0]+l[1]
l2 = l[2:]
l2.append(res)
o2 = o[1:]
#print(l2,o2)
result = smallnumber(l2... | Title: Smallest number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the n... | ```python
l = [int(i) for i in input().split()]
o = [i for i in input().split()]
def smallnumber(l,o):
if(len(l)<=1 or len(o)<1):
return l[0]
if(o[0] == "+"):
res = l[0]+l[1]
l2 = l[2:]
l2.append(res)
o2 = o[1:]
#print(l2,o2)
result = smal... | 0 |
979 | A | Pizza, Pizza, Pizza!!! | PROGRAMMING | 1,000 | [
"math"
] | null | null | Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to cele... | A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces. | A single integer — the number of straight cuts Shiro needs. | [
"3\n",
"4\n"
] | [
"2",
"5"
] | To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts. | 500 | [
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "5"
},
{
"input": "10",
"output": "11"
},
{
"input": "10000000000",
"output": "10000000001"
},
{
"input": "1234567891",
"output": "617283946"
},
{
"input": "7509213957",
"output": "37546069... | 1,699,863,802 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 46 | 0 | n = int(input())
n+=1
if(n==1):
print(0)
elif(n%2==0):
print(n//2)
else:
print(n)
| Title: Pizza, Pizza, Pizza!!!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthd... | ```python
n = int(input())
n+=1
if(n==1):
print(0)
elif(n%2==0):
print(n//2)
else:
print(n)
``` | 3 | |
264 | B | Good Sequences | PROGRAMMING | 1,500 | [
"dp",
"number theory"
] | null | null | Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks *n* integers *a*1,<=*a*2,<=...,<=*a**n* are good.
Now she is interested in good sequences. A sequence *x*1,<=*x*2,<=...,<=*x**k* is called good if it satisfies the following three conditions:
- The sequence is strictly increas... | The input consists of two lines. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of good integers. The second line contains a single-space separated list of good integers *a*1,<=*a*2,<=...,<=*a**n* in strictly increasing order (1<=≤<=*a**i*<=≤<=105; *a**i*<=<<=*a**i*<=+<=1). | Print a single integer — the length of the longest good sequence. | [
"5\n2 3 4 6 9\n",
"9\n1 2 3 5 6 7 8 9 10\n"
] | [
"4\n",
"4\n"
] | In the first example, the following sequences are examples of good sequences: [2; 4; 6; 9], [2; 4; 6], [3; 9], [6]. The length of the longest good sequence is 4. | 1,000 | [
{
"input": "5\n2 3 4 6 9",
"output": "4"
},
{
"input": "9\n1 2 3 5 6 7 8 9 10",
"output": "4"
},
{
"input": "4\n1 2 4 6",
"output": "3"
},
{
"input": "7\n1 2 3 4 7 9 10",
"output": "3"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "8\n3 4 5 6 7 8 9... | 1,626,664,174 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 38 | 684 | 31,948,800 | n=int(input())
a=list(map(int, input().split(" ")))
if(a==[1]*n):
print(1)
else:
primes=[True for i in range(401)]
primes[0]=False
primes[1]=False
for k in range(1, 401):
if(primes[k]==True):
for pro in range(k*k, 401, k):
primes[pro]=False
mine=[]
for k in range(401):
if(primes[k]):
mine.app... | Title: Good Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks *n* integers *a*1,<=*a*2,<=...,<=*a**n* are good.
Now she is interested in good sequences. A sequence *x*1,<=*x*2,<=...,<=*x**k*... | ```python
n=int(input())
a=list(map(int, input().split(" ")))
if(a==[1]*n):
print(1)
else:
primes=[True for i in range(401)]
primes[0]=False
primes[1]=False
for k in range(1, 401):
if(primes[k]==True):
for pro in range(k*k, 401, k):
primes[pro]=False
mine=[]
for k in range(401):
if(primes[k]):
... | 0 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,652,555,024 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 93 | 3,379,200 | n = int(input())
print(n)
for i in range(0, n):
print(1, end=" ") | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
n = int(input())
print(n)
for i in range(0, n):
print(1, end=" ")
``` | -1 | |
471 | A | MUH and Sticks | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
-... | The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. | If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). | [
"4 2 5 4 4 4\n",
"4 4 5 4 4 5\n",
"1 2 3 4 5 6\n"
] | [
"Bear",
"Elephant",
"Alien"
] | If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | 500 | [
{
"input": "4 2 5 4 4 4",
"output": "Bear"
},
{
"input": "4 4 5 4 4 5",
"output": "Elephant"
},
{
"input": "1 2 3 4 5 6",
"output": "Alien"
},
{
"input": "5 5 5 5 5 5",
"output": "Elephant"
},
{
"input": "1 1 1 2 3 5",
"output": "Alien"
},
{
"input": "... | 1,413,332,061 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 46 | 0 | def main():
x = [int(y) for y in input().split()] #Lectura de datos
x.sort()
rank = [0 for y in range(1,x[5]+2)]
patas = -1
r = []
for i in range(0,len(x)):
rank[x[i]]+=1
if(rank[x[i]] == 4):
patas=x[i]
if(patas != -1):
for i in range(0,len(rank... | Title: MUH and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an... | ```python
def main():
x = [int(y) for y in input().split()] #Lectura de datos
x.sort()
rank = [0 for y in range(1,x[5]+2)]
patas = -1
r = []
for i in range(0,len(x)):
rank[x[i]]+=1
if(rank[x[i]] == 4):
patas=x[i]
if(patas != -1):
for i in range(... | -1 | |
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,691,254,602 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 92 | 0 | input();d={};t=0
for i in input().split():
if i in d:d[i]+=1
else:d[i]=1
print(max(d.values()),len(d)) | 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
input();d={};t=0
for i in input().split():
if i in d:d[i]+=1
else:d[i]=1
print(max(d.values()),len(d))
``` | 3.977 |
988 | A | Diverse Team | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES"... | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student. | If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If t... | [
"5 3\n15 13 15 15 12\n",
"5 4\n15 13 15 15 12\n",
"4 4\n20 10 40 30\n"
] | [
"YES\n1 2 5 \n",
"NO\n",
"YES\n1 2 3 4 \n"
] | All possible answers for the first example:
- {1 2 5} - {2 3 5} - {2 4 5}
Note that the order does not matter. | 0 | [
{
"input": "5 3\n15 13 15 15 12",
"output": "YES\n1 2 5 "
},
{
"input": "5 4\n15 13 15 15 12",
"output": "NO"
},
{
"input": "4 4\n20 10 40 30",
"output": "YES\n1 2 3 4 "
},
{
"input": "1 1\n1",
"output": "YES\n1 "
},
{
"input": "100 53\n16 17 1 2 27 5 9 9 53 24 17... | 1,615,704,861 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 307,200 | while True:
try:
a, b = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
idx = {idx:val for val, idx in enumerate(l)}
if len(idx) >= b:
print("YES")
for key, value in idx.items():
if b < 0 :
break... | Title: Diverse Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct... | ```python
while True:
try:
a, b = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
idx = {idx:val for val, idx in enumerate(l)}
if len(idx) >= b:
print("YES")
for key, value in idx.items():
if b < 0 :
... | 0 | |
411 | A | Password Check | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che... | The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_". | If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes). | [
"abacaba\n",
"X12345\n",
"CONTEST_is_STARTED!!11\n"
] | [
"Too weak\n",
"Too weak\n",
"Correct\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "Too weak"
},
{
"input": "X12345",
"output": "Too weak"
},
{
"input": "CONTEST_is_STARTED!!11",
"output": "Correct"
},
{
"input": "1zA__",
"output": "Correct"
},
{
"input": "1zA_",
"output": "Too weak"
},
{
"input": "zA_... | 1,589,431,340 | 2,147,483,647 | PyPy 3 | OK | TESTS | 81 | 156 | 20,172,800 | s=input()
x,y,z=0,0,0
n=len(s)
if(n<5):
print("Too weak")
else:
for i in s:
if(i.isupper()):
x=1
break
for i in s:
if(i.islower()):
y=1
break
for i in s:
if(i.isdigit()):
z=1
break
if(x=... | Title: Password Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password... | ```python
s=input()
x,y,z=0,0,0
n=len(s)
if(n<5):
print("Too weak")
else:
for i in s:
if(i.isupper()):
x=1
break
for i in s:
if(i.islower()):
y=1
break
for i in s:
if(i.isdigit()):
z=1
break
... | 3 | |
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th... | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\... | 1,698,246,037 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n=int(input(""))
count=0
l=[]
for i in range(n):
z=input("")
l.append(z)
for i in range(len(l)):
if l[i] in ["x++","++x","+x+"]:
count+=1
else:
count=count-1
print(count) | Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ incre... | ```python
n=int(input(""))
count=0
l=[]
for i in range(n):
z=input("")
l.append(z)
for i in range(len(l)):
if l[i] in ["x++","++x","+x+"]:
count+=1
else:
count=count-1
print(count)
``` | 0 | |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara... | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ... | 1,671,212,042 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n,t=map(int,input().split())
mass=list(map(int,input().split()))
i=1
while i<=t:
i=mass[i-1]+l
if i==t:
print("YES");
break
else:
print("NO") | Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o... | ```python
n,t=map(int,input().split())
mass=list(map(int,input().split()))
i=1
while i<=t:
i=mass[i-1]+l
if i==t:
print("YES");
break
else:
print("NO")
``` | -1 | |
729 | A | Interview with Oleg | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters.
There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the interview.
The second line contains the string *s* of length *n*, consisting of lowercase English letters. | Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences. | [
"7\naogogob\n",
"13\nogogmgogogogo\n",
"9\nogoogoogo\n"
] | [
"a***b\n",
"***gmg***\n",
"*********\n"
] | The first sample contains one filler word ogogo, so the interview for printing is "a***b".
The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***". | 500 | [
{
"input": "7\naogogob",
"output": "a***b"
},
{
"input": "13\nogogmgogogogo",
"output": "***gmg***"
},
{
"input": "9\nogoogoogo",
"output": "*********"
},
{
"input": "32\nabcdefogoghijklmnogoopqrstuvwxyz",
"output": "abcdef***ghijklmn***opqrstuvwxyz"
},
{
"input":... | 1,598,906,424 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 109 | 307,200 | n = int(input())
s = input()
l = list(s)
i = 0
while i < n:
j = i
if s[i] == "o":
flag = 0
while s[i+1:i+3] == "go":
flag +=1
i = i+2
if flag >= 1:
for x in range(j,j+3):
l[x] = "*"
for x in range(j+3,i+1):
l[x] = "+"
i+=1
ans = ""
for i in l:
if i != "+":
ans+=i
pri... | Title: Interview with Oleg
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters.
There is a fi... | ```python
n = int(input())
s = input()
l = list(s)
i = 0
while i < n:
j = i
if s[i] == "o":
flag = 0
while s[i+1:i+3] == "go":
flag +=1
i = i+2
if flag >= 1:
for x in range(j,j+3):
l[x] = "*"
for x in range(j+3,i+1):
l[x] = "+"
i+=1
ans = ""
for i in l:
if i != "+":
a... | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,666,073,286 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 46 | 0 | def solve(numOne, numTwo):
newNum = []
for idx in range(len(numOne)):
if numOne[idx] != numTwo[idx]:
newNum.append("1")
else:
newNum.append("0")
return "".join(newNum)
numOne = input()
numTwo = input()
print(solve(numOne, numTwo)) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
def solve(numOne, numTwo):
newNum = []
for idx in range(len(numOne)):
if numOne[idx] != numTwo[idx]:
newNum.append("1")
else:
newNum.append("0")
return "".join(newNum)
numOne = input()
numTwo = input()
print(solve(numOne, numTwo))
``` | 3.9885 |
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,552,412,731 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 109 | 0 | n = int(input())
dp = [1, 2]
while dp[-2] + dp[-1] <= n:
dp.append(dp[-2] + dp[-1])
print(len(dp) - 1) | 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())
dp = [1, 2]
while dp[-2] + dp[-1] <= n:
dp.append(dp[-2] + dp[-1])
print(len(dp) - 1)
``` | 3 | |
386 | A | Second-Price Auction | PROGRAMMING | 800 | [
"implementation"
] | null | null | In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the au... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. | The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. | [
"2\n5 7\n",
"3\n10 2 8\n",
"6\n3 8 2 9 4 14\n"
] | [
"2 5\n",
"1 8\n",
"6 9\n"
] | none | 500 | [
{
"input": "2\n5 7",
"output": "2 5"
},
{
"input": "3\n10 2 8",
"output": "1 8"
},
{
"input": "6\n3 8 2 9 4 14",
"output": "6 9"
},
{
"input": "4\n4707 7586 4221 5842",
"output": "2 5842"
},
{
"input": "5\n3304 4227 4869 6937 6002",
"output": "4 6002"
},
{... | 1,666,892,999 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 93 | 0 | x = int(input())
z = input().split(" ")
fin = ""
for i in range(len(z)):
z[i] = int(z[i])
highest = z.index(max(z))
fin += str(highest+1)
fin += " "
z.sort()
sndhigh = z[-2]
fin += str(sndhigh)
print(fin) | Title: Second-Price Auction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is... | ```python
x = int(input())
z = input().split(" ")
fin = ""
for i in range(len(z)):
z[i] = int(z[i])
highest = z.index(max(z))
fin += str(highest+1)
fin += " "
z.sort()
sndhigh = z[-2]
fin += str(sndhigh)
print(fin)
``` | 3 | |
984 | B | Minesweeper | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won.
Alex has grown up since then, so he easily wins the most difficu... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 100$) — the sizes of the field.
The next $n$ lines contain the description of the field. Each line contains $m$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $1$ to $8$, inclusive. | Print "YES", if the field is valid and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrarily. | [
"3 3\n111\n1*1\n111\n",
"2 4\n*.*.\n1211\n"
] | [
"YES",
"NO"
] | In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1.
You can read more about Minesweeper in [Wikipedia's article](https://en.wikipedia.org/wiki/Minesweeper_(video_game)). | 1,000 | [
{
"input": "3 3\n111\n1*1\n111",
"output": "YES"
},
{
"input": "2 4\n*.*.\n1211",
"output": "NO"
},
{
"input": "1 10\n.....1*1..",
"output": "YES"
},
{
"input": "1 1\n4",
"output": "NO"
},
{
"input": "10 10\n..........\n...111111.\n..13*21*1.\n.12**2111.\n.1*542..... | 1,586,856,234 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 4 | 202 | 2,150,400 | n,m = map(int,input().split())
arr = []
for i in range(n):
arr.append(list(input()))
ans = True
for i in range(n):
if not ans:
break
for j in range(m):
try:
b = 0
g = int(arr[i][j])
if i-1>=0 and j-1>=0 and arr[i-1][j-1]=='*':
b+=1
if i-1>=0 and arr[i-1][j]=='*':
b+=1
if i-... | Title: Minesweeper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by... | ```python
n,m = map(int,input().split())
arr = []
for i in range(n):
arr.append(list(input()))
ans = True
for i in range(n):
if not ans:
break
for j in range(m):
try:
b = 0
g = int(arr[i][j])
if i-1>=0 and j-1>=0 and arr[i-1][j-1]=='*':
b+=1
if i-1>=0 and arr[i-1][j]=='*':
b+=1... | -1 | |
209 | A | Multicolored Marbles | PROGRAMMING | 1,600 | [
"dp",
"math"
] | null | null | Polycarpus plays with red and blue marbles. He put *n* marbles from the left to the right in a row. As it turned out, the marbles form a zebroid.
A non-empty sequence of red and blue marbles is a zebroid, if the colors of the marbles in this sequence alternate. For example, sequences (red; blue; red) and (blue) are ze... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106) — the number of marbles in Polycarpus's sequence. | Print a single number — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"3\n",
"4\n"
] | [
"6\n",
"11\n"
] | Let's consider the first test sample. Let's assume that Polycarpus initially had sequence (red; blue; red), so there are six ways to pick a zebroid:
- pick the first marble; - pick the second marble; - pick the third marble; - pick the first and second marbles; - pick the second and third marbles; - pick the fi... | 500 | [
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "11"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "3"
},
{
"input": "5",
"output": "19"
},
{
"input": "6",
"output": "32"
},
{
"input": "7",
"output": "53"
},... | 1,579,087,666 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 1,278 | 0 | n=int(input())
a,b=0,0
for i in range(n):
if i%2==0:a+=b+1
else:b+=a+1
a,b=a%1000000007,b%1000000007
print((a+b)%1000000007) | Title: Multicolored Marbles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus plays with red and blue marbles. He put *n* marbles from the left to the right in a row. As it turned out, the marbles form a zebroid.
A non-empty sequence of red and blue marbles is a zebroid, if the c... | ```python
n=int(input())
a,b=0,0
for i in range(n):
if i%2==0:a+=b+1
else:b+=a+1
a,b=a%1000000007,b%1000000007
print((a+b)%1000000007)
``` | 3 | |
1,011 | B | Planning The Expedition | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant.
The warehouse has $m$ daily food packages. Each package has some food type $a_i$.
Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat t... | The first line contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 100$) — the number of the expedition participants and the number of the daily food packages available.
The second line contains sequence of integers $a_1, a_2, \dots, a_m$ ($1 \le a_i \le 100$), where $a_i$ is the type of $i$-th food pac... | Print the single integer — the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0. | [
"4 10\n1 5 2 1 1 1 2 5 7 2\n",
"100 1\n1\n",
"2 5\n5 4 3 2 1\n",
"3 9\n42 42 42 42 42 42 42 42 42\n"
] | [
"2\n",
"0\n",
"1\n",
"3\n"
] | In the first example, Natasha can assign type $1$ food to the first participant, the same type $1$ to the second, type $5$ to the third and type $2$ to the fourth. In this case, the expedition can last for $2$ days, since each participant can get two food packages of his food type (there will be used $4$ packages of ty... | 1,000 | [
{
"input": "4 10\n1 5 2 1 1 1 2 5 7 2",
"output": "2"
},
{
"input": "100 1\n1",
"output": "0"
},
{
"input": "2 5\n5 4 3 2 1",
"output": "1"
},
{
"input": "3 9\n42 42 42 42 42 42 42 42 42",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"inp... | 1,580,277,691 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 234 | 2,355,200 | # maa chudaaye duniya
from copy import copy
n, m = map(int, input().split())
arr = [0]*(101)
a = list(map(int, input().split()))
for i in a:
arr[i] += 1
d = 100
f = False
while d >= 1:
cc = copy(arr)
k = 0
for i in range(1, 101) :
while cc[i] >= d:
k += 1
c... | Title: Planning The Expedition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant.
The warehouse has $m$ daily food packages. Each package has some food type $a_i$.
E... | ```python
# maa chudaaye duniya
from copy import copy
n, m = map(int, input().split())
arr = [0]*(101)
a = list(map(int, input().split()))
for i in a:
arr[i] += 1
d = 100
f = False
while d >= 1:
cc = copy(arr)
k = 0
for i in range(1, 101) :
while cc[i] >= d:
k += 1
... | 3 | |
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
... | 1,667,706,596 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 88 | 93 | 11,878,400 | n=int(input())
a=[int(i) for i in input().split()]
m=min(a)
n=max(a)
cnt=0
for z in a:
if m<z<n:
cnt+=1
print(cnt) | Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am... | ```python
n=int(input())
a=[int(i) for i in input().split()]
m=min(a)
n=max(a)
cnt=0
for z in a:
if m<z<n:
cnt+=1
print(cnt)
``` | 3 | |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,697,750,631 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 0 | n = 5
matrix = []
for i in range(n):
matrix.append(list(map(int, input().split())))
recordi = 0
recordj = 0
for i in range(n):
for j in range(n):
if matrix[i][j] == 1:
recordi = i
recordj = j
break
sum = abs(recordi - 2) + abs(recordj - 2)
print(sum... | Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
n = 5
matrix = []
for i in range(n):
matrix.append(list(map(int, input().split())))
recordi = 0
recordj = 0
for i in range(n):
for j in range(n):
if matrix[i][j] == 1:
recordi = i
recordj = j
break
sum = abs(recordi - 2) + abs(recordj - 2)
... | 3 | |
984 | A | Game | PROGRAMMING | 800 | [
"sortings"
] | null | null | Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ... | The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). | Print one number that will be left on the board. | [
"3\n2 1 3\n",
"3\n2 2 2\n"
] | [
"2",
"2"
] | In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | 500 | [
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 2 2",
"output": "2"
},
{
"input": "9\n44 53 51 80 5 27 74 79 94",
"output": "53"
},
{
"input": "10\n38 82 23 37 96 4 81 60 67 86",
"output": "60"
},
{
"input": "10\n58 26 77 15 53 81 68 48 22 65",
"outpu... | 1,560,181,566 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | n=int(input())
num=input().split()
num=[int(num[i]) for i in range(n)]
while len(num)!=1:
num.remove(max(num))
if len(num)>1:
num.remove(min(num))
num[0]=str(num[0])
num="".join(num)
print(num) | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the... | ```python
n=int(input())
num=input().split()
num=[int(num[i]) for i in range(n)]
while len(num)!=1:
num.remove(max(num))
if len(num)>1:
num.remove(min(num))
num[0]=str(num[0])
num="".join(num)
print(num)
``` | 3 | |
363 | A | Soroban | PROGRAMMING | 800 | [
"implementation"
] | null | null | You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban — an abacus developed in Japan. This phenomenon has its reasons, of course, but we are not going to speak about ... | The first line contains a single integer *n* (0<=≤<=*n*<=<<=109). | Print the description of the decimal digits of number *n* from the last one to the first one (as mentioned on the picture in the statement), one per line. Print the beads as large English letters 'O', rod pieces as character '-' and the reckoning bar as '|'. Print as many rods, as many digits are in the decimal represe... | [
"2\n",
"13\n",
"720\n"
] | [
"O-|OO-OO\n",
"O-|OOO-O\nO-|O-OOO\n",
"O-|-OOOO\nO-|OO-OO\n-O|OO-OO\n"
] | none | 500 | [
{
"input": "2",
"output": "O-|OO-OO"
},
{
"input": "13",
"output": "O-|OOO-O\nO-|O-OOO"
},
{
"input": "720",
"output": "O-|-OOOO\nO-|OO-OO\n-O|OO-OO"
},
{
"input": "0",
"output": "O-|-OOOO"
},
{
"input": "1",
"output": "O-|O-OOO"
},
{
"input": "3",
... | 1,677,357,087 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | zero = ['O-|-OOOO','O-|O-OOO','O-|OO-OO','O-|OOO-O','O-|OOOO-','-O|-OOOO','-O|O-OOO','-O|OO-OO','-O|OOO-O','-O|OOOO-']
n = input()
for i in range(len(n),0,-1):
print(zero[int(n[i-1])]) | Title: Soroban
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban — an abacus develop... | ```python
zero = ['O-|-OOOO','O-|O-OOO','O-|OO-OO','O-|OOO-O','O-|OOOO-','-O|-OOOO','-O|O-OOO','-O|OO-OO','-O|OOO-O','-O|OOOO-']
n = input()
for i in range(len(n),0,-1):
print(zero[int(n[i-1])])
``` | 3 | |
600 | C | Make Palindrome | PROGRAMMING | 1,800 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.
You are given string *s* consisting of lowercase Latin letters. At once you can choose any position in ... | The only line contains string *s* (1<=≤<=|*s*|<=≤<=2·105) consisting of only lowercase Latin letters. | Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes. | [
"aabc\n",
"aabcd\n"
] | [
"abba\n",
"abcba\n"
] | none | 0 | [
{
"input": "aabc",
"output": "abba"
},
{
"input": "aabcd",
"output": "abcba"
},
{
"input": "u",
"output": "u"
},
{
"input": "ttttt",
"output": "ttttt"
},
{
"input": "xxxvvvxxvv",
"output": "vvvxxxxvvv"
},
{
"input": "wrwrwfrrfrffrrwwwffffwrfrrwfrrfrwwf... | 1,614,226,984 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 14 | 171 | 9,728,000 | from collections import deque
# palindrome all letter sums must be even and 0 or 1 odd sum allowed
s = input()
cnt = [0]*26
for letter in s:
cnt[ord(letter) - ord('a')] += 1
# find number of odd counts
odd = []
for letter in range(26):
if cnt[letter] % 2:
odd.append(letter)
# swap odds (all if even or l... | Title: Make Palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.
Yo... | ```python
from collections import deque
# palindrome all letter sums must be even and 0 or 1 odd sum allowed
s = input()
cnt = [0]*26
for letter in s:
cnt[ord(letter) - ord('a')] += 1
# find number of odd counts
odd = []
for letter in range(26):
if cnt[letter] % 2:
odd.append(letter)
# swap odds (all if... | 0 | |
361 | A | Levko and Table | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them. | [
"2 4\n",
"4 7\n"
] | [
"1 3\n3 1\n",
"2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n"
] | In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other table... | 500 | [
{
"input": "2 4",
"output": "4 0 \n0 4 "
},
{
"input": "4 7",
"output": "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 "
},
{
"input": "1 8",
"output": "8 "
},
{
"input": "9 3",
"output": "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0... | 1,561,230,639 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 109 | 0 | """from numpy import *
a,b=map(int,input().split())
arr=zeros([a,a],dtype=int)
for i in range(a):
for j in range(a):
if i==j:
arr[i][j]=b
for x in arr:
print(*x)
"""
n,k=map(int,input().split())
for i in range(n):
print(i*'0 ',end='')
print(k,end='')
print((n-1... | Title: Levko and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortun... | ```python
"""from numpy import *
a,b=map(int,input().split())
arr=zeros([a,a],dtype=int)
for i in range(a):
for j in range(a):
if i==j:
arr[i][j]=b
for x in arr:
print(*x)
"""
n,k=map(int,input().split())
for i in range(n):
print(i*'0 ',end='')
print(k,end='')
... | 3 | |
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul... | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter t... | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input":... | 1,664,038,163 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | orders = {'A':0, 'B': 0, 'C':0}
for i in range(3):
order = input()
if (order[1] == '<'):
orders[order[2]] += 1
else:
orders[order[0]] += 1
sortedOrders = sorted(orders, key= orders.get)
result = ''.join(sortedOrders)
print(result) | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ... | ```python
orders = {'A':0, 'B': 0, 'C':0}
for i in range(3):
order = input()
if (order[1] == '<'):
orders[order[2]] += 1
else:
orders[order[0]] += 1
sortedOrders = sorted(orders, key= orders.get)
result = ''.join(sortedOrders)
print(result)
``` | 0 |
768 | B | Code For 1 | PROGRAMMING | 1,600 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer"
] | null | null | Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s... | The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=<<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*.
It is guaranteed that *r* is not greater than the length of the final list. | Output the total number of 1s in the range *l* to *r* in the final sequence. | [
"7 2 5\n",
"10 3 10\n"
] | [
"4\n",
"5\n"
] | Consider first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.
For the second example:
<img al... | 1,000 | [
{
"input": "7 2 5",
"output": "4"
},
{
"input": "10 3 10",
"output": "5"
},
{
"input": "56 18 40",
"output": "20"
},
{
"input": "203 40 124",
"output": "67"
},
{
"input": "903316762502 354723010040 354723105411",
"output": "78355"
},
{
"input": "335343... | 1,697,986,077 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n, l, r = map(int, input().split())
def f(x):
if x <= 1:
return [x]
else:
left = int(x / 2)
mid = x % 2
right = int(x / 2)
left = f(left)
mid = f(mid)
right = f(right)
return left + mid + right
print(f(n).count(1)) | Title: Code For 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and ta... | ```python
n, l, r = map(int, input().split())
def f(x):
if x <= 1:
return [x]
else:
left = int(x / 2)
mid = x % 2
right = int(x / 2)
left = f(left)
mid = f(mid)
right = f(right)
return left + mid + right
print(f(n).count(1))
`... | 0 | |
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police offi... | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ... | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c... | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ... | 1,676,102,655 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | a=int(input())
d=list(map(int,input().split()))
s=0
j=0
for i in range(len(d)):
s=s+d[i]
if s<0:
j=j+1
else:
j=2
print(j-1)
| Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of... | ```python
a=int(input())
d=list(map(int,input().split()))
s=0
j=0
for i in range(len(d)):
s=s+d[i]
if s<0:
j=j+1
else:
j=2
print(j-1)
``` | 0 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,698,901,446 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | n, k = map(int, input().split())
participation_counts = list(map(int, input().split()))
already_participated = sum(1 for count in participation_counts if count >= k)
can_participate_more = sum(1 for count in participation_counts if count < k and count + (5 - k) >= k)
teams_with_already_participated = already_pa... | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n, k = map(int, input().split())
participation_counts = list(map(int, input().split()))
already_participated = sum(1 for count in participation_counts if count >= k)
can_participate_more = sum(1 for count in participation_counts if count < k and count + (5 - k) >= k)
teams_with_already_participated = ... | 0 | |
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXY... | 1,698,949,561 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 59 | 62 | 0 | def main():
# Reading multiple test cases
n = int(input())
word = input().strip().lower() # string values
if len(set(word)) == 26:
print("YES")
else:
print("NO")
if __name__ == "__main__":
main() | Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
... | ```python
def main():
# Reading multiple test cases
n = int(input())
word = input().strip().lower() # string values
if len(set(word)) == 26:
print("YES")
else:
print("NO")
if __name__ == "__main__":
main()
``` | 3 | |
259 | B | Little Elephant and Magic Square | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals ... | The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented... | Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditio... | [
"0 1 1\n1 0 1\n1 1 0\n",
"0 3 6\n5 0 5\n4 7 0\n"
] | [
"1 1 1\n1 1 1\n1 1 1\n",
"6 3 6\n5 5 5\n4 7 4\n"
] | none | 1,000 | [
{
"input": "0 1 1\n1 0 1\n1 1 0",
"output": "1 1 1\n1 1 1\n1 1 1"
},
{
"input": "0 3 6\n5 0 5\n4 7 0",
"output": "6 3 6\n5 5 5\n4 7 4"
},
{
"input": "0 4 4\n4 0 4\n4 4 0",
"output": "4 4 4\n4 4 4\n4 4 4"
},
{
"input": "0 54 48\n36 0 78\n66 60 0",
"output": "69 54 48\n36 5... | 1,624,362,917 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | def solve(f , s , t):
f_tot , s_tot , t_tot = sum(f) , sum(s) , sum(t)
get = (f_tot + s_tot + t_tot) // 2
f[0] , s[1] , t[2] = get - f_tot , get - s_tot , get - t_tot
print(f)
print(s)
print(t)
return
f = list(map(int,input().split()))
s = list(map(int,input().split()))
t =... | Title: Little Elephant and Magic Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table ... | ```python
def solve(f , s , t):
f_tot , s_tot , t_tot = sum(f) , sum(s) , sum(t)
get = (f_tot + s_tot + t_tot) // 2
f[0] , s[1] , t[2] = get - f_tot , get - s_tot , get - t_tot
print(f)
print(s)
print(t)
return
f = list(map(int,input().split()))
s = list(map(int,input().spli... | 0 | |
445 | A | DZY Loves Chessboard | PROGRAMMING | 1,200 | [
"dfs and similar",
"implementation"
] | null | null | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ... | Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It ... | [
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] | [
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | 500 | [
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n--------... | 1,615,035,231 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 109 | 1,740,800 | n,m=map(int,input().split())
l=[]
for _ in range(n):
l.append(list(input()))
for i in range(n):
for j in range(m):
if l[i][j]=='.':
if (i+j)%2==0:
l[i][j]='B'
else:
l[i][j]='W'
for _ in l:
print(''.join(_))
| Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ... | ```python
n,m=map(int,input().split())
l=[]
for _ in range(n):
l.append(list(input()))
for i in range(n):
for j in range(m):
if l[i][j]=='.':
if (i+j)%2==0:
l[i][j]='B'
else:
l[i][j]='W'
for _ in l:
print(''.join(_))
``` | 3 | |
559 | B | Equivalent Strings | PROGRAMMING | 1,700 | [
"divide and conquer",
"hashing",
"sortings",
"strings"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 1,000 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,541,963,556 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | def smallest(x):
if len(x) % 2:
return x
s1 = smallest(x[:len(x)/2])
s2 = smallest(x[len(x)/2])
if s1 < s2:
return s1 + s2
else:
return s2 + s1
def are_equiv(x, y):
if smallest(x) == smallest(y):
return "YES"
else:
return "NO"
print(a... | Title: Equivalent Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split str... | ```python
def smallest(x):
if len(x) % 2:
return x
s1 = smallest(x[:len(x)/2])
s2 = smallest(x[len(x)/2])
if s1 < s2:
return s1 + s2
else:
return s2 + s1
def are_equiv(x, y):
if smallest(x) == smallest(y):
return "YES"
else:
return "NO"
... | -1 | |
899 | B | Months and Years | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.
... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=24) — the number of integers.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (28<=≤<=*a**i*<=≤<=31) — the numbers you are to check. | If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in arbitrary case (small or large). | [
"4\n31 31 30 31\n",
"2\n30 30\n",
"5\n29 31 30 31 30\n",
"3\n31 28 30\n",
"3\n31 31 28\n"
] | [
"Yes\n\n",
"No\n\n",
"Yes\n\n",
"No\n\n",
"Yes\n\n"
] | In the first example the integers can denote months July, August, September and October.
In the second example the answer is no, because there are no two consecutive months each having 30 days.
In the third example the months are: February (leap year) — March — April – May — June.
In the fourth example the number of... | 1,000 | [
{
"input": "4\n31 31 30 31",
"output": "Yes"
},
{
"input": "2\n30 30",
"output": "No"
},
{
"input": "5\n29 31 30 31 30",
"output": "Yes"
},
{
"input": "3\n31 28 30",
"output": "No"
},
{
"input": "3\n31 31 28",
"output": "Yes"
},
{
"input": "24\n29 28 3... | 1,513,902,379 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 77 | 5,632,000 | n=int(input())
line=input().split(' ')
line=[int(i) for i in line]
b1=[31,28,31,30,31,30,31,31,30,31,30,31]
b2=[31,29,31,30,31,30,31,31,30,31,30,31]
b=b1*3+b2+b1*3
s=0
for i in range(0,84):
if line==b[i:i+n]:
s=1
if s==1:
print('Yes',end='')
print('\n')
else:
print('No',end='')
... | Title: Months and Years
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, ... | ```python
n=int(input())
line=input().split(' ')
line=[int(i) for i in line]
b1=[31,28,31,30,31,30,31,31,30,31,30,31]
b2=[31,29,31,30,31,30,31,31,30,31,30,31]
b=b1*3+b2+b1*3
s=0
for i in range(0,84):
if line==b[i:i+n]:
s=1
if s==1:
print('Yes',end='')
print('\n')
else:
print('No',e... | 3 | |
554 | A | Kyoya and Photobooks | PROGRAMMING | 900 | [
"brute force",
"math",
"strings"
] | null | null | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters. | Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. | [
"a\n",
"hi\n"
] | [
"51\n",
"76\n"
] | In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | 250 | [
{
"input": "a",
"output": "51"
},
{
"input": "hi",
"output": "76"
},
{
"input": "y",
"output": "51"
},
{
"input": "kgan",
"output": "126"
},
{
"input": "zoabkyuvus",
"output": "276"
},
{
"input": "spyemhyznjieyhhbk",
"output": "451"
},
{
"i... | 1,620,304,024 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 6,963,200 | import itertools
import math
def repetations(l1):
s1=set(l1)
prod=1
for i in s1:
prod*=math.factorial(l1.count(i))
return prod
st=input()
l1=list(st)
base=97
ans=0
numer=len(st)+1
for i in range(base,123):
l1.append(chr(i))
co=len(list(itertools.permutations(l1,2)))
... | Title: Kyoya and Photobooks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos b... | ```python
import itertools
import math
def repetations(l1):
s1=set(l1)
prod=1
for i in s1:
prod*=math.factorial(l1.count(i))
return prod
st=input()
l1=list(st)
base=97
ans=0
numer=len(st)+1
for i in range(base,123):
l1.append(chr(i))
co=len(list(itertools.permutations(l1... | 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,591,747,154 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 186 | 307,200 | n = int(input())
l = list(map(int, input().split()))
m = int(input())
for i in range(m):
a, b = map(int, input().split())
if(a!=1):
l[a-2] += l[a-1]-(l[a-1]-b+1)
l[a] += l[a-1]-b
l[a-1] = 0
elif(a==1):
l[a] += l[a-1]-b
l[a-1]=0
for i in l:
print(i... | 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
n = int(input())
l = list(map(int, input().split()))
m = int(input())
for i in range(m):
a, b = map(int, input().split())
if(a!=1):
l[a-2] += l[a-1]-(l[a-1]-b+1)
l[a] += l[a-1]-b
l[a-1] = 0
elif(a==1):
l[a] += l[a-1]-b
l[a-1]=0
for i in l:
... | -1 | |
215 | A | Bicycle Chain | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the *i*-th star on the pedal axle has *a**i* (0<=<<=*a*1<=<<=*a*2<=<<=...<=<<... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing.
The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars o... | Print the number of "integer" gears with the maximum ratio among all "integer" gears. | [
"2\n4 5\n3\n12 13 15\n",
"4\n1 2 3 4\n5\n10 11 12 13 14\n"
] | [
"2\n",
"1\n"
] | In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15. | 500 | [
{
"input": "2\n4 5\n3\n12 13 15",
"output": "2"
},
{
"input": "4\n1 2 3 4\n5\n10 11 12 13 14",
"output": "1"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 2\n1\n1",
"output": "1"
},
{
"input": "1\n1\n2\n1 2",
"output": "1"
},
{
"input":... | 1,590,691,447 | 2,147,483,647 | PyPy 3 | OK | TESTS | 57 | 280 | 1,331,200 | #A. Bicycle Chain
n = int(input())
a = list(map(int,input().split()))
m = int(input())
b = list(map(int,input().split()))
t = 0
max_ = 0
for i in a:
for j in b:
if j%i==0:
if j//i > max_:
t = 1
max_ = j//i
elif j//i == max_:
... | Title: Bicycle Chain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We ... | ```python
#A. Bicycle Chain
n = int(input())
a = list(map(int,input().split()))
m = int(input())
b = list(map(int,input().split()))
t = 0
max_ = 0
for i in a:
for j in b:
if j%i==0:
if j//i > max_:
t = 1
max_ = j//i
elif j//i == max_:
... | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.