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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
622 | A | Infinite Sequence | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains ... | The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find.
Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | Print the element in the *n*-th position of the sequence (the elements are numerated from one). | [
"3\n",
"5\n",
"10\n",
"55\n",
"56\n"
] | [
"2\n",
"2\n",
"4\n",
"10\n",
"1\n"
] | none | 0 | [
{
"input": "3",
"output": "2"
},
{
"input": "5",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "55",
"output": "10"
},
{
"input": "56",
"output": "1"
},
{
"input": "1000000000000",
"output": "88209"
},
{
"input": "8471941278... | 1,621,065,730 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 124 | 0 | n=int(input())
i1=int(pow((2*n+0.25),0.5)-0.5)
if(int((i1*(i1+1))/2)==n):
print(i1)
elif(int((i1*(i1+1))/2)<n):
print(n-int((i1*(i1+1))/2))
| Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2,... | ```python
n=int(input())
i1=int(pow((2*n+0.25),0.5)-0.5)
if(int((i1*(i1+1))/2)==n):
print(i1)
elif(int((i1*(i1+1))/2)<n):
print(n-int((i1*(i1+1))/2))
``` | 3 | |
462 | B | Appleman and Card Game | PROGRAMMING | 1,300 | [
"greedy"
] | null | null | Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to lette... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman. | Print a single integer – the answer to the problem. | [
"15 10\nDZFDFZDFDDDDDDF\n",
"6 4\nYJSNPI\n"
] | [
"82\n",
"4\n"
] | In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin. | 1,000 | [
{
"input": "15 10\nDZFDFZDFDDDDDDF",
"output": "82"
},
{
"input": "6 4\nYJSNPI",
"output": "4"
},
{
"input": "5 3\nAOWBY",
"output": "3"
},
{
"input": "1 1\nV",
"output": "1"
},
{
"input": "2 1\nWT",
"output": "1"
},
{
"input": "2 2\nBL",
"output":... | 1,580,154,332 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 155 | 0 | from collections import *
n, k = map(int, input().split())
s, ans = Counter(input()), 0
for i, j in s.items():
if k <= 0:
break
ans += min(k, j) * min(k, j)
k -= j
print(ans) | Title: Appleman and Card Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally... | ```python
from collections import *
n, k = map(int, input().split())
s, ans = Counter(input()), 0
for i, j in s.items():
if k <= 0:
break
ans += min(k, j) * min(k, j)
k -= j
print(ans)
``` | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,589,758,271 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 80 | 218 | 6,656,000 | n = int(input())
total = 0
for i in range(n):
a = [int(i) for i in input().split()]
total+=(sum(a))
if total == 0:
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
total = 0
for i in range(n):
a = [int(i) for i in input().split()]
total+=(sum(a))
if total == 0:
print("YES")
else:
print("NO")
``` | 0 |
44 | H | Phone Number | PROGRAMMING | 1,700 | [
"dp"
] | H. Phone Number | 2 | 256 | Alas, finding one's true love is not easy. Masha has been unsuccessful in that yet. Her friend Dasha told Masha about a way to determine the phone number of one's Prince Charming through arithmancy.
The phone number is divined like that. First one needs to write down one's own phone numbers. For example, let's suppos... | The first line contains nonempty sequence consisting of digits from 0 to 9 — Masha's phone number. The sequence length does not exceed 50. | Output the single number — the number of phone numbers Masha will dial. | [
"12345\n",
"09\n"
] | [
"48\n",
"15\n"
] | none | 0 | [
{
"input": "12345",
"output": "48"
},
{
"input": "09",
"output": "15"
},
{
"input": "3",
"output": "9"
},
{
"input": "55",
"output": "14"
},
{
"input": "737",
"output": "23"
},
{
"input": "21583",
"output": "55"
},
{
"input": "33408349",
... | 1,658,305,308 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | s = list(input())
n, nums = len(s), [int(i) for i in s]
def f(idx, val):
if idx == n:
return 1
cur = nums[idx]
if (cur + val) % 2 == 0:
ans = f(idx + 1, (cur + val) // 2)
else:
ans = f(idx + 1, (cur + val) // 2) + f(idx + 1, (cur + val) // 2 + 1)
return ans
... | Title: Phone Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Alas, finding one's true love is not easy. Masha has been unsuccessful in that yet. Her friend Dasha told Masha about a way to determine the phone number of one's Prince Charming through arithmancy.
The phone number is divin... | ```python
s = list(input())
n, nums = len(s), [int(i) for i in s]
def f(idx, val):
if idx == n:
return 1
cur = nums[idx]
if (cur + val) % 2 == 0:
ans = f(idx + 1, (cur + val) // 2)
else:
ans = f(idx + 1, (cur + val) // 2) + f(idx + 1, (cur + val) // 2 + 1)
retur... | 0 |
387 | B | George and Round | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"two pointers"
] | null | null | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirem... | Print a single integer — the answer to the problem. | [
"3 5\n1 2 3\n1 2 2 3 3\n",
"3 5\n1 2 3\n1 1 1 1 1\n",
"3 1\n2 3 4\n1\n"
] | [
"0\n",
"2\n",
"3\n"
] | In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems wi... | 1,000 | [
{
"input": "3 5\n1 2 3\n1 2 2 3 3",
"output": "0"
},
{
"input": "3 5\n1 2 3\n1 1 1 1 1",
"output": "2"
},
{
"input": "3 1\n2 3 4\n1",
"output": "3"
},
{
"input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 97... | 1,607,939,527 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 93 | 614,400 | n,m= map(int, input().split())
a= list(map(int, input().split()))
b= list(map(int, input().split()))
i=j=0
while i<n and j<m:
if a[i]<=b[j]:
i+=1
j+=1
print(n-i) | Title: George and Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
T... | ```python
n,m= map(int, input().split())
a= list(map(int, input().split()))
b= list(map(int, input().split()))
i=j=0
while i<n and j<m:
if a[i]<=b[j]:
i+=1
j+=1
print(n-i)
``` | 3 | |
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first positi... | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4... | 1,596,968,236 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 140 | 6,963,200 | n = int(input())
a = list(map(int, input().split()))
rating = []
for j in range(n):
rating.append(a[j])
rating.sort()
rating.reverse()
contest = []
for i in range(n):
contest.append(rating.index(a[i]) + 1)
print(*contest) | Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the star... | ```python
n = int(input())
a = list(map(int, input().split()))
rating = []
for j in range(n):
rating.append(a[j])
rating.sort()
rating.reverse()
contest = []
for i in range(n):
contest.append(rating.index(a[i]) + 1)
print(*contest)
``` | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,405,857,873 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 154 | 307,200 | from string import ascii_uppercase as u
a=input()
b=0
for i in a:
if i in u:b+=1
if 2*b>len(a):print(a.upper())
else:print(a.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
from string import ascii_uppercase as u
a=input()
b=0
for i in a:
if i in u:b+=1
if 2*b>len(a):print(a.upper())
else:print(a.lower())
``` | 3.960928 |
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat... | The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one ... | Print one integer number — the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5... | 1,516,439,000 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 77 | 5,632,000 | n,k=map(int,input().split())
a=list(map(int,input().split()))
m=k
for i in range(len(a)):
if k%a[i]==0 and k//a[i]<=m:
m=k//a[i]
print(m) | Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each ... | ```python
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=k
for i in range(len(a)):
if k%a[i]==0 and k//a[i]<=m:
m=k//a[i]
print(m)
``` | 3 | |
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s... | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch... | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 ... | 1,665,777,507 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n, d = [int(i) for i in input().split()]
a = list(map(int,input().split()))
if(n*10 == d):
b = int((d-sum(a))/5)
print(b)
else:
print(-1)
| Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit... | ```python
n, d = [int(i) for i in input().split()]
a = list(map(int,input().split()))
if(n*10 == d):
b = int((d-sum(a))/5)
print(b)
else:
print(-1)
``` | 0 | |
501 | B | Misha and Changing Handles | PROGRAMMING | 1,100 | [
"data structures",
"dsu",
"strings"
] | null | null | Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the re... | The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests.
Next *q* lines contain the descriptions of the requests, one per line.
Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and di... | In the first line output the integer *n* — the number of users that changed their handles at least once.
In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*,... | [
"5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n"
] | [
"3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n"
] | none | 500 | [
{
"input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov",
"output": "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123"
},
{
"input": "1\nMisha Vasya",
"output": "1\nMisha Vasya"
},
{
"input": "10\na b\nb c\nc d\nd... | 1,543,879,092 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 140 | 614,400 | import fileinput
data = []
with fileinput.input() as f:
for line in f:
data.append(line.strip())
graph = {}
names = []
names2 = []
for i in range(1, len(data)):
names.append(data[i].split(' ')[0])
names2.append(data[i].split(' ')[1])
graph[data[i].split(' ')[0]] = (data[i].split(' ')[1], None... | Title: Misha and Changing Handles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is a... | ```python
import fileinput
data = []
with fileinput.input() as f:
for line in f:
data.append(line.strip())
graph = {}
names = []
names2 = []
for i in range(1, len(data)):
names.append(data[i].split(' ')[0])
names2.append(data[i].split(' ')[1])
graph[data[i].split(' ')[0]] = (data[i].split(' '... | 3 | |
412 | A | Poster | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.
The slogan of the company consists of *n* characters, so the decorators hung a l... | The first line contains two integers, *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as *n* characters written without spaces. Each character of the slogan is either a large English letter, or di... | In *t* lines, print the actions the programmers need to make. In the *i*-th line print:
- "LEFT" (without the quotes), if the *i*-th action was "move the ladder to the left"; - "RIGHT" (without the quotes), if the *i*-th action was "move the ladder to the right"; - "PRINT *x*" (without the quotes), if the *i*-th ac... | [
"2 2\nR1\n",
"2 1\nR1\n",
"6 4\nGO?GO!\n"
] | [
"PRINT 1\nLEFT\nPRINT R\n",
"PRINT R\nRIGHT\nPRINT 1\n",
"RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G\n"
] | Note that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character. | 500 | [
{
"input": "2 2\nR1",
"output": "PRINT 1\nLEFT\nPRINT R"
},
{
"input": "2 1\nR1",
"output": "PRINT R\nRIGHT\nPRINT 1"
},
{
"input": "6 4\nGO?GO!",
"output": "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"
},
{
"input": "7 3\n... | 1,448,300,759 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 77 | 0 | n, k = map(int, input().split())
k, s = k - 1, input()
print('PRINT', s[k])
if k <= n - k - 1:
for i in range(k - 1, -1, -1):
print('LEFT')
print('PRINT', s[i])
for i in range(k):
print('RIGHT')
for i in range(k + 1, n):
print('RIGHT')
print('PRINT', s[i])
... | Title: Poster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the... | ```python
n, k = map(int, input().split())
k, s = k - 1, input()
print('PRINT', s[k])
if k <= n - k - 1:
for i in range(k - 1, -1, -1):
print('LEFT')
print('PRINT', s[i])
for i in range(k):
print('RIGHT')
for i in range(k + 1, n):
print('RIGHT')
print('PRIN... | 3 | |
364 | D | Ghd | PROGRAMMING | 2,900 | [
"brute force",
"math",
"probabilities"
] | null | null | John Doe offered his sister Jane Doe find the gcd of some set of numbers *a*.
Gcd is a positive integer *g*, such that all number from the set are evenly divisible by *g* and there isn't such *g*' (*g*'<=><=*g*), that all numbers of the set are evenly divisible by *g*'.
Unfortunately Jane couldn't cope with the ta... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) showing how many numbers are in set *a*. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1012). Please note, that given set can contain equal numbers.
Please, do not write the %lld specifier to read or write 64-bi... | Print a single integer *g* — the Ghd of set *a*. | [
"6\n6 2 3 4 5 6\n",
"5\n5 5 6 10 15\n"
] | [
"3\n",
"5\n"
] | none | 2,000 | [
{
"input": "6\n6 2 3 4 5 6",
"output": "3"
},
{
"input": "5\n5 5 6 10 15",
"output": "5"
},
{
"input": "100\n32 40 7 3 7560 21 7560 7560 10 12 3 7560 7560 7560 7560 5 7560 7560 6 7560 7560 7560 35 7560 18 7560 7560 7560 7560 7560 48 2 7 25 7560 2 2 49 7560 7560 15 16 7560 7560 2 7560 27 ... | 1,581,753,156 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 2,252,800 | def read_integers():
return list(map(int, stdin.readline().strip().split()))
_, = read_integers()
input_arr = read_integers()
print(input_arr) | Title: Ghd
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
John Doe offered his sister Jane Doe find the gcd of some set of numbers *a*.
Gcd is a positive integer *g*, such that all number from the set are evenly divisible by *g* and there isn't such *g*' (*g*'<=><=*g*), that all numbe... | ```python
def read_integers():
return list(map(int, stdin.readline().strip().split()))
_, = read_integers()
input_arr = read_integers()
print(input_arr)
``` | -1 | |
30 | B | Codeforces World Finals | PROGRAMMING | 1,700 | [
"implementation"
] | B. Codeforces World Finals | 2 | 256 | The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa understood that to conquer the world he needs to organize the world Codeforces tournament. He hopes that a... | The first line contains the date *DD*.*MM*.*YY*, the second line contains the date *BD*.*BM*.*BY*. It is guaranteed that both dates are correct, and *YY* and *BY* are always in [01;99].
It could be that by passport Bob was born after the finals. In this case, he can still change the order of numbers in date. | If it is possible to rearrange the numbers in the date of birth so that Bob will be at least 18 years old on the *DD*.*MM*.*YY*, output YES. In the other case, output NO.
Each number contains exactly two digits and stands for day, month or year in a date. Note that it is permitted to rearrange only numbers, not digit... | [
"01.01.98\n01.01.80\n",
"20.10.20\n10.02.30\n",
"28.02.74\n28.02.64\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 1,000 | [
{
"input": "01.01.98\n01.01.80",
"output": "YES"
},
{
"input": "20.10.20\n10.02.30",
"output": "NO"
},
{
"input": "28.02.74\n28.02.64",
"output": "NO"
},
{
"input": "05.05.25\n06.02.71",
"output": "NO"
},
{
"input": "19.11.54\n29.11.53",
"output": "NO"
},
... | 1,539,877,815 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 62 | 248 | 0 | d,m,y = map(int,input().split('.'))
a,b,c = map(int,input().split('.'))
months = [0,31,28,31,30,31,30,31,31,30,31,30,31]
count = 0
while(count <6):
if b < c and c in range(13) and months[c] >= a + (b%4 == 0 and b ==2) :
temp = b
b = c
c = temp
count = 0
else: count += 1
if ... | Title: Codeforces World Finals
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa u... | ```python
d,m,y = map(int,input().split('.'))
a,b,c = map(int,input().split('.'))
months = [0,31,28,31,30,31,30,31,31,30,31,30,31]
count = 0
while(count <6):
if b < c and c in range(13) and months[c] >= a + (b%4 == 0 and b ==2) :
temp = b
b = c
c = temp
count = 0
else: count +=... | 0 |
888 | A | Local Extrema | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=<<=*a**i*<=-<=1 and *a**i*<=<<=*a**i*<=+<=1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, *a**i*<=><=*... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in array *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000) — the elements of array *a*. | Print the number of local extrema in the given array. | [
"3\n1 2 3\n",
"4\n1 5 2 5\n"
] | [
"0\n",
"2\n"
] | none | 0 | [
{
"input": "3\n1 2 3",
"output": "0"
},
{
"input": "4\n1 5 2 5",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n548",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "3\n3 2 3",
"output": "1"
},
{
"inp... | 1,514,335,351 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 62 | 5,632,000 | num = int(input())
a = input()
a = a.split()
for i in range(len(a)): a[i] = int(a[i])
n=0
for i in range(1,len(a)-1):
if a[i] < a[i-1] and a[i]<a[i+1]: n+=1
elif a[i] > a[i-1] and a[i]> a[i+1]: n+=1
print (n
)
| Title: Local Extrema
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=<<=*a**i*<=-<=1 and *a**i*<=<<=*a**i*<=+<=1). Also the element c... | ```python
num = int(input())
a = input()
a = a.split()
for i in range(len(a)): a[i] = int(a[i])
n=0
for i in range(1,len(a)-1):
if a[i] < a[i-1] and a[i]<a[i+1]: n+=1
elif a[i] > a[i-1] and a[i]> a[i+1]: n+=1
print (n
)
``` | 3 | |
264 | A | Escape from Stones | PROGRAMMING | 1,200 | [
"constructive algorithms",
"data structures",
"implementation",
"two pointers"
] | null | null | Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the stones. The stones are numbered from 1 to *n* in order.
The stones always fall to the center of Liss's ... | The input consists of only one line. The only line contains the string *s* (1<=≤<=|*s*|<=≤<=106). Each character in *s* will be either "l" or "r". | Output *n* lines — on the *i*-th line you should print the *i*-th stone's number from the left. | [
"llrlr\n",
"rrlll\n",
"lrlrr\n"
] | [
"3\n5\n4\n2\n1\n",
"1\n2\n5\n4\n3\n",
"2\n4\n5\n3\n1\n"
] | In the first example, the positions of stones 1, 2, 3, 4, 5 will be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/58fdb5684df807bfcb705a9da9ce175613362b7d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, respectively. So you should print the sequence: 3, 5, 4, 2, 1. | 500 | [
{
"input": "llrlr",
"output": "3\n5\n4\n2\n1"
},
{
"input": "rrlll",
"output": "1\n2\n5\n4\n3"
},
{
"input": "lrlrr",
"output": "2\n4\n5\n3\n1"
},
{
"input": "lllrlrllrl",
"output": "4\n6\n9\n10\n8\n7\n5\n3\n2\n1"
},
{
"input": "llrlrrrlrr",
"output": "3\n5\n6... | 1,620,892,713 | 2,147,483,647 | PyPy 3 | OK | TESTS | 57 | 1,107 | 68,096,000 | s = input()
l, r = 0, len(s) - 1
a = [None] * len(s)
for i, c in enumerate(s, 1):
if c == 'l':
a[r] = i
r -= 1
else:
a[l] = i
l += 1
print(*a, sep='\n')
| Title: Escape from Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the ... | ```python
s = input()
l, r = 0, len(s) - 1
a = [None] * len(s)
for i, c in enumerate(s, 1):
if c == 'l':
a[r] = i
r -= 1
else:
a[l] = i
l += 1
print(*a, sep='\n')
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters.
Each club's full name consist of two wo... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of clubs in the league.
Each of the next *n* lines contains two words — the team's name and the hometown's name for some club. Both team's name and hometown's name consist of uppercase English letters and have length at least 3 and at most ... | It it is not possible to choose short names and satisfy all constraints, print a single line "NO".
Otherwise, in the first line print "YES". Then print *n* lines, in each line print the chosen short name for the corresponding club. Print the clubs in the same order as they appeared in input.
If there are multiple ans... | [
"2\nDINAMO BYTECITY\nFOOTBALL MOSCOW\n",
"2\nDINAMO BYTECITY\nDINAMO BITECITY\n",
"3\nPLAYFOOTBALL MOSCOW\nPLAYVOLLEYBALL SPB\nGOGO TECHNOCUP\n",
"3\nABC DEF\nABC EFG\nABD OOO\n"
] | [
"YES\nDIN\nFOO\n",
"NO\n",
"YES\nPLM\nPLS\nGOG\n",
"YES\nABD\nABE\nABO\n"
] | In the first sample Innokenty can choose first option for both clubs.
In the second example it is not possible to choose short names, because it is not possible that one club has first option, and the other has second option if the first options are equal for both clubs.
In the third example Innokenty can choose the ... | 0 | [
{
"input": "2\nDINAMO BYTECITY\nFOOTBALL MOSCOW",
"output": "YES\nDIN\nFOO"
},
{
"input": "2\nDINAMO BYTECITY\nDINAMO BITECITY",
"output": "NO"
},
{
"input": "3\nPLAYFOOTBALL MOSCOW\nPLAYVOLLEYBALL SPB\nGOGO TECHNOCUP",
"output": "YES\nPLM\nPLS\nGOG"
},
{
"input": "3\nABC DEF... | 1,488,721,916 | 2,816 | PyPy 3 | WRONG_ANSWER | PRETESTS | 15 | 171 | 23,654,400 | from collections import defaultdict
def main():
n = int(input())
name_map = defaultdict(list)
teams = []
for i in range(n):
club, city = input().split()
teams.append((club, city))
name_map[club[:3]].append((club, city))
shorts = {}
used = []
for s... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wan... | ```python
from collections import defaultdict
def main():
n = int(input())
name_map = defaultdict(list)
teams = []
for i in range(n):
club, city = input().split()
teams.append((club, city))
name_map[club[:3]].append((club, city))
shorts = {}
used = []
... | 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,695,464,804 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | n=(int)(input())
lucky_count=0
while(n>0):
if(n%10==4 or n%10==7):
lucky_count+=1
n//=10
flag=True
while(lucky_count>0):
if(lucky_count%10!=4 and lucky_count%10!= 7):
flag=False
break
lucky_count//=10
if(flag):
print("YES")
else:
print("NO") | 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
n=(int)(input())
lucky_count=0
while(n>0):
if(n%10==4 or n%10==7):
lucky_count+=1
n//=10
flag=True
while(lucky_count>0):
if(lucky_count%10!=4 and lucky_count%10!= 7):
flag=False
break
lucky_count//=10
if(flag):
print("YES")
else:
print("NO")
`... | 0 |
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (withou... | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa... | 1,688,308,301 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | n = int(input())
faces = 0
tetrahedron = "Tetrahedron"
cube = "Cube"
octahedron = "Octahedron"
dodecahedron = "Dodecahedron"
icosahedron = "Icosahedron"
for i in range(n):
polyhedron = input()
if polyhedron == tetrahedron:
faces += 4
elif polyhedron == cube:
faces += 6
... | Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe... | ```python
n = int(input())
faces = 0
tetrahedron = "Tetrahedron"
cube = "Cube"
octahedron = "Octahedron"
dodecahedron = "Dodecahedron"
icosahedron = "Icosahedron"
for i in range(n):
polyhedron = input()
if polyhedron == tetrahedron:
faces += 4
elif polyhedron == cube:
faces... | 3 | |
205 | A | Little Elephant and Rozdil | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider t... | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | [
"2\n7 4\n",
"7\n7 4 47 100 4 9 12\n"
] | [
"2\n",
"Still Rozdil\n"
] | In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling t... | 500 | [
{
"input": "2\n7 4",
"output": "2"
},
{
"input": "7\n7 4 47 100 4 9 12",
"output": "Still Rozdil"
},
{
"input": "1\n47",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "Still Rozdil"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "7"
},
{
... | 1,633,178,769 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 186 | 15,052,800 | input()
a = [int(ele) for ele in input().split()]
l = min(a)
if(a.count(l) > 1):
print("Still Rozdil")
else:
print(a.index(l)+1) | Title: Little Elephant and Rozdil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elepha... | ```python
input()
a = [int(ele) for ele in input().split()]
l = min(a)
if(a.count(l) > 1):
print("Still Rozdil")
else:
print(a.index(l)+1)
``` | 3 | |
16 | A | Flag | PROGRAMMING | 800 | [
"implementation"
] | A. Flag | 2 | 64 | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be... | The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands ... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | [
"3 3\n000\n111\n222\n",
"3 3\n000\n000\n111\n",
"3 3\n000\n111\n002\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 0 | [
{
"input": "3 3\n000\n111\n222",
"output": "YES"
},
{
"input": "3 3\n000\n000\n111",
"output": "NO"
},
{
"input": "3 3\n000\n111\n002",
"output": "NO"
},
{
"input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000... | 1,614,838,920 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | n, m = [int(item) for item in input().split(' ')]
ans, prev = 'YES', ''
for i in range(n):
current = input()
if prev == current or current.count(current[0]) != m:
ans = 'NO'
break
prev = current
print(ans) | Title: Flag
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of... | ```python
n, m = [int(item) for item in input().split(' ')]
ans, prev = 'YES', ''
for i in range(n):
current = input()
if prev == current or current.count(current[0]) != m:
ans = 'NO'
break
prev = current
print(ans)
``` | 3.969 |
658 | A | Bear and Reverse Radewoosh | PROGRAMMING | 800 | [
"implementation"
] | null | null | Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by diff... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=50,<=1<=≤<=*c*<=≤<=1000) — the number of problems and the constant representing the speed of loosing points.
The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1000,<=*p**i*<=<<=*p**i*<=+<=1) — initial scores.
The third... | Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points. | [
"3 2\n50 85 250\n10 15 25\n",
"3 6\n50 85 250\n10 15 25\n",
"8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n"
] | [
"Limak\n",
"Radewoosh\n",
"Tie\n"
] | In the first sample, there are 3 problems. Limak solves them as follows:
1. Limak spends 10 minutes on the 1-st problem and he gets 50 - *c*·10 = 50 - 2·10 = 30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85... | 500 | [
{
"input": "3 2\n50 85 250\n10 15 25",
"output": "Limak"
},
{
"input": "3 6\n50 85 250\n10 15 25",
"output": "Radewoosh"
},
{
"input": "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76",
"output": "Tie"
},
{
"input": "4 1\n3 5 6 9\n1 2 4 8",
"output": "Limak"
},
{... | 1,587,188,606 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 109 | 307,200 | n,c=list(map(int,input().strip().split()))
l=list(map(int,input().strip().split()))
t=list(map(int,input().strip().split()))
k=0
p=0
for i in range(n):
j=(l[i]-c*(sum(t[:i+1])))
if j<0:
k +=0
else:
k +=j
l=l[::-1]
t=t[::-1]
for i in range(n):
j=(l[i]-c*(sum(t[:i+1])))
... | Title: Bear and Reverse Radewoosh
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-... | ```python
n,c=list(map(int,input().strip().split()))
l=list(map(int,input().strip().split()))
t=list(map(int,input().strip().split()))
k=0
p=0
for i in range(n):
j=(l[i]-c*(sum(t[:i+1])))
if j<0:
k +=0
else:
k +=j
l=l[::-1]
t=t[::-1]
for i in range(n):
j=(l[i]-c*(sum(t[:i+1... | 3 | |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,677,247,715 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 60 | 0 | n, time = list(map(int, input().split()))
books = list(map(int, input().split()))
curr_time = 0
curr_books = []
ans = 0
for book in books:
ans = max(ans, len(curr_books))
if not curr_books:
curr_books.append(book)
curr_time = book
continue
while curr_books and curr_time ... | Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
n, time = list(map(int, input().split()))
books = list(map(int, input().split()))
curr_time = 0
curr_books = []
ans = 0
for book in books:
ans = max(ans, len(curr_books))
if not curr_books:
curr_books.append(book)
curr_time = book
continue
while curr_books and ... | 0 | |
886 | B | Vlad and Cafes | PROGRAMMING | 1,000 | [] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes... | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ... | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in... | 1,000 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000... | 1,510,510,033 | 7,333 | Python 3 | OK | TESTS | 33 | 217 | 14,233,600 | n = int(input())
a = [int(i) for i in input().split()]
b = [0]*(max(a)+1)
k = len(set(a))
t = 0
p = 0
for i in range (n):
b[a[i]] = n-i
print (b.index(max(b))) | Title: Vlad and Cafes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research... | ```python
n = int(input())
a = [int(i) for i in input().split()]
b = [0]*(max(a)+1)
k = len(set(a))
t = 0
p = 0
for i in range (n):
b[a[i]] = n-i
print (b.index(max(b)))
``` | 3 | |
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like... | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input"... | 1,618,776,625 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 109 | 614,400 | n=int(input())
s=input()
c=0
for i in range(0,n):
if s[i]=="1":
c+=1
v=n-c
print(abs(c-v)) | Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Cons... | ```python
n=int(input())
s=input()
c=0
for i in range(0,n):
if s[i]=="1":
c+=1
v=n-c
print(abs(c-v))
``` | 3 | |
620 | B | Grandfather Dovlet’s calculator | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)).
Max starts to type all the values from *a* to *b*. After typi... | The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max. | Print the only integer *a* — the total number of printed segments. | [
"1 3\n",
"10 15\n"
] | [
"12\n",
"39\n"
] | none | 0 | [
{
"input": "1 3",
"output": "12"
},
{
"input": "10 15",
"output": "39"
},
{
"input": "1 100",
"output": "928"
},
{
"input": "100 10000",
"output": "188446"
},
{
"input": "213 221442",
"output": "5645356"
},
{
"input": "1 1000000",
"output": "287333... | 1,649,382,469 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | disp=[0,1,2,3,4,5,6,7,8,9]
value=[6,2,5,5,4,5,6,3,7,6]
masuk=input("")
masuk=masuk.split(" ")
a=int(masuk[0])
b=int(masuk[1])
total=0
for i in range(a,b+1):
div=1;
if(i>=10):
while(True):
if(i/div>9):
total+=value[i//div%10]
div*=10;
... | Title: Grandfather Dovlet’s calculator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](... | ```python
disp=[0,1,2,3,4,5,6,7,8,9]
value=[6,2,5,5,4,5,6,3,7,6]
masuk=input("")
masuk=masuk.split(" ")
a=int(masuk[0])
b=int(masuk[1])
total=0
for i in range(a,b+1):
div=1;
if(i>=10):
while(True):
if(i/div>9):
total+=value[i//div%10]
div*=10;
... | 0 | |
603 | A | Alternative Thinking | PROGRAMMING | 1,600 | [
"dp",
"greedy",
"math"
] | null | null | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one of the *n* questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is... | The first line contains the number of questions on the olympiad *n* (1<=≤<=*n*<=≤<=100<=000).
The following line contains a binary string of length *n* representing Kevin's results on the USAICO. | Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring. | [
"8\n10000011\n",
"2\n01\n"
] | [
"5\n",
"2\n"
] | In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | 500 | [
{
"input": "8\n10000011",
"output": "5"
},
{
"input": "2\n01",
"output": "2"
},
{
"input": "5\n10101",
"output": "5"
},
{
"input": "75\n010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "75"
},
{
"input": "11\n00000000000",
... | 1,632,750,803 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 93 | 20,172,800 |
n = int(input())
t = list(input())
for i in range(n):
if i>0 and i+1<n:
if t[i]==t[i-1] and t[i]==t[i+1]:
if t[i]=='1':
t[i]='0'
else:
t[i]='1'
break
ans=1
last= t[0]
for i in range(1,n):
if t[i]!=last:
... | Title: Alternative Thinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one o... | ```python
n = int(input())
t = list(input())
for i in range(n):
if i>0 and i+1<n:
if t[i]==t[i-1] and t[i]==t[i+1]:
if t[i]=='1':
t[i]='0'
else:
t[i]='1'
break
ans=1
last= t[0]
for i in range(1,n):
if t[i]... | 0 | |
61 | B | Hard Work | PROGRAMMING | 1,300 | [
"strings"
] | B. Hard Work | 2 | 256 | After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer!
Some days before the contest, the teacher took a very simple-looking exam and all his *n* students took part in the exam. The teach... | The first three lines contain a string each. These are the initial strings. They consists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). All the initial strings have length from 1 to 100, inclusively.
In the fourth line there is a single integer *n* (0<=≤<=*n*<=≤<=1000), the number of stud... | For each student write in a different line. Print "WA" if his answer is wrong or "ACC" if his answer is OK. | [
"Iran_\nPersian;\nW_o;n;d;e;r;f;u;l;\n7\nWonderfulPersianIran\nwonderful_PersIAN_IRAN;;_\nWONDERFUL___IRAN__PERSIAN__;;\nIra__Persiann__Wonderful\nWonder;;fulPersian___;I;r;a;n;\n__________IranPersianWonderful__________\nPersianIran_is_Wonderful\n",
"Shapur;;\nis___\na_genius\n3\nShapur__a_is___geniUs\nis___shapu... | [
"ACC\nACC\nACC\nWA\nACC\nACC\nWA\n",
"WA\nACC\nACC\n"
] | none | 1,000 | [
{
"input": "Iran_\nPersian;\nW_o;n;d;e;r;f;u;l;\n7\nWonderfulPersianIran\nwonderful_PersIAN_IRAN;;_\nWONDERFUL___IRAN__PERSIAN__;;\nIra__Persiann__Wonderful\nWonder;;fulPersian___;I;r;a;n;\n__________IranPersianWonderful__________\nPersianIran_is_Wonderful",
"output": "ACC\nACC\nACC\nWA\nACC\nACC\nWA"
},
... | 1,671,853,883 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 17 | 46 | 204,800 | """
Nghiện code love Chu Gia Linh <3
"""
def preprocess(s: str):
s = s.replace("-", "")
s = s.replace(";", "")
s = s.replace("_", "")
return s.lower()
def solve():
s = preprocess(input())
if leng != len(s):
print("WA")
return
for item in a:
if item... | Title: Hard Work
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer!
Some days before the contest, the teache... | ```python
"""
Nghiện code love Chu Gia Linh <3
"""
def preprocess(s: str):
s = s.replace("-", "")
s = s.replace(";", "")
s = s.replace("_", "")
return s.lower()
def solve():
s = preprocess(input())
if leng != len(s):
print("WA")
return
for item in a:
... | 0 |
127 | B | Canvas Frames | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has *n* sticks whose lengths equal *a*1,<=*a*2,<=... *a**n*. Nicholas does not want... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of sticks. The second line contains *n* space-separated integers. The *i*-th integer equals the length of the *i*-th stick *a**i* (1<=≤<=*a**i*<=≤<=100). | Print the single number — the maximum number of frames Nicholas can make for his future canvases. | [
"5\n2 4 3 2 3\n",
"13\n2 2 4 4 4 4 6 6 6 7 7 9 9\n",
"4\n3 3 3 5\n"
] | [
"1",
"3",
"0"
] | none | 1,000 | [
{
"input": "5\n2 4 3 2 3",
"output": "1"
},
{
"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9",
"output": "3"
},
{
"input": "4\n3 3 3 5",
"output": "0"
},
{
"input": "2\n3 5",
"output": "0"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "0"
},
{
"input": "14\... | 1,613,670,193 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 62 | 0 | i = int(input())
garumi = list(input().split())
d ={}
for x in garumi:
if x in d:
d[x] = d[x] + 1
else:
d[x] = 1
kkas = 0
for x in d:
kkas = kkas + d[x] // 2
print(kkas // 2) | Title: Canvas Frames
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin w... | ```python
i = int(input())
garumi = list(input().split())
d ={}
for x in garumi:
if x in d:
d[x] = d[x] + 1
else:
d[x] = 1
kkas = 0
for x in d:
kkas = kkas + d[x] // 2
print(kkas // 2)
``` | 3 | |
994 | B | Knights of a Polygonal Table | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"sortings"
] | null | null | Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo... | The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement.
The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct.
The third line contains $n... | Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights. | [
"4 2\n4 5 9 7\n1 2 11 33\n",
"5 1\n1 2 3 4 5\n1 2 3 4 5\n",
"1 0\n2\n3\n"
] | [
"1 3 46 36 ",
"1 3 5 7 9 ",
"3 "
] | Consider the first example.
- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is o... | 1,000 | [
{
"input": "4 2\n4 5 9 7\n1 2 11 33",
"output": "1 3 46 36 "
},
{
"input": "5 1\n1 2 3 4 5\n1 2 3 4 5",
"output": "1 3 5 7 9 "
},
{
"input": "1 0\n2\n3",
"output": "3 "
},
{
"input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9",
"output": "0 3 10 16 14 17 18 "
},
{
"input"... | 1,534,920,865 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 14,540,800 | R = lambda : list(map(int,input().split()))
n,k = map(int,input().split())
p,c = R(),R()
tuples = sorted(list(zip(p,c,list(range(n)))),key = lambda x : x[1],reverse=True)
for i in range(n) :
pts = c[i]
cnt = 0
for it in tuples :
if cnt==k :
break
if p[i]>it[0] :
... | Title: Knights of a Polygonal Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power ... | ```python
R = lambda : list(map(int,input().split()))
n,k = map(int,input().split())
p,c = R(),R()
tuples = sorted(list(zip(p,c,list(range(n)))),key = lambda x : x[1],reverse=True)
for i in range(n) :
pts = c[i]
cnt = 0
for it in tuples :
if cnt==k :
break
if p[i]>it[... | 0 | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,695,306,357 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | import math
s=list(map(int,input().split()))
a=s[0]
b=s[1]
print(math.ceil(math.log(b/a,10)/0.176)) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
import math
s=list(map(int,input().split()))
a=s[0]
b=s[1]
print(math.ceil(math.log(b/a,10)/0.176))
``` | 0 | |
849 | A | Odds and Ends | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numb... | The first line of input contains a non-negative integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence.
The second line contains *n* space-separated non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — the elements of the sequence. | Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower). | [
"3\n1 3 5\n",
"5\n1 0 1 5 1\n",
"3\n4 3 1\n",
"4\n3 9 9 3\n"
] | [
"Yes\n",
"Yes\n",
"No\n",
"No\n"
] | In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.
In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.
In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.
In ... | 500 | [
{
"input": "3\n1 3 5",
"output": "Yes"
},
{
"input": "5\n1 0 1 5 1",
"output": "Yes"
},
{
"input": "3\n4 3 1",
"output": "No"
},
{
"input": "4\n3 9 9 3",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "5\n100 99 100 99 99",
"out... | 1,652,560,188 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 74 | 62 | 28,364,800 | n=int(input())
a=[*map(int,input().split())]
print('YES' if n&a[0]&a[-1]&1 else 'NO')
| Title: Odds and Ends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd num... | ```python
n=int(input())
a=[*map(int,input().split())]
print('YES' if n&a[0]&a[-1]&1 else 'NO')
``` | 3 | |
550 | A | Two Substrings | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | 1,000 | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"... | 1,691,068,378 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | text = list(input())
length = len(text)
BA = False
AB = False
index = 1
while index < length :
if text[index] + text[index - 1] == "BA" :
BA = True
index += 1
elif text[index] + text[index - 1] == "AB" :
AB = True
index += 1
index += 1
print("YES" if BA and ... | Title: Two Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Input Specification:
The only line of input contain... | ```python
text = list(input())
length = len(text)
BA = False
AB = False
index = 1
while index < length :
if text[index] + text[index - 1] == "BA" :
BA = True
index += 1
elif text[index] + text[index - 1] == "AB" :
AB = True
index += 1
index += 1
print("YES" ... | 0 | |
991 | B | Getting an A | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that... | The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$).
The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works. | Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$. | [
"3\n4 4 4\n",
"4\n5 4 5 5\n",
"4\n5 3 3 5\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first sample, it is enough to redo two lab works to make two $4$s into $5$s.
In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$.
In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so t... | 1,000 | [
{
"input": "3\n4 4 4",
"output": "2"
},
{
"input": "4\n5 4 5 5",
"output": "0"
},
{
"input": "4\n5 3 3 5",
"output": "1"
},
{
"input": "1\n5",
"output": "0"
},
{
"input": "4\n3 2 5 4",
"output": "2"
},
{
"input": "5\n5 4 3 2 5",
"output": "2"
},
... | 1,623,802,430 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 62 | 0 | i = int(input())
s = list(map(int, input().split()))
t = 0
while True:
a = sum(s) / len(s)
if a >= 4.5:
print(t)
exit()
else:
if s.count(2) == 0:
if s.count(3) == 0:
s.pop(s.index(4))
s.append(5)
t += 1
... | Title: Getting an A
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming t... | ```python
i = int(input())
s = list(map(int, input().split()))
t = 0
while True:
a = sum(s) / len(s)
if a >= 4.5:
print(t)
exit()
else:
if s.count(2) == 0:
if s.count(3) == 0:
s.pop(s.index(4))
s.append(5)
t += ... | 3 | |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,638,372,384 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | t=int(input())
x = int(input())
if x % 6 == 0:
print(x//6)
if x%6 != 0:
print((x//6)+1) | Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
t=int(input())
x = int(input())
if x % 6 == 0:
print(x//6)
if x%6 != 0:
print((x//6)+1)
``` | -1 | |
464 | A | No to Palindromes! | PROGRAMMING | 1,700 | [
"greedy",
"strings"
] | null | null | Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or more.
Paul has found a tolerable string *s* of length *n*. Help him find the lexicographically next to... | The first line contains two space-separated integers: *n* and *p* (1<=≤<=*n*<=≤<=1000; 1<=≤<=*p*<=≤<=26). The second line contains string *s*, consisting of *n* small English letters. It is guaranteed that the string is tolerable (according to the above definition). | If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes). | [
"3 3\ncba\n",
"3 4\ncba\n",
"4 4\nabcd\n"
] | [
"NO\n",
"cbd\n",
"abda\n"
] | String *s* is lexicographically larger (or simply larger) than string *t* with the same length, if there is number *i*, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, ..., *s*<sub class="lower-index">*i*</sub> = *t*<sub class="lower-index">*i*</sub>, *s*<sub class="lower-index">*i*... | 500 | [
{
"input": "3 3\ncba",
"output": "NO"
},
{
"input": "3 4\ncba",
"output": "cbd"
},
{
"input": "4 4\nabcd",
"output": "abda"
},
{
"input": "2 2\nab",
"output": "ba"
},
{
"input": "2 2\nba",
"output": "NO"
},
{
"input": "1 2\na",
"output": "b"
},
... | 1,411,571,378 | 6,878 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 30 | 1,000 | 102,400 | def qwe(s, p, last):
matrix = [[True for i in range(p)] for g in range(len(s))]
for i in range(last):
if(i > 0):
matrix[i - 1][ord(s[i]) - 97] = False
if(i > 1):
matrix[i - 2][ord(s[i]) - 97] = False
if(i < n - 1):
matrix[i + 1][ord(s[i]) - 97]... | Title: No to Palindromes!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or... | ```python
def qwe(s, p, last):
matrix = [[True for i in range(p)] for g in range(len(s))]
for i in range(last):
if(i > 0):
matrix[i - 1][ord(s[i]) - 97] = False
if(i > 1):
matrix[i - 2][ord(s[i]) - 97] = False
if(i < n - 1):
matrix[i + 1][ord(s... | 0 | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,690,472,685 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | n, m = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
mini = float('inf')
for i in range(m-n+1):
mini = min(mini, max(arr[i:i+4]) - min(arr[i:i+4]))
print(mini) | Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
n, m = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
mini = float('inf')
for i in range(m-n+1):
mini = min(mini, max(arr[i:i+4]) - min(arr[i:i+4]))
print(mini)
``` | 0 | |
15 | A | Cottage Village | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Cottage Village | 2 | 64 | A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.
The architect bureau, wher... | The first line of the input data contains numbers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* — *x*-coordinate of the centre of the *i*-th house, and *a**i* — length of its side (<=-<=1000<=≤<=*x**i*<=≤<=1000... | Output the amount of possible positions of the new house. | [
"2 2\n0 4\n6 2\n",
"2 2\n0 4\n5 2\n",
"2 3\n0 4\n5 2\n"
] | [
"4\n",
"3\n",
"2\n"
] | It is possible for the *x*-coordinate of the new house to have non-integer value. | 0 | [
{
"input": "2 2\n0 4\n6 2",
"output": "4"
},
{
"input": "2 2\n0 4\n5 2",
"output": "3"
},
{
"input": "2 3\n0 4\n5 2",
"output": "2"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 2\n2 1",
"output": "2"
},
{
"input": "2 1\n2 1\n1 1",
"outp... | 1,618,051,526 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 307,200 | n, t = [int(item) for item in input().split(' ')]
cont, ans = [], 2
for i in range(n):
hcenter, hlen = [float(item) for item in input().split(' ')]
# subArr = [hcenter - hlen / 2, hcenter + hlen / 2]
# cont.append(subArr)
cont.append([hcenter - hlen / 2, hcenter + hlen / 2])
# print(f'cont befo... | Title: Cottage Village
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. I... | ```python
n, t = [int(item) for item in input().split(' ')]
cont, ans = [], 2
for i in range(n):
hcenter, hlen = [float(item) for item in input().split(' ')]
# subArr = [hcenter - hlen / 2, hcenter + hlen / 2]
# cont.append(subArr)
cont.append([hcenter - hlen / 2, hcenter + hlen / 2])
# print(f... | 3.966711 |
299 | A | Ksusha and Array | PROGRAMMING | 1,000 | [
"brute force",
"number theory",
"sortings"
] | null | null | Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! | The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements. | Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them. | [
"3\n2 2 4\n",
"5\n2 1 3 1 6\n",
"3\n2 3 5\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | 500 | [
{
"input": "3\n2 2 4",
"output": "2"
},
{
"input": "5\n2 1 3 1 6",
"output": "1"
},
{
"input": "3\n2 3 5",
"output": "-1"
},
{
"input": "1\n331358794",
"output": "331358794"
},
{
"input": "5\n506904227 214303304 136194869 838256937 183952885",
"output": "-1"
... | 1,681,137,562 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 3,481,600 | n =int(input())
l = list(map(int , input().split()))
number = -1
for i in range(n):
res = 0
for j in range(n) :
if l[j] % l[i] == 0:
res+=1
if res == n :
number = l[i]
break
print(number) | Title: Ksusha and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that ... | ```python
n =int(input())
l = list(map(int , input().split()))
number = -1
for i in range(n):
res = 0
for j in range(n) :
if l[j] % l[i] == 0:
res+=1
if res == n :
number = l[i]
break
print(number)
``` | 0 | |
264 | A | Escape from Stones | PROGRAMMING | 1,200 | [
"constructive algorithms",
"data structures",
"implementation",
"two pointers"
] | null | null | Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the stones. The stones are numbered from 1 to *n* in order.
The stones always fall to the center of Liss's ... | The input consists of only one line. The only line contains the string *s* (1<=≤<=|*s*|<=≤<=106). Each character in *s* will be either "l" or "r". | Output *n* lines — on the *i*-th line you should print the *i*-th stone's number from the left. | [
"llrlr\n",
"rrlll\n",
"lrlrr\n"
] | [
"3\n5\n4\n2\n1\n",
"1\n2\n5\n4\n3\n",
"2\n4\n5\n3\n1\n"
] | In the first example, the positions of stones 1, 2, 3, 4, 5 will be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/58fdb5684df807bfcb705a9da9ce175613362b7d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, respectively. So you should print the sequence: 3, 5, 4, 2, 1. | 500 | [
{
"input": "llrlr",
"output": "3\n5\n4\n2\n1"
},
{
"input": "rrlll",
"output": "1\n2\n5\n4\n3"
},
{
"input": "lrlrr",
"output": "2\n4\n5\n3\n1"
},
{
"input": "lllrlrllrl",
"output": "4\n6\n9\n10\n8\n7\n5\n3\n2\n1"
},
{
"input": "llrlrrrlrr",
"output": "3\n5\n6... | 1,671,680,307 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 15 | 514 | 268,390,400 | s = input()
n = len(s)
p = []
a = 0
b = pow(2, 1000000)
for i in range(len(s)):
m = (a + b)//2
p.append([m, i+1])
if s[i]=='l': b = m
else: a = m
p.sort()
for i in p: print(i[1])
| Title: Escape from Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the ... | ```python
s = input()
n = len(s)
p = []
a = 0
b = pow(2, 1000000)
for i in range(len(s)):
m = (a + b)//2
p.append([m, i+1])
if s[i]=='l': b = m
else: a = m
p.sort()
for i in p: print(i[1])
``` | 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,511,701,526 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 184 | 5,529,600 | a = int(input())
f = [int(k) for k in input().split()]
b = 0
c = 0
d = 0
e = 0
for i in f:
if i % 2 == 0:
b += 1
c = i
else:
d += 1
e = i
if b == 1:
print(f.index(c) + 1)
else:
print(f.index(e) + 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
a = int(input())
f = [int(k) for k in input().split()]
b = 0
c = 0
d = 0
e = 0
for i in f:
if i % 2 == 0:
b += 1
c = i
else:
d += 1
e = i
if b == 1:
print(f.index(c) + 1)
else:
print(f.index(e) + 1)
``` | 3.9437 |
863 | F | Almost Permutation | PROGRAMMING | 2,200 | [
"flows"
] | null | null | Recently Ivan noticed an array *a* while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this array might help him to reproduce the bug.
Ivan clearly remembers that there were *n* elements in the array, and each element was not ... | The first line contains two integer numbers *n* and *q* (1<=≤<=*n*<=≤<=50, 0<=≤<=*q*<=≤<=100).
Then *q* lines follow, each representing a fact about the array. *i*-th line contains the numbers *t**i*, *l**i*, *r**i* and *v**i* for *i*-th fact (1<=≤<=*t**i*<=≤<=2, 1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*, 1<=≤<=*v**i*<=≤<=*n*, ... | If the facts are controversial and there is no array that corresponds to them, print -1. Otherwise, print minimum possible *cost* of the array. | [
"3 0\n",
"3 1\n1 1 3 2\n",
"3 2\n1 1 3 2\n2 1 3 2\n",
"3 2\n1 1 3 2\n2 1 3 1\n"
] | [
"3\n",
"5\n",
"9\n",
"-1\n"
] | none | 0 | [
{
"input": "3 0",
"output": "3"
},
{
"input": "3 1\n1 1 3 2",
"output": "5"
},
{
"input": "3 2\n1 1 3 2\n2 1 3 2",
"output": "9"
},
{
"input": "3 2\n1 1 3 2\n2 1 3 1",
"output": "-1"
},
{
"input": "50 0",
"output": "50"
},
{
"input": "50 1\n2 31 38 25"... | 1,542,673,666 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 311 | 2,048,000 | #~ # MAGIC CODEFORCES PYTHON FAST IO
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
#~ # END OF MAGIC CODEFO... | Title: Almost Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Ivan noticed an array *a* while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this array might help him to reprodu... | ```python
#~ # MAGIC CODEFORCES PYTHON FAST IO
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
#~ # END OF MA... | 3 | |
362 | B | Petya and Staircases | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.
No... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty s... | Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO". | [
"10 5\n2 4 8 3 6\n",
"10 5\n2 4 5 7 9\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "10 5\n2 4 8 3 6",
"output": "NO"
},
{
"input": "10 5\n2 4 5 7 9",
"output": "YES"
},
{
"input": "10 9\n2 3 4 5 6 7 8 9 10",
"output": "NO"
},
{
"input": "5 2\n4 5",
"output": "NO"
},
{
"input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37",
"outp... | 1,496,409,677 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 7 | 249 | 307,200 | a,b=tuple(input().split(" "))
if b==0:
print("NO")
exit(0)
a=int(a)
b=int(b)
c=[int(x) for x in input().split(" ")]
c.sort()
if 1 in c or a in c:
print("NO")
exit(0)
for x in c:
if x in c and x+1 in c and x+2 in c:
print("NO")
exit(0)
print("YES") | Title: Petya and Staircases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump o... | ```python
a,b=tuple(input().split(" "))
if b==0:
print("NO")
exit(0)
a=int(a)
b=int(b)
c=[int(x) for x in input().split(" ")]
c.sort()
if 1 in c or a in c:
print("NO")
exit(0)
for x in c:
if x in c and x+1 in c and x+2 in c:
print("NO")
exit(0)
print("YES")
``` | -1 | |
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,690,535,399 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | def main():
cas = list(map(int, input().split()))
print((cas[0]*cas[1])//2)
main() | 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
def main():
cas = list(map(int, input().split()))
print((cas[0]*cas[1])//2)
main()
``` | 3.977 |
918 | B | Radio Station | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name o... | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase... | Print *m* lines, the commands in the configuration file after Dustin did his task. | [
"2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n"
] | [
"block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n"
] | none | 1,000 | [
{
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main"
},
{
"input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.3... | 1,600,475,028 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 109 | 307,200 | n,m = tuple(map(int,input().split()))
dic = dict()
query =""
for i in range(n + m):
fun,ip = input().split()
if ip[:-1] in dic:
query += fun + " " + ip + " #" + dic[ip[:-1]] + "\n"
else:
dic[ip] = fun
print(query)
| Title: Radio Station
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server ... | ```python
n,m = tuple(map(int,input().split()))
dic = dict()
query =""
for i in range(n + m):
fun,ip = input().split()
if ip[:-1] in dic:
query += fun + " " + ip + " #" + dic[ip[:-1]] + "\n"
else:
dic[ip] = fun
print(query)
``` | 3 | |
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec... | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"... | 1,685,326,152 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 93 | 1,331,200 | n=int(input())
s=input()
spots=["."]*n
left=0
right=n-1
chk=1
for i in range(n-1,-1,-1):
elem=s[i]
if chk==1:
spots[right]=elem
right-=1
else:
spots[left]=elem
left+=1
chk=1-chk
print("".join(spots))
| Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the... | ```python
n=int(input())
s=input()
spots=["."]*n
left=0
right=n-1
chk=1
for i in range(n-1,-1,-1):
elem=s[i]
if chk==1:
spots[right]=elem
right-=1
else:
spots[left]=elem
left+=1
chk=1-chk
print("".join(spots))
``` | 3 | |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,668,180,749 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | print(int(input()%9) | Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
print(int(input()%9)
``` | -1 |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,691,373,779 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | n = [0] * int(input())
p = list(map(int,input().split()))
for i in range(len(p)):
n[(p[i] - 1)] = i + 1
print(*n) | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
n = [0] * int(input())
p = list(map(int,input().split()))
for i in range(len(p)):
n[(p[i] - 1)] = i + 1
print(*n)
``` | 3 | |
47 | A | Triangular numbers | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Triangular numbers | 2 | 256 | A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers fr... | The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. | If the given integer is a triangular number output YES, otherwise output NO. | [
"1\n",
"2\n",
"3\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "2",
"output": "NO"
},
{
"input": "3",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "NO... | 1,629,482,308 | 2,147,483,647 | PyPy 3 | OK | TESTS | 71 | 248 | 20,172,800 | def tri_nums(n):
a = [0]*32
for c, i in enumerate(range(1, 32)):
a[i] = a[i-1] + (c+1)
tf = bin_search(a, n)
if tf:
return "YES"
return "NO"
def bin_search(a, tar):
first = 0
last = 31
while first<=last:
midpoint = (first+last)//2
if a[midpoint] == tar:
... | Title: Triangular numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t... | ```python
def tri_nums(n):
a = [0]*32
for c, i in enumerate(range(1, 32)):
a[i] = a[i-1] + (c+1)
tf = bin_search(a, n)
if tf:
return "YES"
return "NO"
def bin_search(a, tar):
first = 0
last = 31
while first<=last:
midpoint = (first+last)//2
if a[midpoint]... | 3.900425 |
837 | A | Text Volume | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. | Print one integer number — volume of text. | [
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] | [
"5\n",
"0\n",
"1\n"
] | In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | 0 | [
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd... | 1,572,462,514 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 109 | 0 | x = input()
n = input().split()
maxCap = 0
cap = 0
for x in n:
for i in x:
if i.isupper():
cap += 1
if cap > maxCap:
maxCap = cap
cap = 0
print(maxCap)
| Title: Text Volume
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex... | ```python
x = input()
n = input().split()
maxCap = 0
cap = 0
for x in n:
for i in x:
if i.isupper():
cap += 1
if cap > maxCap:
maxCap = cap
cap = 0
print(maxCap)
``` | 3 | |
491 | A | Up the hill | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation"
] | null | null | Hiking club "Up the hill" just returned from a walk. Now they are trying to remember which hills they've just walked through.
It is known that there were *N* stops, all on different integer heights between 1 and *N* kilometers (inclusive) above the sea level. On the first day they've traveled from the first stop to th... | In the first line there is an integer non-negative number *A* denoting the number of days of climbing up the hill. Second line contains an integer non-negative number *B* — the number of days of walking down the hill (*A*<=+<=*B*<=+<=1<==<=*N*, 1<=≤<=*N*<=≤<=100<=000). | Output *N* space-separated distinct integers from 1 to *N* inclusive, denoting possible heights of the stops in order of visiting. | [
"0\n1\n",
"2\n1"
] | [
"2 1 \n",
"1 3 4 2"
] | none | 500 | [
{
"input": "0\n1",
"output": "2 1 "
},
{
"input": "2\n1",
"output": "2 3 4 1 "
},
{
"input": "0\n3",
"output": "4 3 2 1 "
},
{
"input": "1\n1",
"output": "2 3 1 "
},
{
"input": "3\n7",
"output": "8 9 10 11 7 6 5 4 3 2 1 "
},
{
"input": "700\n300",
... | 1,690,809,706 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 124 | 6,041,600 | a=int(input())
b=int(input())
ans=[i for i in range(b+1,0,-1)]+[i for i in range(b+2,a+b+2)]
print(*ans) | Title: Up the hill
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hiking club "Up the hill" just returned from a walk. Now they are trying to remember which hills they've just walked through.
It is known that there were *N* stops, all on different integer heights between 1 and *N* kilome... | ```python
a=int(input())
b=int(input())
ans=[i for i in range(b+1,0,-1)]+[i for i in range(b+2,a+b+2)]
print(*ans)
``` | 3 | |
899 | C | Dividing the numbers | PROGRAMMING | 1,300 | [
"constructive algorithms",
"graphs",
"math"
] | null | null | Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of *n* integers should be exactly in one group. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has. | Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them. | [
"4\n",
"2\n"
] | [
"0\n2 1 4 \n",
"1\n1 1 \n"
] | In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and on... | 1,500 | [
{
"input": "4",
"output": "0\n2 1 4 "
},
{
"input": "2",
"output": "1\n1 1 "
},
{
"input": "3",
"output": "0\n1\n3 "
},
{
"input": "5",
"output": "1\n3\n1 2 5 "
},
{
"input": "59998",
"output": "1\n29999 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 4... | 1,587,291,050 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 155 | 921,600 | import math
import sys
from collections import defaultdict
from collections import Counter
from collections import deque
import bisect
sys.setrecursionlimit(1000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input... | Title: Dividing the numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help P... | ```python
import math
import sys
from collections import defaultdict
from collections import Counter
from collections import deque
import bisect
sys.setrecursionlimit(1000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(... | 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,713,192 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 248 | 0 | a=int(input())
res=1
for i in range(1,a):
res+=12
print(res) | 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())
res=1
for i in range(1,a):
res+=12
print(res)
``` | 0 | ||
1,006 | C | Three Parts of the Array | PROGRAMMING | 1,200 | [
"binary search",
"data structures",
"two pointers"
] | null | null | You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possib... | The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$. | Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$). | [
"5\n1 3 1 1 4\n",
"5\n1 3 2 1 4\n",
"3\n4 1 2\n"
] | [
"5\n",
"4\n",
"0\n"
] | In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | 0 | [
{
"input": "5\n1 3 1 1 4",
"output": "5"
},
{
"input": "5\n1 3 2 1 4",
"output": "4"
},
{
"input": "3\n4 1 2",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "5\n1 3 5 4 5",
"output": ... | 1,684,319,679 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 202 | 28,672,000 | n=int(input())
l=list(map(int,input().split()))
s=c=p=q=m=0
for i in range(n):
s+=l[i]
c+=1
while s>p and c+q<n:
p+=l[n-1-q]
q+=1
if s==p:m=max(m,s)
print(m)
| Title: Three Parts of the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belo... | ```python
n=int(input())
l=list(map(int,input().split()))
s=c=p=q=m=0
for i in range(n):
s+=l[i]
c+=1
while s>p and c+q<n:
p+=l[n-1-q]
q+=1
if s==p:m=max(m,s)
print(m)
``` | 3 | |
75 | C | Modified GCD | PROGRAMMING | 1,600 | [
"binary search",
"number theory"
] | C. Modified GCD | 2 | 256 | Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task... | The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=... | Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query. | [
"9 27\n3\n1 5\n10 11\n9 11\n"
] | [
"3\n-1\n9\n"
] | none | 1,500 | [
{
"input": "9 27\n3\n1 5\n10 11\n9 11",
"output": "3\n-1\n9"
},
{
"input": "48 72\n2\n8 29\n29 37",
"output": "24\n-1"
},
{
"input": "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90",
"output": "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1"
},
{
"input... | 1,625,422,716 | 2,147,483,647 | PyPy 3 | OK | TESTS | 60 | 1,058 | 13,209,600 | import math
from os import startfile
import random
from queue import Queue
import time
import heapq
import sys
def main(a,b,qu):
d=math.gcd(a,b)
factors=[]
for i in range(1,int(math.sqrt(d))+1):
q=d/i
if q==int(q):
factors.append(int(q))
factors.append(i)
fac... | Title: Modified GCD
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which ... | ```python
import math
from os import startfile
import random
from queue import Queue
import time
import heapq
import sys
def main(a,b,qu):
d=math.gcd(a,b)
factors=[]
for i in range(1,int(math.sqrt(d))+1):
q=d/i
if q==int(q):
factors.append(int(q))
factors.append(... | 3.710895 |
665 | C | Simple Strings | PROGRAMMING | 1,300 | [
"dp",
"greedy",
"strings"
] | null | null | zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with th... | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters. | Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them.
Note that the string *s*' should also consist of only lowercase English letters. | [
"aab\n",
"caaab\n",
"zscoder\n"
] | [
"bab\n",
"cabab\n",
"zscoder\n"
] | none | 0 | [
{
"input": "aab",
"output": "bab"
},
{
"input": "caaab",
"output": "cabab"
},
{
"input": "zscoder",
"output": "zscoder"
},
{
"input": "u",
"output": "u"
},
{
"input": "h",
"output": "h"
},
{
"input": "dtottttotd",
"output": "dtotataotd"
},
{
... | 1,624,104,998 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 77 | 0 | from sys import *
input = stdin.readline
print = stdout.write
s = input().strip()
arr = list(s)
arr2 = list('abcdefghijklmnopqrstuvwxyz')
s = {}
for j in range(26):
s[arr2[j]] = j
#print(s)
pre = 0
curr = s[arr[0]]
post = 0
for k in range(len(arr) - 1):
curr = s[arr[k]]
if k != 0:
pr... | Title: Simple Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wa... | ```python
from sys import *
input = stdin.readline
print = stdout.write
s = input().strip()
arr = list(s)
arr2 = list('abcdefghijklmnopqrstuvwxyz')
s = {}
for j in range(26):
s[arr2[j]] = j
#print(s)
pre = 0
curr = s[arr[0]]
post = 0
for k in range(len(arr) - 1):
curr = s[arr[k]]
if k != 0:
... | 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,677,513,774 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,764,800 | t=input().split()
if t[0][::-1]==t[1]:print("YES")
else: print("NO") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
t=input().split()
if t[0][::-1]==t[1]:print("YES")
else: print("NO")
``` | -1 |
257 | A | Sockets | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"sortings"
] | null | null | Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supp... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=50) —... | Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1. | [
"3 5 3\n3 1 2\n",
"4 7 2\n3 3 2 4\n",
"5 5 1\n1 3 1 2 1\n"
] | [
"1\n",
"2\n",
"-1\n"
] | In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to ... | 500 | [
{
"input": "3 5 3\n3 1 2",
"output": "1"
},
{
"input": "4 7 2\n3 3 2 4",
"output": "2"
},
{
"input": "5 5 1\n1 3 1 2 1",
"output": "-1"
},
{
"input": "4 5 8\n3 2 4 3",
"output": "0"
},
{
"input": "5 10 1\n4 3 4 2 4",
"output": "3"
},
{
"input": "7 13 2... | 1,518,809,170 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 92 | 5,632,000 | x,y,z=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
l=l[-1:-x-1:-1]
if z>=y:
print(0)
quit()
i=0
while(i<x):
z+=l[i]-1
if z > y:
print(i)
quit()
i+=1
print(-1)
| Title: Sockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his f... | ```python
x,y,z=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
l=l[-1:-x-1:-1]
if z>=y:
print(0)
quit()
i=0
while(i<x):
z+=l[i]-1
if z > y:
print(i)
quit()
i+=1
print(-1)
``` | 0 | |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,674,286,302 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | n = int(input())
ans = 0
i = 1
while i * i < n:
if n % i == 0:
ans += 2
i += 1
if i * i == n:
ans += 1
print(ans - 1)
| Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
n = int(input())
ans = 0
i = 1
while i * i < n:
if n % i == 0:
ans += 2
i += 1
if i * i == n:
ans += 1
print(ans - 1)
``` | 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,568,769,951 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 108 | 0 | n = input()
n=int(n)
holds=[]
diffs = []
holds = list(map(int,input().split()))
counter = 1
while counter < n-1 :
diff = holds[counter +1]-holds[counter -1]
i = 1
while i < n-1 :
if ( i-1 == counter or i+1 == counter):
i += 1
continue
if ((holds[i+1]-holds[i-1])-1 > diff) :
diff = holds[i... | Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 fo... | ```python
n = input()
n=int(n)
holds=[]
diffs = []
holds = list(map(int,input().split()))
counter = 1
while counter < n-1 :
diff = holds[counter +1]-holds[counter -1]
i = 1
while i < n-1 :
if ( i-1 == counter or i+1 == counter):
i += 1
continue
if ((holds[i+1]-holds[i-1])-1 > diff) :
diff... | 0 | |
216 | B | Forming Teams | PROGRAMMING | 1,700 | [
"dfs and similar",
"implementation"
] | null | null | One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student *A* is an archenemy to student *B*, then stud... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=100) — the number of students and the number of pairs of archenemies correspondingly.
Next *m* lines describe enmity between students. Each enmity is described as two numbers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=... | Print a single integer — the minimum number of students you will have to send to the bench in order to start the game. | [
"5 4\n1 2\n2 4\n5 3\n1 4\n",
"6 2\n1 4\n3 4\n",
"6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n"
] | [
"1",
"0",
"2"
] | none | 1,500 | [
{
"input": "5 4\n1 2\n2 4\n5 3\n1 4",
"output": "1"
},
{
"input": "6 2\n1 4\n3 4",
"output": "0"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4",
"output": "2"
},
{
"input": "5 1\n1 2",
"output": "1"
},
{
"input": "8 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 1",
... | 1,659,287,609 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | from collections import deque
import sys
def get_int(): return list(map(int, sys.stdin.readline().rstrip("\n\r").split()))
def dfs(start):
ans = 0
q = deque()
q.append(start)
while q:
cur = q.pop()
visited[cur-1] = True
for x in graph[cur]:
if visited[x-1] == True:
... | Title: Forming Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each stu... | ```python
from collections import deque
import sys
def get_int(): return list(map(int, sys.stdin.readline().rstrip("\n\r").split()))
def dfs(start):
ans = 0
q = deque()
q.append(start)
while q:
cur = q.pop()
visited[cur-1] = True
for x in graph[cur]:
if visited[x-1]... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes... | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ... | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in... | 0 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000... | 1,510,503,715 | 1,015 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 4 | 2,000 | 14,233,600 | # 445b
n = int(input())
a = list(map(int, input().split()))
uniq = []
for i in range(n - 1, -1, -1):
if a[i] not in uniq:
uniq.append(a[i])
print(uniq[-1])
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First o... | ```python
# 445b
n = int(input())
a = list(map(int, input().split()))
uniq = []
for i in range(n - 1, -1, -1):
if a[i] not in uniq:
uniq.append(a[i])
print(uniq[-1])
``` | 0 | |
257 | C | View Angle | PROGRAMMING | 1,800 | [
"brute force",
"geometry",
"math"
] | null | null | Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this a... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of mannequins.
Next *n* lines contain two space-separated integers each: *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=1000) — the coordinates of the *i*-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is gu... | Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10<=-<=6. | [
"2\n2 0\n0 2\n",
"3\n2 0\n0 2\n-2 2\n",
"4\n2 0\n0 2\n-2 0\n0 -2\n",
"2\n2 1\n1 2\n"
] | [
"90.0000000000\n",
"135.0000000000\n",
"270.0000000000\n",
"36.8698976458\n"
] | Solution for the first sample test is shown below:
Solution for the second sample test is shown below:
Solution for the third sample test is shown below:
Solution for the fourth sample test is shown below: | 1,500 | [
{
"input": "2\n2 0\n0 2",
"output": "90.0000000000"
},
{
"input": "3\n2 0\n0 2\n-2 2",
"output": "135.0000000000"
},
{
"input": "4\n2 0\n0 2\n-2 0\n0 -2",
"output": "270.0000000000"
},
{
"input": "2\n2 1\n1 2",
"output": "36.8698976458"
},
{
"input": "1\n1 1",
... | 1,690,704,358 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 1,466 | 24,985,600 | # https://codeforces.com/contest/257/problem/C
from math import atan, degrees
n = int(input())
# /|
# / |
# / | y
# / |
# / |
# /_____|
# x
#
# atan(y / x)
# tan is negative in the 2nd and 4th quadrant
mannequins = []
for _ in range(n):
mannequins.append(tuple(map(int, input().split()... | Title: View Angle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex ... | ```python
# https://codeforces.com/contest/257/problem/C
from math import atan, degrees
n = int(input())
# /|
# / |
# / | y
# / |
# / |
# /_____|
# x
#
# atan(y / x)
# tan is negative in the 2nd and 4th quadrant
mannequins = []
for _ in range(n):
mannequins.append(tuple(map(int, input... | 0 | |
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is... | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so ... | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "... | 1,664,198,538 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | kassa = 1
last = -1
for i in range(int(input())):
h, m = map(int, input().split())
mins = h * 60 + m
if last == -1:
last = mins
elif (mins - last) > 1:
last = mins
else:
last = mins
kassa += 1
print(kassa)
| Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l... | ```python
kassa = 1
last = -1
for i in range(int(input())):
h, m = map(int, input().split())
mins = h * 60 + m
if last == -1:
last = mins
elif (mins - last) > 1:
last = mins
else:
last = mins
kassa += 1
print(kassa)
``` | 0 | |
887 | A | Div. 64 | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisi... | In the only line given a non-empty binary string *s* with length up to 100. | Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise. | [
"100010001\n",
"100\n"
] | [
"yes",
"no"
] | In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system) | 500 | [
{
"input": "100010001",
"output": "yes"
},
{
"input": "100",
"output": "no"
},
{
"input": "0000001000000",
"output": "yes"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "no"
},
{
"in... | 1,611,254,613 | 213 | PyPy 3 | RUNTIME_ERROR | TESTS | 10 | 140 | 2,150,400 | s = str(input())
n = len(s)
for i in range(n):
if s[i] == '1':
p = i
break
else:
print('no')
c = 0
for i in range(p+1, n):
if s[i] == '0':
c += 1
if c >= 6:
print('yes')
else:
print('no')
| Title: Div. 64
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some dig... | ```python
s = str(input())
n = len(s)
for i in range(n):
if s[i] == '1':
p = i
break
else:
print('no')
c = 0
for i in range(p+1, n):
if s[i] == '0':
c += 1
if c >= 6:
print('yes')
else:
print('no')
``` | -1 | |
332 | A | Down the Hatch! | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!
Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. After they ran out of the first barrel of juice, they decided to pl... | The first line contains a single integer *n* (4<=≤<=*n*<=≤<=2000) — the number of participants in the game. The second line describes the actual game: the *i*-th character of this line equals 'a', if the participant who moved *i*-th pointed at the next person with his elbow, and 'b', if the participant pointed with a n... | Print a single integer — the number of glasses of juice Vasya could have drunk if he had played optimally well. | [
"4\nabbba\n",
"4\nabbab\n"
] | [
"1\n",
"0\n"
] | In both samples Vasya has got two turns — 1 and 5. In the first sample, Vasya could have drunk a glass of juice during the fifth turn if he had pointed at the next person with a nod. In this case, the sequence of moves would look like "abbbb". In the second sample Vasya wouldn't drink a single glass of juice as the mov... | 500 | [
{
"input": "4\nabbba",
"output": "1"
},
{
"input": "4\nabbab",
"output": "0"
},
{
"input": "4\naaa",
"output": "0"
},
{
"input": "4\naab",
"output": "0"
},
{
"input": "4\naabaabbba",
"output": "1"
},
{
"input": "6\naaaaaaaaaaaaaaaa",
"output": "2"
... | 1,380,921,069 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 124 | 0 | s, n, t = 0, int(input()), input()
print(sum(t[i] == t[i + 1] == t[i + 2] for i in range((3 // n + 1) * n - 3, len(t) - 3, n))) | Title: Down the Hatch!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!
Yesterday one student, Vasya and his mates made some barbecue and th... | ```python
s, n, t = 0, int(input()), input()
print(sum(t[i] == t[i + 1] == t[i + 2] for i in range((3 // n + 1) * n - 3, len(t) - 3, n)))
``` | 3 | |
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m... | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
... | 1,647,090,891 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 124 | 1,126,400 | s = input()
t = input()
s_l = len(s)
t_l = len(t)
if s_l == 0 or t_l == 0:
if s_l>=t_l:
print(s_l)
else:
print(t_l)
if s_l>=t_l:
temp = t_l
else:
temp = s_l
qqqq = 0
for i in range(temp):
if s[s_l-i-1] == t[t_l-i-1]:
qqqq += 1
sum_h = s_l-qqqq
sum_q = t_l-qq... | Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ... | ```python
s = input()
t = input()
s_l = len(s)
t_l = len(t)
if s_l == 0 or t_l == 0:
if s_l>=t_l:
print(s_l)
else:
print(t_l)
if s_l>=t_l:
temp = t_l
else:
temp = s_l
qqqq = 0
for i in range(temp):
if s[s_l-i-1] == t[t_l-i-1]:
qqqq += 1
sum_h = s_l-qqqq
sum_... | 0 | |
501 | B | Misha and Changing Handles | PROGRAMMING | 1,100 | [
"data structures",
"dsu",
"strings"
] | null | null | Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the re... | The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests.
Next *q* lines contain the descriptions of the requests, one per line.
Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and di... | In the first line output the integer *n* — the number of users that changed their handles at least once.
In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*,... | [
"5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n"
] | [
"3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n"
] | none | 500 | [
{
"input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov",
"output": "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123"
},
{
"input": "1\nMisha Vasya",
"output": "1\nMisha Vasya"
},
{
"input": "10\na b\nb c\nc d\nd... | 1,618,333,649 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 77 | 0 | n=int(input())
names={}
for i in range(n):
x,y=map(str,input().split())
names[x]=[y]
ans=[]
for i in names:
x,y=i,names[i][0]
if y not in names:
continue
else:
tmp=[x]
j=names[x][0]
names[x].append(True)
while True:
if j not in names... | Title: Misha and Changing Handles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is a... | ```python
n=int(input())
names={}
for i in range(n):
x,y=map(str,input().split())
names[x]=[y]
ans=[]
for i in names:
x,y=i,names[i][0]
if y not in names:
continue
else:
tmp=[x]
j=names[x][0]
names[x].append(True)
while True:
if j no... | 0 | |
622 | D | Optimal Number Permutation | PROGRAMMING | 1,900 | [
"constructive algorithms"
] | null | null | You have array *a* that contains all integers from 1 to *n* twice. You can arbitrary permute any numbers in *a*.
Let number *i* be in positions *x**i*,<=*y**i* (*x**i*<=<<=*y**i*) in the permuted array *a*. Let's define the value *d**i*<==<=*y**i*<=-<=*x**i* — the distance between the positions of the number *i*. P... | The only line contains integer *n* (1<=≤<=*n*<=≤<=5·105). | Print 2*n* integers — the permuted array *a* that minimizes the value of the sum *s*. | [
"2\n",
"1\n"
] | [
"1 1 2 2\n",
"1 1\n"
] | none | 0 | [
{
"input": "2",
"output": "1 1 2 2"
},
{
"input": "1",
"output": "1 1"
},
{
"input": "3",
"output": "1 3 1 2 2 3"
},
{
"input": "4",
"output": "1 3 3 1 2 4 2 4"
},
{
"input": "10",
"output": "1 3 5 7 9 9 7 5 3 1 2 4 6 8 10 8 6 4 2 10"
},
{
"input": "10... | 1,459,095,131 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 4,608,000 | n = int(input())
a = []
for i in range(1, n + 1):
a.append(i)
a.append(i)
print(*a) | Title: Optimal Number Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have array *a* that contains all integers from 1 to *n* twice. You can arbitrary permute any numbers in *a*.
Let number *i* be in positions *x**i*,<=*y**i* (*x**i*<=<<=*y**i*) in the permuted array *a... | ```python
n = int(input())
a = []
for i in range(1, n + 1):
a.append(i)
a.append(i)
print(*a)
``` | 0 | |
189 | A | Cut Ribbon | PROGRAMMING | 1,300 | [
"brute force",
"dp"
] | null | null | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon piece... | The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. | Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. | [
"5 5 3 2\n",
"7 5 5 2\n"
] | [
"2\n",
"2\n"
] | In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | 500 | [
{
"input": "5 5 3 2",
"output": "2"
},
{
"input": "7 5 5 2",
"output": "2"
},
{
"input": "4 4 4 4",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "4000 1 2 3",
"output": "4000"
},
{
"input": "4000 3 4 5",
"output": "1333"
},
... | 1,682,096,158 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 31 | 512,000 | import sys
memo = [sys.maxsize] * 4001
def dp(items, S):
if S == 0:
memo[S] = 0
return memo[S]
if memo[S] != sys.maxsize:
return memo[S]
maximum = -sys.maxsize
for i in range(len(items)):
if S - items[i] >= 0:
maximum = max(maximum, 1 + dp(items, S... | Title: Cut Ribbon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the... | ```python
import sys
memo = [sys.maxsize] * 4001
def dp(items, S):
if S == 0:
memo[S] = 0
return memo[S]
if memo[S] != sys.maxsize:
return memo[S]
maximum = -sys.maxsize
for i in range(len(items)):
if S - items[i] >= 0:
maximum = max(maximum, 1 + d... | -1 | |
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,697,850,251 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 0 | num = abs(int(input()))
l = [int(x) for x in str((num))]
lucky = (str(l.count(4) + l.count(7)))
listed = [y for y in lucky if y!='4' and y!='7']
if len(listed) == 0:
print("YES")
else:
print("NO") | 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
num = abs(int(input()))
l = [int(x) for x in str((num))]
lucky = (str(l.count(4) + l.count(7)))
listed = [y for y in lucky if y!='4' and y!='7']
if len(listed) == 0:
print("YES")
else:
print("NO")
``` | 3.9845 |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,592,272,348 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 19 | 109 | 0 | n = int(input(""))
l = 0
b = False
for i in range(n):
line = input("")
if len(set(line)) != 2:
b = True
if line[i] != line[-i - 1]:
b = True
if b == True:
break
if b == True:
print("NO")
else:
print("YES")
| Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
n = int(input(""))
l = 0
b = False
for i in range(n):
line = input("")
if len(set(line)) != 2:
b = True
if line[i] != line[-i - 1]:
b = True
if b == True:
break
if b == True:
print("NO")
else:
print("YES")
``` | 0 | |
907 | A | Masha and Bears | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg... | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 500 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"... | 1,592,459,845 | 385 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | import sys
import math
#import random
#sys.setrecursionlimit(1000000)
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
return(int(input()))
def inara():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(... | Title: Masha and Bears
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son b... | ```python
import sys
import math
#import random
#sys.setrecursionlimit(1000000)
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
return(int(input()))
def inara():
return(list(map(int,input().split())))
def insr():
s = input()
return(li... | 0 | |
350 | A | TL | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running ... | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1... | If there is a valid TL value, print it. Otherwise, print -1. | [
"3 6\n4 5 2\n8 9 6 10 7 11\n",
"3 1\n3 4 5\n6\n"
] | [
"5",
"-1\n"
] | none | 500 | [
{
"input": "3 6\n4 5 2\n8 9 6 10 7 11",
"output": "5"
},
{
"input": "3 1\n3 4 5\n6",
"output": "-1"
},
{
"input": "2 5\n45 99\n49 41 77 83 45",
"output": "-1"
},
{
"input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43... | 1,667,412,622 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 124 | 0 | def solve():
n,m=list(map(int,input().split(" ")))
l1=list(map(int,input().split(" ")))
l2=list(map(int,input().split(" ")))
m=max(min(l1)*2,max(l1))
print(m if max(l2)>m else -1)
solve() | Title: TL
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Val... | ```python
def solve():
n,m=list(map(int,input().split(" ")))
l1=list(map(int,input().split(" ")))
l2=list(map(int,input().split(" ")))
m=max(min(l1)*2,max(l1))
print(m if max(l2)>m else -1)
solve()
``` | 0 | |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,684,326,778 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 92 | 0 | s1=list(input())
s2=list(input())
s3=list(input())
l=[0]*26
for i in s1:
l[ord(i)%ord("A")]+=1
for i in s2:
l[ord(i)%ord("A")]+=1
for i in s3:
l[ord(i)%ord("A")]-=1
if(len(set(l))==1 and l[0]==0):
print("YES")
else:
print("NO") | Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
s1=list(input())
s2=list(input())
s3=list(input())
l=[0]*26
for i in s1:
l[ord(i)%ord("A")]+=1
for i in s2:
l[ord(i)%ord("A")]+=1
for i in s3:
l[ord(i)%ord("A")]-=1
if(len(set(l))==1 and l[0]==0):
print("YES")
else:
print("NO")
``` | 3 | |
584 | A | Olesya and Rodion | PROGRAMMING | 1,000 | [
"math"
] | null | null | Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-... | The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by. | Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them. | [
"3 2\n"
] | [
"712"
] | none | 500 | [
{
"input": "3 2",
"output": "222"
},
{
"input": "2 2",
"output": "22"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 3",
"output": "33333"
},
{
"input": "10 7",
"output": "7777777777"
},
{
"input": "2 9",
"output": "99"
},
{
"input"... | 1,670,136,692 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 46 | 0 | # 李本伟四六开
# 这是一场试炼
n,t = map(int, input().split(' '))
def snow(a, b):
n1 = pow(10, a) - 1
n2 = pow(10, a-1)
for i in range(n2, n1):
if i % b == 0:
return print(i)
return print(-1)
snow(n, t)
| Title: Olesya and Rodion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larg... | ```python
# 李本伟四六开
# 这是一场试炼
n,t = map(int, input().split(' '))
def snow(a, b):
n1 = pow(10, a) - 1
n2 = pow(10, a-1)
for i in range(n2, n1):
if i % b == 0:
return print(i)
return print(-1)
snow(n, t)
``` | 0 | |
451 | A | Game With Sticks | PROGRAMMING | 900 | [
"implementation"
] | null | null | After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.
In the grid show... | The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). | Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game. | [
"2 2\n",
"2 3\n",
"3 3\n"
] | [
"Malvika\n",
"Malvika\n",
"Akshat\n"
] | Explanation of the first sample:
The grid has four intersection points, numbered from 1 to 4.
If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this.
Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remov... | 500 | [
{
"input": "2 2",
"output": "Malvika"
},
{
"input": "2 3",
"output": "Malvika"
},
{
"input": "3 3",
"output": "Akshat"
},
{
"input": "20 68",
"output": "Malvika"
},
{
"input": "1 1",
"output": "Akshat"
},
{
"input": "1 2",
"output": "Akshat"
},
... | 1,679,887,950 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | grid = list(map(int,input().split()))
intersections = grid[0]*grid[1]
turns = 0
while intersections:
grid[0] -= 1
grid[1] -= 1
turns += 1
intersections = intersections = grid[0]*grid[1]
if turns % 2 or turns == 0:
print("Akshat")
else:
print("Malvika") | Title: Game With Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid... | ```python
grid = list(map(int,input().split()))
intersections = grid[0]*grid[1]
turns = 0
while intersections:
grid[0] -= 1
grid[1] -= 1
turns += 1
intersections = intersections = grid[0]*grid[1]
if turns % 2 or turns == 0:
print("Akshat")
else:
print("Malvika")
``` | 3 | |
743 | A | Vladik and flights | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows *n* airports. All the airports are located on a straight line. Each airport has u... | The first line contains three integers *n*, *a*, and *b* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length *n*, which consists only of characters... | Print single integer — the minimum cost Vladik has to pay to get to the olympiad. | [
"4 1 4\n1010\n",
"5 5 2\n10110\n"
] | [
"1",
"0"
] | In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to th... | 500 | [
{
"input": "4 1 4\n1010",
"output": "1"
},
{
"input": "5 5 2\n10110",
"output": "0"
},
{
"input": "10 9 5\n1011111001",
"output": "1"
},
{
"input": "7 3 7\n1110111",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 3 3\n100101101... | 1,529,777,012 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 93 | 102,400 | n,a,b=list(map(int,input().split()))
s=input()
print(0 if s[a-1]==s[b-1] else 1)
| Title: Vladik and flights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the o... | ```python
n,a,b=list(map(int,input().split()))
s=input()
print(0 if s[a-1]==s[b-1] else 1)
``` | 3 | |
103 | A | Testing Pants for Sadness | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"math"
] | A. Testing Pants for Sadness | 2 | 256 | The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 t... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*. | Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"2\n1 1\n",
"2\n2 2\n",
"1\n10\n"
] | [
"2",
"5",
"10"
] | Note to the second sample. In the worst-case scenario you will need five clicks:
- the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the ... | 500 | [
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n2 2",
"output": "5"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "3\n2 4 1",
"output": "10"
},
{
"input": "4\n5 5 3 1",
"output": "22"
},
{
"input": "2\n1000000000 1000000000",
"output": "... | 1,550,930,744 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 156 | 0 | n=int(input());s=input().split()
for i in range(0,n):
s[i]=int(s[i])
print(sum(s)+n-1) | Title: Testing Pants for Sadness
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* q... | ```python
n=int(input());s=input().split()
for i in range(0,n):
s[i]=int(s[i])
print(sum(s)+n-1)
``` | 0 |
609 | A | USB Flash Drives | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. | The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabyt... | Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. | [
"3\n5\n2\n1\n3\n",
"3\n6\n2\n3\n2\n",
"2\n5\n5\n10\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | 0 | [
{
"input": "3\n5\n2\n1\n3",
"output": "2"
},
{
"input": "3\n6\n2\n3\n2",
"output": "3"
},
{
"input": "2\n5\n5\n10",
"output": "1"
},
{
"input": "5\n16\n8\n1\n3\n4\n9",
"output": "2"
},
{
"input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100",
"output": "2"
... | 1,568,817,364 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 0 | #print(" ".join(map(str, r)))
n = int(input())
a = []
for j in range(n+1):
m = int(input())
a.append(m)
k = a[0]
del(a[0])
a.sort()
count = 0
for i in reversed(a):
if i>= k:
count+=1
break
else:
k-=i
count+=1
print(count)
| Title: USB Flash Drives
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of... | ```python
#print(" ".join(map(str, r)))
n = int(input())
a = []
for j in range(n+1):
m = int(input())
a.append(m)
k = a[0]
del(a[0])
a.sort()
count = 0
for i in reversed(a):
if i>= k:
count+=1
break
else:
k-=i
count+=1
print(count)
``` | 3 | |
592 | C | The Big Race | PROGRAMMING | 1,800 | [
"math"
] | null | null | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While ... | The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. | Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*. | [
"10 3 2\n",
"7 1 2\n"
] | [
"3/10\n",
"3/7\n"
] | In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. | 1,500 | [
{
"input": "10 3 2",
"output": "3/10"
},
{
"input": "7 1 2",
"output": "3/7"
},
{
"input": "1 1 1",
"output": "1/1"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 813 766",
"output": "765/94268"
},
{
"input": "262610 5583 4717",
... | 1,678,041,087 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | def gcd(a,b):
return a if b== 0 else gcd(b, a % b)
def lcm(a,b):
return a*b / gcd(a,b)
def solve():
t = int(input())
w = int(input())
b = int(input())
mn = min(w,b)
l = lcm(w,b)
step = (t + l - 1) // l
ans = step * mn - 1
if ( (t % 2) ==0 and mn == 1):
ans+... | Title: The Big Race
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the... | ```python
def gcd(a,b):
return a if b== 0 else gcd(b, a % b)
def lcm(a,b):
return a*b / gcd(a,b)
def solve():
t = int(input())
w = int(input())
b = int(input())
mn = min(w,b)
l = lcm(w,b)
step = (t + l - 1) // l
ans = step * mn - 1
if ( (t % 2) ==0 and mn == 1):
... | -1 | |
475 | B | Strongly Connected City | PROGRAMMING | 1,400 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to wes... | The first line of input contains two integers *n* and *m*, (2<=≤<=*n*,<=*m*<=≤<=20), denoting the number of horizontal streets and the number of vertical streets.
The second line contains a string of length *n*, made of characters '<' and '>', denoting direction of each horizontal street. If the *i*-th character... | If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO". | [
"3 3\n><>\nv^v\n",
"4 6\n<><>\nv^v^v^\n"
] | [
"NO\n",
"YES\n"
] | The figure above shows street directions in the second sample test case. | 1,000 | [
{
"input": "3 3\n><>\nv^v",
"output": "NO"
},
{
"input": "4 6\n<><>\nv^v^v^",
"output": "YES"
},
{
"input": "2 2\n<>\nv^",
"output": "YES"
},
{
"input": "2 2\n>>\n^v",
"output": "NO"
},
{
"input": "3 3\n>><\n^^v",
"output": "YES"
},
{
"input": "3 4\n>>... | 1,551,414,126 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 233 | 409,600 | from collections import deque
def gather_input():
n, m = [int(x) for x in input().split()]
hor_streets = list(input())
vert_streets = list(input())
return (hor_streets, vert_streets)
def gen_graph(hor_streets, vert_streets):
graph = {}
for i in range(len(hor_streets)):
for j i... | Title: Strongly Connected City
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one... | ```python
from collections import deque
def gather_input():
n, m = [int(x) for x in input().split()]
hor_streets = list(input())
vert_streets = list(input())
return (hor_streets, vert_streets)
def gen_graph(hor_streets, vert_streets):
graph = {}
for i in range(len(hor_streets)):
... | 3 | |
300 | A | Array | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The produ... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. | In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second... | [
"3\n-1 2 0\n",
"4\n-1 -2 -3 0\n"
] | [
"1 -1\n1 2\n1 0\n",
"1 -1\n2 -3 -2\n1 0\n"
] | none | 500 | [
{
"input": "3\n-1 2 0",
"output": "1 -1\n1 2\n1 0"
},
{
"input": "4\n-1 -2 -3 0",
"output": "1 -1\n2 -3 -2\n1 0"
},
{
"input": "5\n-1 -2 1 2 0",
"output": "1 -1\n2 1 2\n2 0 -2"
},
{
"input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -1... | 1,646,727,333 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 |
def solve(arr) :
pos=[]
neg=[]
zer=[x for x in arr if x==0 ]
arr=[x for x in arr if x!=0]
for i in range(len(arr)) :
neg.append(arr[i])
if arr[i]<0 :
if i==len(arr)-1 :
pos.append(neg[0])
neg.pop(0)
break
pos=ar... | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. T... | ```python
def solve(arr) :
pos=[]
neg=[]
zer=[x for x in arr if x==0 ]
arr=[x for x in arr if x!=0]
for i in range(len(arr)) :
neg.append(arr[i])
if arr[i]<0 :
if i==len(arr)-1 :
pos.append(neg[0])
neg.pop(0)
break
... | 0 | |
907 | A | Masha and Bears | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg... | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 500 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"... | 1,514,038,278 | 378 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 46 | 5,632,000 | v1, v2, v3, vm = map(int, input().split())
if v1 >= v2 >= v3 >= vm:
print(v1)
print(v2)
print(v3)
else:
print(-1)
| Title: Masha and Bears
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son b... | ```python
v1, v2, v3, vm = map(int, input().split())
if v1 >= v2 >= v3 >= vm:
print(v1)
print(v2)
print(v3)
else:
print(-1)
``` | 0 | |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,576,494,208 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 265 | 15,769,600 | n = int(input())
A = map(int, input().split())
before = set()
cnt = 0
ans = 0
for x in A:
if x in before:
cnt -= 1
else:
cnt += 1
before.add(x)
ans = max(ans, cnt)
print(ans)
| Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere... | ```python
n = int(input())
A = map(int, input().split())
before = set()
cnt = 0
ans = 0
for x in A:
if x in before:
cnt -= 1
else:
cnt += 1
before.add(x)
ans = max(ans, cnt)
print(ans)
``` | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,687,722,706 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 61 | 0 | import math
a,b,c=map(int,input().split())
k=0
if a%c==0:
k+= math.ceil(max(a,b)/c) * b
else:
k += math.ceil(max(a, b) / c) * (min(a,b)%c)
print(k) | 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
import math
a,b,c=map(int,input().split())
k=0
if a%c==0:
k+= math.ceil(max(a,b)/c) * b
else:
k += math.ceil(max(a, b) / c) * (min(a,b)%c)
print(k)
``` | 0 |
725 | A | Jumping Ball | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at pos... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | [
"4\n<<><\n",
"5\n>>>>>\n",
"4\n>><<\n"
] | [
"2",
"5",
"0"
] | In the first sample, the ball will fall from the field if starts at position 1 or position 2.
In the second sample, any starting position will result in the ball falling from the field. | 500 | [
{
"input": "4\n<<><",
"output": "2"
},
{
"input": "5\n>>>>>",
"output": "5"
},
{
"input": "4\n>><<",
"output": "0"
},
{
"input": "3\n<<>",
"output": "3"
},
{
"input": "3\n<<<",
"output": "3"
},
{
"input": "3\n><<",
"output": "0"
},
{
"input... | 1,586,283,194 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 93 | 0 | n=int(input())
s=input()
i=0
c1,c2=0,0
while s[i]=="<":
c1+=1
i+=1
i=n-1
while s[i]==">":
c2+=1
i-=1
print(c1+c2)
| Title: Jumping Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of b... | ```python
n=int(input())
s=input()
i=0
c1,c2=0,0
while s[i]=="<":
c1+=1
i+=1
i=n-1
while s[i]==">":
c2+=1
i-=1
print(c1+c2)
``` | -1 | |
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea... | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n... | 1,688,284,866 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 186 | 0 | x=int(input())
j=[0]*x
k=[0]*x
s=0
for i in range(x):
y,z=map(int,input().split())
j[i]=y
k[i]=z
for w in range(x):
for c in range(x):
if j[w]==k[c]:
s+=1
print(s) | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W... | ```python
x=int(input())
j=[0]*x
k=[0]*x
s=0
for i in range(x):
y,z=map(int,input().split())
j[i]=y
k[i]=z
for w in range(x):
for c in range(x):
if j[w]==k[c]:
s+=1
print(s)
``` | 3 | |
755 | F | PolandBall and Gifts | PROGRAMMING | 2,600 | [
"bitmasks",
"dp",
"greedy"
] | null | null | It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are *n* Balls overall. Each Ball has someone for whom he should bring a present according to some permutation *p*, *p**i*<=≠<=*i* for all *i*.
Unfortunately, Balls are quite clumsy. We know earlier that exactly *k* of them will forg... | The first line of input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=106, 0<=≤<=*k*<=≤<=*n*), representing the number of Balls and the number of Balls who will forget to bring their presents.
The second line contains the permutation *p* of integers from 1 to *n*, where *p**i* is the index of Ball who should get a... | You should output two values — minimum and maximum possible number of Balls who will not get their presents, in that order. | [
"5 2\n3 4 1 5 2\n",
"10 1\n2 3 4 5 6 7 8 9 10 1\n"
] | [
"2 4",
"2 2"
] | In the first sample, if the third and the first balls will forget to bring their presents, they will be th only balls not getting a present. Thus the minimum answer is 2. However, if the first ans the second balls will forget to bring their presents, then only the fifth ball will get a present. So, the maximum answer i... | 2,750 | [
{
"input": "5 2\n3 4 1 5 2",
"output": "2 4"
},
{
"input": "10 1\n2 3 4 5 6 7 8 9 10 1",
"output": "2 2"
},
{
"input": "5 4\n3 1 4 5 2",
"output": "5 5"
},
{
"input": "3 0\n2 3 1",
"output": "0 0"
},
{
"input": "4 3\n2 3 4 1",
"output": "4 4"
},
{
"inp... | 1,604,080,176 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(... | Title: PolandBall and Gifts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are *n* Balls overall. Each Ball has someone for whom he should bring a present according to some permutation *p*, *p**i*<=≠<=*... | ```python
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=... | -1 | |
437 | A | The Child and Homework | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The chi... | The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description... | Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). | [
"A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"A.ab\nB.abcde\nC.ab\nD.abc\n",
"A.c\nB.cc\nC.c\nD.c\n"
] | [
"D\n",
"C\n",
"B\n"
] | In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no ... | 500 | [
{
"input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute",
"output": "D"
},
{
"input": "A.ab\nB.abcde\nC.ab\nD.abc",
"output": "C"
},
{
"input": "A.c\nB.cc\nC.c\nD.c",
"output": "B"
},
... | 1,586,944,911 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 139 | 0 | a = len(input())-2
b = len(input())-2
c = len(input())-2
d = len(input())-2
l = list()
l.append(a)
l.append(b)
l.append(c)
l.append(d)
l = sorted(l)
x,y = 0, 0
if l[0] <= l[1]//2 and l[0] <= l[2]//2 and l[0] <= l[3]//2:
x = 1
if l[3] >= l[0]*2 and l[3] >= l[1]*2 and l[3] >= l[2]*2:
y = 1
if x+y =... | Title: The Child and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should fin... | ```python
a = len(input())-2
b = len(input())-2
c = len(input())-2
d = len(input())-2
l = list()
l.append(a)
l.append(b)
l.append(c)
l.append(d)
l = sorted(l)
x,y = 0, 0
if l[0] <= l[1]//2 and l[0] <= l[2]//2 and l[0] <= l[3]//2:
x = 1
if l[3] >= l[0]*2 and l[3] >= l[1]*2 and l[3] >= l[2]*2:
y = 1... | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,681,311,846 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | s=input()
l=str(len(s)-2)
if len(s)>10:
print(s[0]+l+s[-1])
else:
print(s) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
s=input()
l=str(len(s)-2)
if len(s)>10:
print(s[0]+l+s[-1])
else:
print(s)
``` | 0 |
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,678,452,967 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 93 | 7,884,800 | n = int(input())
val = list(map(int,input().split()))
val.sort()
temp = len(val)
print(len(val[1:temp-1]))
| 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())
val = list(map(int,input().split()))
val.sort()
temp = len(val)
print(len(val[1:temp-1]))
``` | 0 | |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportio... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ... | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39... | 1,684,757,990 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | a = eval(input())
s = input()
s = s.split()
for i in range(0, len(s)):
s[i] = int(s[i])
sum =0
for i in range(a):
sum+=s[i]
print(sum/a) | Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*... | ```python
a = eval(input())
s = input()
s = s.split()
for i in range(0, len(s)):
s[i] = int(s[i])
sum =0
for i in range(a):
sum+=s[i]
print(sum/a)
``` | 3 | |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,691,342,621 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 0 | test_cases, k = map(int, input().split())
counter = 0
for _ in range(test_cases):
num = input()
flag = True
for i in range(k+1):
if str(i) not in num:
flag = False
break
if flag: counter += 1
print(counter) | Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve... | ```python
test_cases, k = map(int, input().split())
counter = 0
for _ in range(test_cases):
num = input()
flag = True
for i in range(k+1):
if str(i) not in num:
flag = False
break
if flag: counter += 1
print(counter)
``` | 3 | |
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,335,182 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | n=int(input())
m=str(input()).upper()
l=[]
for i in range(n):
if m[i] in l:
continue
else:
l.append(m[i])
if len(l)==26:
print("YES")
else:
print("NO")
| 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
n=int(input())
m=str(input()).upper()
l=[]
for i in range(n):
if m[i] in l:
continue
else:
l.append(m[i])
if len(l)==26:
print("YES")
else:
print("NO")
``` | 3 | |
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu... | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"... | 1,693,510,227 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 77 | 0 | #yousef
n,m,a,b=map(int, input().split())
c=(n//m)*b
d=n*a
w=n%m
print(min(d,c)+min((w*a,b))) | Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl... | ```python
#yousef
n,m,a,b=map(int, input().split())
c=(n//m)*b
d=n*a
w=n%m
print(min(d,c)+min((w*a,b)))
``` | 3 | |
710 | E | Generate a String | PROGRAMMING | 2,000 | [
"dfs and similar",
"dp"
] | null | null | zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of *n* letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.
Initially, the text editor is empty. It takes him *x* seconds to insert or delete a letter... | The only line contains three integers *n*, *x* and *y* (1<=≤<=*n*<=≤<=107, 1<=≤<=*x*,<=*y*<=≤<=109) — the number of letters 'a' in the input file and the parameters from the problem statement. | Print the only integer *t* — the minimum amount of time needed to generate the input file. | [
"8 1 1\n",
"8 1 10\n"
] | [
"4\n",
"8\n"
] | none | 0 | [
{
"input": "8 1 1",
"output": "4"
},
{
"input": "8 1 10",
"output": "8"
},
{
"input": "10 62 99",
"output": "384"
},
{
"input": "88 417 591",
"output": "4623"
},
{
"input": "57 5289 8444",
"output": "60221"
},
{
"input": "382 81437847 324871127",
"... | 1,692,438,769 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 0 | 31 | 536,883,200 | def II():
return(int(input()))
def LMI():
return(list(map(int,input().split())))
def I():
return(input())
def MII():
return(map(int,input().split()))
import sys
sys.setrecursionlimit(10**7)
# input=sys.stdin.readline
# import io,os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readlin... | Title: Generate a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of *n* letters 'a'. He is too lazy to write a generator so he will manually generate the input in a t... | ```python
def II():
return(int(input()))
def LMI():
return(list(map(int,input().split())))
def I():
return(input())
def MII():
return(map(int,input().split()))
import sys
sys.setrecursionlimit(10**7)
# input=sys.stdin.readline
# import io,os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size... | 0 | |
166 | E | Tetrahedron | PROGRAMMING | 1,500 | [
"dp",
"math",
"matrices"
] | null | null | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. ... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. | Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"2\n",
"4\n"
] | [
"3\n",
"21\n"
] | The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "6"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "183"
},
{
"input": "7",
"output": "546"
... | 1,617,242,523 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 2,000 | 8,908,800 | def linear_solution(n):
dd,do = 1,0
for i in range(n):
t = do*3
do = (do<<1)+dd
dd = t
return dd%(int(1e9+7))
def f(n):
return linear_solution(n)
n = int(input())
print(f(n))
| Title: Tetrahedron
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each m... | ```python
def linear_solution(n):
dd,do = 1,0
for i in range(n):
t = do*3
do = (do<<1)+dd
dd = t
return dd%(int(1e9+7))
def f(n):
return linear_solution(n)
n = int(input())
print(f(n))
``` | 0 | |
508 | B | Anton and currency you all know | PROGRAMMING | 1,300 | [
"greedy",
"math",
"strings"
] | null | null | Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have informed the financier Anton of some information about the exchange rate of... | The first line contains an odd positive integer *n* — the exchange rate of currency you all know for today. The length of number *n*'s representation is within range from 2 to 105, inclusive. The representation of *n* doesn't contain any leading zeroes. | If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print <=-<=1.
Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained fro... | [
"527\n",
"4573\n",
"1357997531\n"
] | [
"572\n",
"3574\n",
"-1\n"
] | none | 1,000 | [
{
"input": "527",
"output": "572"
},
{
"input": "4573",
"output": "3574"
},
{
"input": "1357997531",
"output": "-1"
},
{
"input": "444443",
"output": "444434"
},
{
"input": "22227",
"output": "72222"
},
{
"input": "24683",
"output": "34682"
},
... | 1,684,236,757 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n=list(input())
m=[]
for i in range (len(n)):
if int(n[i])%2==0:
m.append(i)
if len(m)!=0:
small=m[0]
for i in range (1,len(m)):
if m[i]<small:
small=m[i]
n[small],n[-1]=n[-1],n[small]
print("".join(n))
else:
print(-1) | Title: Anton and currency you all know
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed... | ```python
n=list(input())
m=[]
for i in range (len(n)):
if int(n[i])%2==0:
m.append(i)
if len(m)!=0:
small=m[0]
for i in range (1,len(m)):
if m[i]<small:
small=m[i]
n[small],n[-1]=n[-1],n[small]
print("".join(n))
else:
print(-1)
``` | 0 | |
185 | A | Plant | PROGRAMMING | 1,300 | [
"math"
] | null | null | Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divide... | The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1018) — the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | Print a single integer — the remainder of dividing the number of plants that will point "upwards" in *n* years by 1000000007 (109<=+<=7). | [
"1\n",
"2\n"
] | [
"3\n",
"10\n"
] | The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one. | 500 | [
{
"input": "1",
"output": "3"
},
{
"input": "2",
"output": "10"
},
{
"input": "385599124",
"output": "493875375"
},
{
"input": "989464295",
"output": "31966163"
},
{
"input": "376367012",
"output": "523204186"
},
{
"input": "529357306",
"output": "... | 1,560,449,809 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 2 | 1,496 | 268,390,400 | mod = int(1e9+7)
n = int(input())
print(((1 << (2 * n - 1)) + (1 << (n - 1))) % mod)
| Title: Plant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will poi... | ```python
mod = int(1e9+7)
n = int(input())
print(((1 << (2 * n - 1)) + (1 << (n - 1))) % mod)
``` | 0 | |
55 | C | Pie or die | PROGRAMMING | 1,900 | [
"games"
] | C. Pie or die | 2 | 256 | Volodya and Vlad play the following game. There are *k* pies at the cells of *n*<=<=×<=<=*m* board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at... | First line contains 3 integers, separated by space: 1<=≤<=*n*,<=*m*<=≤<=100 — dimensions of the board and 0<=≤<=*k*<=≤<=100 — the number of pies. Each of the next *k* lines contains 2 integers, separated by space: 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* — coordinates of the corresponding pie. There could be more than one ... | Output only one word: "YES" — if Volodya wins, "NO" — otherwise. | [
"2 2 1\n1 2\n",
"3 4 0\n",
"100 50 2\n50 25\n50 25\n"
] | [
"YES",
"NO",
"NO"
] | none | 1,500 | [
{
"input": "2 2 1\n1 2",
"output": "YES"
},
{
"input": "3 4 0",
"output": "NO"
},
{
"input": "100 50 2\n50 25\n50 25",
"output": "NO"
},
{
"input": "20 20 4\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "15 15 1\n8 8",
"output": "NO"
},
{
... | 1,646,628,006 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 75 | 122 | 0 | n, m, k = map(int, input().split())
for i in range(k):
x, y = map(int, input().split())
if min(n-x, x-1, m-y, y-1) <5:
print('YES')
exit()
print('NO') | Title: Pie or die
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Volodya and Vlad play the following game. There are *k* pies at the cells of *n*<=<=×<=<=*m* board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can ... | ```python
n, m, k = map(int, input().split())
for i in range(k):
x, y = map(int, input().split())
if min(n-x, x-1, m-y, y-1) <5:
print('YES')
exit()
print('NO')
``` | 3.9695 |
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.