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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
722 | C | Destroying Array | PROGRAMMING | 1,600 | [
"data structures",
"dsu"
] | null | null | You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defining the order elements of the array are destroyed.
After each element is destroyed you have to find o... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
The third line contains a permutation of integers from 1 to *n* — the order used to destroy elements. | Print *n* lines. The *i*-th line should contain a single integer — the maximum possible sum of elements on the segment containing no destroyed elements, after first *i* operations are performed. | [
"4\n1 3 2 5\n3 4 1 2\n",
"5\n1 2 3 4 5\n4 2 3 5 1\n",
"8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n"
] | [
"5\n4\n3\n0\n",
"6\n5\n5\n1\n0\n",
"18\n16\n11\n8\n8\n6\n6\n0\n"
] | Consider the first sample:
1. Third element is destroyed. Array is now 1 3 * 5. Segment with maximum sum 5 consists of one integer 5. 1. Fourth element is destroyed. Array is now 1 3 * * . Segment with maximum sum 4 consists of two integers 1 3. 1. First element is destroyed. Array is now * 3 * * . Segme... | 1,000 | [
{
"input": "4\n1 3 2 5\n3 4 1 2",
"output": "5\n4\n3\n0"
},
{
"input": "5\n1 2 3 4 5\n4 2 3 5 1",
"output": "6\n5\n5\n1\n0"
},
{
"input": "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6",
"output": "18\n16\n11\n8\n8\n6\n6\n0"
},
{
"input": "10\n3 3 3 5 6 9 3 1 7 3\n3 4 6 7 5 1 10 9 2 8"... | 1,475,332,679 | 1,979 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 12 | 1,000 | 1,843,200 | a=int(input())
l=list(map(int,input().split()))
q=list(map(int,input().split()))
value=[]
for i in range(a):
l[q[i]-1]="*"
k=0
o=k
for j in range(len(l)):
if l[j]!="*":
k=k+l[j]
else:
if o<k:
o=k
k=0
if o<k:
... | Title: Destroying Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defin... | ```python
a=int(input())
l=list(map(int,input().split()))
q=list(map(int,input().split()))
value=[]
for i in range(a):
l[q[i]-1]="*"
k=0
o=k
for j in range(len(l)):
if l[j]!="*":
k=k+l[j]
else:
if o<k:
o=k
k=0
if o<k:... | 0 | |
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*... | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": ... | 1,691,845,381 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 61 | 2,867,200 | x=int( input())
w= input()
import re
if len( re.findall("A",w))> len (re.findall("D",w)):
print("Anton")
elif len( re.findall("A",w))< len (re.findall("D",w)):
print("Danik")
else:
print("Friendship") | Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, w... | ```python
x=int( input())
w= input()
import re
if len( re.findall("A",w))> len (re.findall("D",w)):
print("Anton")
elif len( re.findall("A",w))< len (re.findall("D",w)):
print("Danik")
else:
print("Friendship")
``` | 3 | |
804 | B | Minimum number of steps | PROGRAMMING | 1,400 | [
"combinatorics",
"greedy",
"implementation",
"math"
] | null | null | We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<... | The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106. | Print the minimum number of steps modulo 109<=+<=7. | [
"ab\n",
"aab\n"
] | [
"1\n",
"3\n"
] | The first example: "ab" → "bba".
The second example: "aab" → "abba" → "bbaba" → "bbbbaa". | 1,000 | [
{
"input": "ab",
"output": "1"
},
{
"input": "aab",
"output": "3"
},
{
"input": "aaaaabaabababaaaaaba",
"output": "17307"
},
{
"input": "abaabaaabbabaabab",
"output": "1795"
},
{
"input": "abbaa",
"output": "2"
},
{
"input": "abbaaabaabaaaaabbbbaababaa... | 1,693,618,059 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | s = list(input())
a = 0
b = 0
soma = 0
for i in range(len(s)):
if s[i] == "b":
b += 1
else:
if b > 0:
soma += ((2**(a))-1)*b
a += 1
b = 0
if i == len(s) - 1 and s[i] == "b":
soma += ((2**(a))-1)*b
print(soma)
| Title: Minimum number of steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substr... | ```python
s = list(input())
a = 0
b = 0
soma = 0
for i in range(len(s)):
if s[i] == "b":
b += 1
else:
if b > 0:
soma += ((2**(a))-1)*b
a += 1
b = 0
if i == len(s) - 1 and s[i] == "b":
soma += ((2**(a))-1)*b
print(soma)
... | 0 | |
859 | E | Desk Disorder | PROGRAMMING | 2,100 | [
"combinatorics",
"dfs and similar",
"dsu",
"graphs",
"trees"
] | null | null | A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engineering team asking each engineer the number of the desk they currently sit at,... | Input will begin with a line containing *N* (1<=≤<=*N*<=≤<=100000), the number of engineers.
*N* lines follow, each containing exactly two integers. The *i*-th line contains the number of the current desk of the *i*-th engineer and the number of the desk the *i*-th engineer wants to move to. Desks are numbered from 1... | Print the number of possible assignments, modulo 1000000007<==<=109<=+<=7. | [
"4\n1 5\n5 2\n3 7\n7 3\n",
"5\n1 10\n2 10\n3 10\n4 10\n5 5\n"
] | [
"6\n",
"5\n"
] | These are the possible assignments for the first example:
- 1 5 3 7 - 1 2 3 7 - 5 2 3 7 - 1 5 7 3 - 1 2 7 3 - 5 2 7 3 | 2,000 | [
{
"input": "4\n1 5\n5 2\n3 7\n7 3",
"output": "6"
},
{
"input": "5\n1 10\n2 10\n3 10\n4 10\n5 5",
"output": "5"
},
{
"input": "1\n1 2",
"output": "2"
},
{
"input": "30\n22 37\n12 37\n37 58\n29 57\n43 57\n57 58\n58 53\n45 4\n1 4\n4 51\n35 31\n21 31\n31 51\n51 53\n53 48\n60 55\... | 1,696,308,601 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 93 | 4,710,400 | import sys
import math
from math import ceil
from functools import lru_cache
input = sys.stdin.readline
def womais(i,j):
if i == 0:
return j
elif j == 0:
return i
else:
return min(i,j)
class DisjointSetUnion:
def __init__(self, n):
self.parent = list(range(n))
sel... | Title: Desk Disorder
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out ... | ```python
import sys
import math
from math import ceil
from functools import lru_cache
input = sys.stdin.readline
def womais(i,j):
if i == 0:
return j
elif j == 0:
return i
else:
return min(i,j)
class DisjointSetUnion:
def __init__(self, n):
self.parent = list(range(n))
... | 0 | |
900 | B | Position in Fraction | PROGRAMMING | 1,300 | [
"math",
"number theory"
] | null | null | You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point. | The first contains three single positive integers *a*, *b*, *c* (1<=≤<=*a*<=<<=*b*<=≤<=105, 0<=≤<=*c*<=≤<=9). | Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. | [
"1 2 0\n",
"2 3 7\n"
] | [
"2",
"-1"
] | The fraction in the first example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/896357459a466614a0542f34c9cfb0cef1afc9ed.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first zero stands on second position.
The fraction in the second example ... | 1,000 | [
{
"input": "1 2 0",
"output": "2"
},
{
"input": "2 3 7",
"output": "-1"
},
{
"input": "1 100000 1",
"output": "5"
},
{
"input": "1 7 7",
"output": "6"
},
{
"input": "99999 100000 8",
"output": "-1"
},
{
"input": "44102 73848 2",
"output": "132"
}... | 1,570,209,035 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 0 | a,b,c = map(int,input().split(" "))
a = a%b
n = 9
while n <= 99999 :
if n%b==0 :
a *= n//b
i = 0
while a > 0 :
if a%10==c :
print(len(str(a))-i)
exit()
a //= 10
i += 1
print(-1)
exit()
... | Title: Position in Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point.
Input Specification:
The first contains three single positive integers *a*, *b*, ... | ```python
a,b,c = map(int,input().split(" "))
a = a%b
n = 9
while n <= 99999 :
if n%b==0 :
a *= n//b
i = 0
while a > 0 :
if a%10==c :
print(len(str(a))-i)
exit()
a //= 10
i += 1
print(-1)
ex... | 0 | |
913 | A | Modular Exponentiation | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108).
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108). | Output a single integer — the value of . | [
"4\n42\n",
"1\n58\n",
"98765432\n23456789\n"
] | [
"10\n",
"0\n",
"23456789\n"
] | In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10.
In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0. | 500 | [
{
"input": "4\n42",
"output": "10"
},
{
"input": "1\n58",
"output": "0"
},
{
"input": "98765432\n23456789",
"output": "23456789"
},
{
"input": "8\n88127381",
"output": "149"
},
{
"input": "32\n92831989",
"output": "92831989"
},
{
"input": "92831989\n25... | 1,591,534,849 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 155 | 0 | from math import log2
n=int(input())
m=int(input())
if log2(m)<n:print(m)
else:print(m%(2**n)) | Title: Modular Exponentiation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" prob... | ```python
from math import log2
n=int(input())
m=int(input())
if log2(m)<n:print(m)
else:print(m%(2**n))
``` | 3 | |
515 | A | Drazil and Date | PROGRAMMING | 1,000 | [
"math"
] | null | null | Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to ... | You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line. | If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes).
Otherwise, print "Yes". | [
"5 5 11\n",
"10 15 25\n",
"0 5 1\n",
"0 0 2\n"
] | [
"No\n",
"Yes\n",
"No\n",
"Yes\n"
] | In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "5 5 11",
"output": "No"
},
{
"input": "10 15 25",
"output": "Yes"
},
{
"input": "0 5 1",
"output": "No"
},
{
"input": "0 0 2",
"output": "Yes"
},
{
"input": "999999999 999999999 2000000000",
"output": "Yes"
},
{
"input": "-606037695 9983201... | 1,677,778,055 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 46 | 0 | a,b,c = map(int, input().split())
c -= a+b
if c%2 or c<0:
print("No")
else:
print("Yes") | Title: Drazil and Date
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit ... | ```python
a,b,c = map(int, input().split())
c -= a+b
if c%2 or c<0:
print("No")
else:
print("Yes")
``` | 0 | |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihn... | 1,622,269,028 | 2,147,483,647 | PyPy 3 | OK | TESTS | 58 | 93 | 0 | st=input().count
print(max(0,min((st("n")-1)//2,st("i"),st("t"),st("e")//3))) | Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiinetee... | ```python
st=input().count
print(max(0,min((st("n")-1)//2,st("i"),st("t"),st("e")//3)))
``` | 3 | |
25 | C | Roads in Berland | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Roads in Berland | 2 | 256 | There are *n* cities numbered from 1 to *n* in Berland. Some of them are connected by two-way roads. Each road has its own length — an integer number from 1 to 1000. It is known that from each city it is possible to get to any other city by existing roads. Also for each pair of cities it is known the shortest distance ... | The first line contains integer *n* (2<=≤<=*n*<=≤<=300) — amount of cities in Berland. Then there follow *n* lines with *n* integer numbers each — the matrix of shortest distances. *j*-th integer in the *i*-th row — *d**i*,<=*j*, the shortest distance between cities *i* and *j*. It is guaranteed that *d**i*,<=*i*<==<=0... | Output *k* space-separated integers *q**i* (1<=≤<=*i*<=≤<=*k*). *q**i* should be equal to the sum of shortest distances between all pairs of cities after the construction of roads with indexes from 1 to *i*. Roads are numbered from 1 in the input order. Each pair of cities should be taken into account in the sum exactl... | [
"2\n0 5\n5 0\n1\n1 2 3\n",
"3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1\n"
] | [
"3 ",
"17 12 "
] | none | 0 | [
{
"input": "2\n0 5\n5 0\n1\n1 2 3",
"output": "3 "
},
{
"input": "3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1",
"output": "17 12 "
},
{
"input": "3\n0 983 173\n983 0 810\n173 810 0\n3\n3 2 567\n2 3 767\n1 2 763",
"output": "1480 1480 1480 "
},
{
"input": "4\n0 537 1064 656\n537 0... | 1,697,013,272 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 6,144,000 |
n = int(input())
matrix = []
for _ in range(n):
matrix.append(list(map(int, input().split())))
add = []
k = int(input())
for _ in range(k):
add.append(tuple(map(int, input().split())))
ans = []
tem = sum([ sum(row) for row in matrix])//2
for a, b, c in add:
a -= 1
b -= 1
... | Title: Roads in Berland
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* cities numbered from 1 to *n* in Berland. Some of them are connected by two-way roads. Each road has its own length — an integer number from 1 to 1000. It is known that from each city it is possible to get to... | ```python
n = int(input())
matrix = []
for _ in range(n):
matrix.append(list(map(int, input().split())))
add = []
k = int(input())
for _ in range(k):
add.append(tuple(map(int, input().split())))
ans = []
tem = sum([ sum(row) for row in matrix])//2
for a, b, c in add:
a -= 1
b... | 0 |
275 | B | Convex Shape | PROGRAMMING | 1,700 | [
"constructive algorithms",
"implementation"
] | null | null | Consider an *n*<=×<=*m* grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the size of the grid. Each of the next *n* lines contains *m* characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid.
It's guaranteed that the grid has at least one black cel... | On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. | [
"3 4\nWWBW\nBWWW\nWWWB\n",
"3 1\nB\nB\nW\n"
] | [
"NO\n",
"YES\n"
] | none | 1,000 | [
{
"input": "3 4\nWWBW\nBWWW\nWWWB",
"output": "NO"
},
{
"input": "3 1\nB\nB\nW",
"output": "YES"
},
{
"input": "1 1\nB",
"output": "YES"
},
{
"input": "1 2\nBB",
"output": "YES"
},
{
"input": "2 1\nB\nB",
"output": "YES"
},
{
"input": "1 2\nBW",
"o... | 1,649,683,736 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 26 | 2,000 | 0 | def path_exists(n, m, mat, r1, c1, r2, c2):
if r1 > r2:
r1, c1, r2, c2 = r2, c2, r1, c1
# r1 <= r2
if r1 == r2:
if 0 in [mat[r1][j] for j in range(min(c1, c2), max(c1, c2) + 1)]:
return False
# r1 < r2
if c1 == c2:
if 0 in [mat[i][c1] for i in range(m... | Title: Convex Shape
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider an *n*<=×<=*m* grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any anothe... | ```python
def path_exists(n, m, mat, r1, c1, r2, c2):
if r1 > r2:
r1, c1, r2, c2 = r2, c2, r1, c1
# r1 <= r2
if r1 == r2:
if 0 in [mat[r1][j] for j in range(min(c1, c2), max(c1, c2) + 1)]:
return False
# r1 < r2
if c1 == c2:
if 0 in [mat[i][c1] for i ... | 0 | |
576 | C | Points on Plane | PROGRAMMING | 2,100 | [
"constructive algorithms",
"divide and conquer",
"geometry",
"greedy",
"sortings"
] | null | null | On a plane are *n* points (*x**i*, *y**i*) with integer coordinates between 0 and 106. The distance between the two points with numbers *a* and *b* is said to be the following value: (the distance calculated by such formula is called Manhattan distance).
We call a hamiltonian path to be some permutation *p**i* of num... | The first line contains integer *n* (1<=≤<=*n*<=≤<=106).
The *i*<=+<=1-th line contains the coordinates of the *i*-th point: *x**i* and *y**i* (0<=≤<=*x**i*,<=*y**i*<=≤<=106).
It is guaranteed that no two points coincide. | Print the permutation of numbers *p**i* from 1 to *n* — the sought Hamiltonian path. The permutation must meet the inequality .
If there are multiple possible answers, print any of them.
It is guaranteed that the answer exists. | [
"5\n0 7\n8 10\n3 4\n5 0\n9 12\n"
] | [
"4 3 1 2 5 \n"
] | In the sample test the total distance is:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c772e61c616e1c27114e3facb9e6db6c5cf93b82.png" style="max-width: 100.0%;max-height: 100.0%;"/>
(|5 - 3| + |0 - 4|) + (|3 - 0| + |4 - 7|) + (|0 - 8| + |7 - 10|) + (|8 - 9| + |10 - 12|) = 2 + 4 + 3 + 3 ... | 1,250 | [] | 1,665,760,015 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef long long ll;
struct modui{
int l,r,id;
}s[N];
int n,pos[N];
bool cmp(modui x,modui y){
if (pos[x.l]!=pos[y.l]) return x.l<y.l;
if(pos[x.l]&1) return x.r<y.r;
return x.r>y.r;
}
int main(){
cin>>n;
int dis=sqrt(n);
for(int i=1;... | Title: Points on Plane
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On a plane are *n* points (*x**i*, *y**i*) with integer coordinates between 0 and 106. The distance between the two points with numbers *a* and *b* is said to be the following value: (the distance calculated by such fo... | ```python
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef long long ll;
struct modui{
int l,r,id;
}s[N];
int n,pos[N];
bool cmp(modui x,modui y){
if (pos[x.l]!=pos[y.l]) return x.l<y.l;
if(pos[x.l]&1) return x.r<y.r;
return x.r>y.r;
}
int main(){
cin>>n;
int dis=sqrt(n);
fo... | -1 | |
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police offi... | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ... | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c... | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ... | 1,697,990,750 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n = int(input())
s = list(map(int, input().split()))
c = 0
for j in range(len(s)):
if s[-1 - j] >= 1:
s.pop(-1 - j)
else:
continue
for i in range(len(s)):
if s[i] == -1:
c += 1
else:
c -= s[i] * 2
print(c)
| Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of... | ```python
n = int(input())
s = list(map(int, input().split()))
c = 0
for j in range(len(s)):
if s[-1 - j] >= 1:
s.pop(-1 - j)
else:
continue
for i in range(len(s)):
if s[i] == -1:
c += 1
else:
c -= s[i] * 2
print(c)
``` | -1 | |
986 | A | Fair | PROGRAMMING | 1,600 | [
"graphs",
"greedy",
"number theory",
"shortest paths"
] | null | null | Some company is going to hold a fair in Byteland. There are $n$ towns in Byteland and $m$ two-way roads between towns. Of course, you can reach any town from any other town using roads.
There are $k$ types of goods produced in Byteland and every town produces only one type. To hold a fair you have to bring at least $s... | There are $4$ integers $n$, $m$, $k$, $s$ in the first line of input ($1 \le n \le 10^{5}$, $0 \le m \le 10^{5}$, $1 \le s \le k \le min(n, 100)$) — the number of towns, the number of roads, the number of different types of goods, the number of different types of goods necessary to hold a fair.
In the next line there ... | Print $n$ numbers, the $i$-th of them is the minimum number of coins you need to spend on travel expenses to hold a fair in town $i$. Separate numbers with spaces. | [
"5 5 4 3\n1 2 4 3 2\n1 2\n2 3\n3 4\n4 1\n4 5\n",
"7 6 3 2\n1 2 3 3 2 2 1\n1 2\n2 3\n3 4\n2 5\n5 6\n6 7\n"
] | [
"2 2 2 2 3 \n",
"1 1 1 2 2 1 1 \n"
] | Let's look at the first sample.
To hold a fair in town $1$ you can bring goods from towns $1$ ($0$ coins), $2$ ($1$ coin) and $4$ ($1$ coin). Total numbers of coins is $2$.
Town $2$: Goods from towns $2$ ($0$), $1$ ($1$), $3$ ($1$). Sum equals $2$.
Town $3$: Goods from towns $3$ ($0$), $2$ ($1$), $4$ ($1$). Sum equa... | 500 | [] | 1,699,648,379 | 1,259 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 93,900,800 | import sys
input = sys.stdin.buffer.readline
import heapq
def process(k, s, A, M):
n = len(A)
g = [[] for i in range(n+1)]
for u, v in M:
g[u].append(v)
g[v].append(u)
answer = [0 for i in range(n)]
towns = [[] for i in range(n)]
goods = [[] for i in range(k+1)]
... | Title: Fair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some company is going to hold a fair in Byteland. There are $n$ towns in Byteland and $m$ two-way roads between towns. Of course, you can reach any town from any other town using roads.
There are $k$ types of goods produced in By... | ```python
import sys
input = sys.stdin.buffer.readline
import heapq
def process(k, s, A, M):
n = len(A)
g = [[] for i in range(n+1)]
for u, v in M:
g[u].append(v)
g[v].append(u)
answer = [0 for i in range(n)]
towns = [[] for i in range(n)]
goods = [[] for i in ran... | 0 | |
264 | C | Choosing Balls | PROGRAMMING | 2,000 | [
"dp"
] | null | null | There are *n* balls. They are arranged in a row. Each ball has a color (for convenience an integer) and an integer value. The color of the *i*-th ball is *c**i* and the value of the *i*-th ball is *v**i*.
Squirrel Liss chooses some balls and makes a new sequence without changing the relative order of the balls. She wa... | The first line contains two integers *n* and *q* (1<=≤<=*n*<=≤<=105; 1<=≤<=*q*<=≤<=500). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (|*v**i*|<=≤<=105). The third line contains *n* integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=*n*).
The following *q* lines contain the values of the const... | For each query, output a line containing an integer — the answer to the query. The *i*-th line contains the answer to the *i*-th query in the input order.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"6 3\n1 -2 3 4 0 -1\n1 2 1 2 1 1\n5 1\n-2 1\n1 0\n",
"4 1\n-3 6 -1 2\n1 2 3 1\n1 -1\n"
] | [
"20\n9\n4\n",
"5\n"
] | In the first example, to achieve the maximal value:
- In the first query, you should select 1st, 3rd, and 4th ball. - In the second query, you should select 3rd, 4th, 5th and 6th ball. - In the third query, you should select 2nd and 4th ball.
Note that there may be other ways to achieve the maximal value. | 1,500 | [] | 1,484,675,200 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 124 | 4,812,800 |
n,q = map(int,input().split())
B = list(map(int,input().split()))
A = list(map(int,input().split()))
for t in range(q):
a,b = map(int,input().split())
per1 = [0,0]
per2 = [0,0]
dp = [0] * n
visited = [0] * n
for j in range(n):
color = A[j]
if... | Title: Choosing Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* balls. They are arranged in a row. Each ball has a color (for convenience an integer) and an integer value. The color of the *i*-th ball is *c**i* and the value of the *i*-th ball is *v**i*.
Squirrel Liss ... | ```python
n,q = map(int,input().split())
B = list(map(int,input().split()))
A = list(map(int,input().split()))
for t in range(q):
a,b = map(int,input().split())
per1 = [0,0]
per2 = [0,0]
dp = [0] * n
visited = [0] * n
for j in range(n):
color = A[j]
... | 0 | |
259 | A | Little Elephant and Chess | PROGRAMMING | 1,000 | [
"brute force",
"strings"
] | null | null | The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard d... | The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the *j*-th character in the *i*-th line stands for the color of the *j*-th cell of the *i*-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black co... | In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise. | [
"WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n",
"WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | 500 | [
{
"input": "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB",
"output": "YES"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBW... | 1,455,701,901 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | chess = [input() for i in range(8)]
for c in chess:
if 'WW' in c or 'BB' in c:
print('NO')
break
else:
continue
print('YES')
| Title: Little Elephant and Chess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, e... | ```python
chess = [input() for i in range(8)]
for c in chess:
if 'WW' in c or 'BB' in c:
print('NO')
break
else:
continue
print('YES')
``` | 0 | |
955 | A | Feed the cat | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points.
At any time Andrew can visit the store where tasty buns are... | The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening.
The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102). | Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4.
Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if . | [
"19 00\n255 1 100 1\n",
"17 41\n1000 6 15 11\n"
] | [
"25200.0000\n",
"1365.0000\n"
] | In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.
In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15... | 500 | [
{
"input": "19 00\n255 1 100 1",
"output": "25200.0000"
},
{
"input": "17 41\n1000 6 15 11",
"output": "1365.0000"
},
{
"input": "16 34\n61066 14 50 59",
"output": "43360.0000"
},
{
"input": "18 18\n23331 86 87 41",
"output": "49590.0000"
},
{
"input": "10 48\n684... | 1,579,028,396 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 307,200 | hh, mm = map(int, input().split())
H, D, C, N = map(int, input().split())
mm += hh*60
if mm >= 1200:
t, c = divmod(H, N)
if c:
t += 1
ans = t*C*0.8
else:
t2_d, t2_m = divmod(H, N)
if t2_m:
t2_d += 1
H += (1200-mm)*D
t1_d, t1_m = divmod(H, N)
if t1_m:
... | Title: Feed the cat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without foo... | ```python
hh, mm = map(int, input().split())
H, D, C, N = map(int, input().split())
mm += hh*60
if mm >= 1200:
t, c = divmod(H, N)
if c:
t += 1
ans = t*C*0.8
else:
t2_d, t2_m = divmod(H, N)
if t2_m:
t2_d += 1
H += (1200-mm)*D
t1_d, t1_m = divmod(H, N)
if... | 3 | |
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ... | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\... | 1,498,925,918 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 10,956,800 | n=int(input())
inp=sorted(list(map(int,input().split())))
i=1
tot=sum(inp)
while(i<n):
tot+=sum(inp[1:])
tot+=inp.pop(0)
i+=1
print(tot)
| Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all... | ```python
n=int(input())
inp=sorted(list(map(int,input().split())))
i=1
tot=sum(inp)
while(i<n):
tot+=sum(inp[1:])
tot+=inp.pop(0)
i+=1
print(tot)
``` | 0 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,688,550,494 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | s = input()
# Remove the opening and closing curly braces
s = s[1:-1]
# Split the string by commas and spaces
letters = s.split(", ")
# Count the number of distinct letters
distinct_letters = len(set(letters))
print(distinct_letters) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
s = input()
# Remove the opening and closing curly braces
s = s[1:-1]
# Split the string by commas and spaces
letters = s.split(", ")
# Count the number of distinct letters
distinct_letters = len(set(letters))
print(distinct_letters)
``` | 0 | |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara... | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ... | 1,647,243,035 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 1,536,000 | n, t = map(int, input().split())
pos = list(map(int, input().split()))
def dfs(h):
if h == t:
return True
if h > t:
return False
return dfs(h + pos[h - 1])
def infer(h):
cur = h
while cur < t:
cur += pos[cur - 1]
if cur == t:
return True
else:
ret... | Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o... | ```python
n, t = map(int, input().split())
pos = list(map(int, input().split()))
def dfs(h):
if h == t:
return True
if h > t:
return False
return dfs(h + pos[h - 1])
def infer(h):
cur = h
while cur < t:
cur += pos[cur - 1]
if cur == t:
return True
else:
... | 3 | |
347 | B | Fixed Points | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A p... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | [
"5\n0 1 3 4 2\n"
] | [
"3\n"
] | none | 1,000 | [
{
"input": "5\n0 1 3 4 2",
"output": "3"
},
{
"input": "10\n6 9 4 7 8 2 3 5 0 1",
"output": "2"
},
{
"input": "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15... | 1,615,979,954 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 921,600 | n=int(input())
l=list(map(int,input().split()))
s=[]
cnt=0
for i in range(n):
if(i!=l[i]):
cnt+=1
s.append([l[i],i])
if(cnt>0):
cnt-=1
for obj in s:
if [obj[1],obj[0]] in s:
cnt-=1
break
print(n-cnt) | Title: Fixed Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<... | ```python
n=int(input())
l=list(map(int,input().split()))
s=[]
cnt=0
for i in range(n):
if(i!=l[i]):
cnt+=1
s.append([l[i],i])
if(cnt>0):
cnt-=1
for obj in s:
if [obj[1],obj[0]] in s:
cnt-=1
break
print(n-cnt)
``` | 0 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,587,889,894 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 78 | 307,200 | pshop=[int(x) for x in input().split()]
minimum=0
if pshop[0]<pshop[1]:
if pshop[2]>=(pshop[0]+pshop[1]):
minimum=(pshop[0]+pshop[1])*2
else:
if pshop[2]>=(pshop[0]+pshop[1]):
minimum=(pshop[0]+pshop[1])*2
print(minimum)
| Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
pshop=[int(x) for x in input().split()]
minimum=0
if pshop[0]<pshop[1]:
if pshop[2]>=(pshop[0]+pshop[1]):
minimum=(pshop[0]+pshop[1])*2
else:
if pshop[2]>=(pshop[0]+pshop[1]):
minimum=(pshop[0]+pshop[1])*2
print(minimum)
``` | 0 | |
21 | C | Stripe 2 | PROGRAMMING | 2,000 | [
"binary search",
"dp",
"sortings"
] | C. Stripe 2 | 1 | 64 | Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece,... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains n space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into three non-empty pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | [
"4\n1 2 3 3\n",
"5\n1 2 3 4 5\n"
] | [
"1\n",
"0\n"
] | none | 1,500 | [
{
"input": "1\n-3",
"output": "0"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "3\n0 0 0",
"output": "1"
},
{
"input": "4\n-2 3 3 2",
"output": "0"
},
{
"input": "5\n-6 3 -1 2 -7",
"output": "0"
},
{
"input": "6\n2 3 -3 0 -3 1",
"output": "0... | 1,511,190,068 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 61 | 0 | # 21C
k = int(input())
sum_array= []
b=0
for i in input().split():
sum_array.append(int(i))
max= sum_array[-1]
if max % 3 != 0:
print(0)
quit()
i=0
for b in range(1, k):
if sum_array[b-1]* 3== max:
for b1 in range(b+1, k):
if sum_array[b1-1]== 2* sum_array[b-1]: i+= 1
... | Title: Stripe 2
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so tha... | ```python
# 21C
k = int(input())
sum_array= []
b=0
for i in input().split():
sum_array.append(int(i))
max= sum_array[-1]
if max % 3 != 0:
print(0)
quit()
i=0
for b in range(1, k):
if sum_array[b-1]* 3== max:
for b1 in range(b+1, k):
if sum_array[b1-1]== 2* sum_array[b-1]: 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,647,864,416 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 0 | num=int(input())
n= list(map(int,input().split()))
ev=[]
od=[]
for l in range(num):
if n[l]%2==0:
ev.append(l)
else:
od.append(l)
if len(od) > 1 and len(ev) > 0:
print(ev[0] + 1)
break
elif len(ev)>1 and len(od)>0:
print(od[0]+1)
br... | 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
num=int(input())
n= list(map(int,input().split()))
ev=[]
od=[]
for l in range(num):
if n[l]%2==0:
ev.append(l)
else:
od.append(l)
if len(od) > 1 and len(ev) > 0:
print(ev[0] + 1)
break
elif len(ev)>1 and len(od)>0:
print(od[0]+1)
... | 3.977 |
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output"... | 1,590,687,900 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 248 | 0 | #A. Reconnaissance 2
n = int(input())
arr = list(map(int,input().split()))
pos = [[i,j] for i,j in enumerate(arr)]
pos.sort(key = lambda x:x[1])
min_ = 100001
x,y = 0,0
for i in range(1,n):
if abs(pos[i][1]-pos[i-1][1])<min_:
min_ = abs(pos[i][1]-pos[i-1][1])
x = pos[i][0] + 1
y =... | Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So... | ```python
#A. Reconnaissance 2
n = int(input())
arr = list(map(int,input().split()))
pos = [[i,j] for i,j in enumerate(arr)]
pos.sort(key = lambda x:x[1])
min_ = 100001
x,y = 0,0
for i in range(1,n):
if abs(pos[i][1]-pos[i-1][1])<min_:
min_ = abs(pos[i][1]-pos[i-1][1])
x = pos[i][0] + 1
... | 0 |
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,640,453,036 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 46 | 0 | n,k = map(int,input().split())
s = input()
if n//2 >= k:
for i in range(k-1):
print("LEFT")
for i in range(n-1):
print("PRINT",s[i])
print("RIGHT")
print("PRINT",s[n-1])
else:
for i in range(n-k):
print("RIGHT")
for i in range(1,n):
print("PRINT... | 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())
s = input()
if n//2 >= k:
for i in range(k-1):
print("LEFT")
for i in range(n-1):
print("PRINT",s[i])
print("RIGHT")
print("PRINT",s[n-1])
else:
for i in range(n-k):
print("RIGHT")
for i in range(1,n):
pr... | 3 | |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,665,597,954 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | t=1
while t>0:
t-=1
n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
for i in range(0,len(a)):
if a[i]!=3:
b.append(i)
c.append(a[i])
sum=0
for i in range(0,len(b)-1):
if c[i]==0 or c[i+1]==0:
sum+=b[i+1]-b[i]-1
... | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int... | ```python
t=1
while t>0:
t-=1
n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
for i in range(0,len(a)):
if a[i]!=3:
b.append(i)
c.append(a[i])
sum=0
for i in range(0,len(b)-1):
if c[i]==0 or c[i+1]==0:
sum+=b[i+1... | 0 | |
884 | B | Japanese Crosswords Strike Back | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect.
For example:
- If *x*<==<... | The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding. | Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. | [
"2 4\n1 3\n",
"3 10\n3 3 2\n",
"2 10\n1 3\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2 4\n1 3",
"output": "NO"
},
{
"input": "3 10\n3 3 2",
"output": "YES"
},
{
"input": "2 10\n1 3",
"output": "NO"
},
{
"input": "1 1\n1",
"output": "YES"
},
{
"input": "1 10\n10",
"output": "YES"
},
{
"input": "1 10000\n10000",
"output":... | 1,510,202,580 | 2,147,483,647 | Python 3 | OK | TESTS | 66 | 77 | 7,372,800 | n, x = map(int, input().split())
tot = sum(list(map(int, input().split())))
print('YES' if tot + n - 1 == x else 'NO') | Title: Japanese Crosswords Strike Back
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely ... | ```python
n, x = map(int, input().split())
tot = sum(list(map(int, input().split())))
print('YES' if tot + n - 1 == x else 'NO')
``` | 3 | |
390 | A | Inna and Alarm Clock | PROGRAMMING | 0 | [
"implementation"
] | null | null | Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner at point (100,<=100). Then the alarm clocks are points with integer coordinates in this square.
The mornin... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of the alarm clocks. The next *n* lines describe the clocks: the *i*-th line contains two integers *x**i*, *y**i* — the coordinates of the *i*-th alarm clock (0<=≤<=*x**i*,<=*y**i*<=≤<=100).
Note that a single point in the room can conta... | In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally. | [
"4\n0 0\n0 1\n0 2\n1 0\n",
"4\n0 0\n0 1\n1 0\n1 1\n",
"4\n1 1\n1 2\n2 3\n3 3\n"
] | [
"2\n",
"2\n",
"3\n"
] | In the first sample, Inna first chooses type "vertical segments", and then she makes segments with ends at : (0, 0), (0, 2); and, for example, (1, 0), (1, 1). If she paints horizontal segments, she will need at least 3 segments.
In the third sample it is important to note that Inna doesn't have the right to change the... | 500 | [
{
"input": "4\n0 0\n0 1\n0 2\n1 0",
"output": "2"
},
{
"input": "4\n0 0\n0 1\n1 0\n1 1",
"output": "2"
},
{
"input": "4\n1 1\n1 2\n2 3\n3 3",
"output": "3"
},
{
"input": "1\n0 0",
"output": "1"
},
{
"input": "42\n28 87\n26 16\n59 90\n47 61\n28 83\n36 30\n67 10\n6 ... | 1,467,972,056 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 452 | 5,120,000 | n = int(input())
xset = set()
yset = set()
l = list(tuple(map(int, input().split())) for _ in range(n))
for a in l:
xset.add(a[0])
yset.add(a[1])
print(min(len(xset), len(yset)))
| Title: Inna and Alarm Clock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner a... | ```python
n = int(input())
xset = set()
yset = set()
l = list(tuple(map(int, input().split())) for _ in range(n))
for a in l:
xset.add(a[0])
yset.add(a[1])
print(min(len(xset), len(yset)))
``` | 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,655,741,492 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | user = input("")
n = int(user[0])
m = int(user[1])
a = int(user[2])
surface = n*m
flagstone = a*a
print(surface%flagstone) | 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
user = input("")
n = int(user[0])
m = int(user[1])
a = int(user[2])
surface = n*m
flagstone = a*a
print(surface%flagstone)
``` | -1 |
608 | A | Saitama Destroys Hotel | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor... | The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the tim... | Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0. | [
"3 7\n2 1\n3 8\n5 2\n",
"5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n"
] | [
"11\n",
"79\n"
] | In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: take... | 500 | [
{
"input": "3 7\n2 1\n3 8\n5 2",
"output": "11"
},
{
"input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64",
"output": "79"
},
{
"input": "1 1000\n1000 1000",
"output": "2000"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 1000\n1 1",
"output": "1000"
},
... | 1,614,106,153 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n,s=map(int,input().split())
my_dict={}
while(n):
person,floor=map(int,input().split())
my_dict[person]=floor
n-=1
val=max(my_dict, key=my_dict.get)
print(val+my_dict[val]) | Title: Saitama Destroys Hotel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only mo... | ```python
n,s=map(int,input().split())
my_dict={}
while(n):
person,floor=map(int,input().split())
my_dict[person]=floor
n-=1
val=max(my_dict, key=my_dict.get)
print(val+my_dict[val])
``` | 0 | |
891 | A | Pride | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"math",
"number theory"
] | null | null | You have an array *a* with length *n*, you can perform operations. Each operation is like this: choose two adjacent elements from *a*, say *x* and *y*, and replace one of them with *gcd*(*x*,<=*y*), where *gcd* denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor).
What is the mi... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=2000) — the number of elements in the array.
The second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. | Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. | [
"5\n2 2 3 4 6\n",
"4\n2 4 6 8\n",
"3\n2 6 9\n"
] | [
"5\n",
"-1\n",
"4\n"
] | In the first sample you can turn all numbers to 1 using the following 5 moves:
- [2, 2, 3, 4, 6]. - [2, 1, 3, 4, 6] - [2, 1, 3, 1, 6] - [2, 1, 1, 1, 6] - [1, 1, 1, 1, 6] - [1, 1, 1, 1, 1]
We can prove that in this case it is not possible to make all numbers one using less than 5 moves. | 500 | [
{
"input": "5\n2 2 3 4 6",
"output": "5"
},
{
"input": "4\n2 4 6 8",
"output": "-1"
},
{
"input": "3\n2 6 9",
"output": "4"
},
{
"input": "15\n10 10 10 10 10 10 21 21 21 21 21 21 21 21 21",
"output": "15"
},
{
"input": "12\n10 10 14 14 14 14 14 14 14 14 21 21",
... | 1,593,289,706 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 6,963,200 | import math
n = int(input())
a=list(map(int,input().split()))
k=a[0]
h=0
for i in range(1,n):
k=math.gcd(a[i],k)
if math.gcd(a[i],a[i-1])==1:
h=1
if k>1:
print(-1)
elif h==1:
print(n)
else:
print(n+1)
| Title: Pride
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have an array *a* with length *n*, you can perform operations. Each operation is like this: choose two adjacent elements from *a*, say *x* and *y*, and replace one of them with *gcd*(*x*,<=*y*), where *gcd* denotes the [great... | ```python
import math
n = int(input())
a=list(map(int,input().split()))
k=a[0]
h=0
for i in range(1,n):
k=math.gcd(a[i],k)
if math.gcd(a[i],a[i-1])==1:
h=1
if k>1:
print(-1)
elif h==1:
print(n)
else:
print(n+1)
``` | 0 | |
774 | K | Stepan and Vowels | PROGRAMMING | 1,600 | [
"*special",
"implementation",
"strings"
] | null | null | Stepan likes to repeat vowel letters when he writes words. For example, instead of the word "pobeda" he can write "pobeeeedaaaaa".
Sergey does not like such behavior, so he wants to write a program to format the words written by Stepan. This program must combine all consecutive equal vowels to a single vowel. The vowe... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of letters in the word written by Stepan.
The second line contains the string *s* which has length that equals to *n* and contains only lowercase English letters — the word written by Stepan. | Print the single string — the word written by Stepan converted according to the rules described in the statement. | [
"13\npobeeeedaaaaa\n",
"22\niiiimpleeemeentatiioon\n",
"18\naeiouyaaeeiioouuyy\n",
"24\naaaoooiiiuuuyyyeeeggghhh\n"
] | [
"pobeda\n",
"implemeentatioon\n",
"aeiouyaeeioouy\n",
"aoiuyeggghhh\n"
] | none | 0 | [
{
"input": "13\npobeeeedaaaaa",
"output": "pobeda"
},
{
"input": "22\niiiimpleeemeentatiioon",
"output": "implemeentatioon"
},
{
"input": "18\naeiouyaaeeiioouuyy",
"output": "aeiouyaeeioouy"
},
{
"input": "24\naaaoooiiiuuuyyyeeeggghhh",
"output": "aoiuyeggghhh"
},
{
... | 1,558,786,086 | 6,366 | Python 3 | OK | TESTS | 34 | 171 | 307,200 | n = int(input())
st = input()
last = '-'
ans = ""
k = 0
st += '+';
for it in st:
if it != last:
if last == 'a' or last == 'i' or last == 'u' or last == 'y':
ans += last;
elif last == 'e' or last == 'o':
if k == 2:
ans += last + last
e... | Title: Stepan and Vowels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Stepan likes to repeat vowel letters when he writes words. For example, instead of the word "pobeda" he can write "pobeeeedaaaaa".
Sergey does not like such behavior, so he wants to write a program to format the word... | ```python
n = int(input())
st = input()
last = '-'
ans = ""
k = 0
st += '+';
for it in st:
if it != last:
if last == 'a' or last == 'i' or last == 'u' or last == 'y':
ans += last;
elif last == 'e' or last == 'o':
if k == 2:
ans += last + last
... | 3 | |
61 | D | Eternal Victory | PROGRAMMING | 1,800 | [
"dfs and similar",
"graphs",
"greedy",
"shortest paths",
"trees"
] | D. Eternal Victory | 2 | 256 | Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal!
He decided to visit all *n* cities of Persia to find the best available mountain, but after the recent war he was too ... | First line contains a single natural number *n* (1<=≤<=*n*<=≤<=105) — the amount of cities.
Next *n*<=-<=1 lines contain 3 integer numbers each *x**i*, *y**i* and *w**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*,<=0<=≤<=*w**i*<=≤<=2<=×<=104). *x**i* and *y**i* are two ends of a road and *w**i* is the length of that road. | A single integer number, the minimal length of Shapur's travel.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). | [
"3\n1 2 3\n2 3 4\n",
"3\n1 2 3\n1 3 3\n"
] | [
"7\n",
"9\n"
] | none | 2,000 | [
{
"input": "3\n1 2 3\n2 3 4",
"output": "7"
},
{
"input": "3\n1 2 3\n1 3 3",
"output": "9"
},
{
"input": "5\n5 3 60\n4 3 63\n2 1 97\n3 1 14",
"output": "371"
},
{
"input": "3\n2 1 63\n3 1 78",
"output": "204"
},
{
"input": "13\n8 2 58\n2 1 49\n13 10 41\n11 9 67\n6... | 1,657,624,108 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define pb push_back
#define INF (int)10e9
#define MOD (int)10e9 + 7
#define ll long long
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
vector<vector<pair<int, int> > > graph;
vector<int> weight_subtree;
vector<bool... | Title: Eternal Victory
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal!
He decided to visit a... | ```python
#include <bits/stdc++.h>
#define pb push_back
#define INF (int)10e9
#define MOD (int)10e9 + 7
#define ll long long
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
vector<vector<pair<int, int> > > graph;
vector<int> weight_subtree;
v... | -1 |
348 | A | Mafia | PROGRAMMING | 1,600 | [
"binary search",
"math",
"sortings"
] | null | null | One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the min... | The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play. | In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"3\n3 2 2\n",
"4\n2 2 2 2\n"
] | [
"4\n",
"3\n"
] | You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | 500 | [
{
"input": "3\n3 2 2",
"output": "4"
},
{
"input": "4\n2 2 2 2",
"output": "3"
},
{
"input": "7\n9 7 7 8 8 7 8",
"output": "9"
},
{
"input": "10\n13 12 10 13 13 14 10 10 12 12",
"output": "14"
},
{
"input": "10\n94 96 91 95 99 94 96 92 95 99",
"output": "106"
... | 1,384,887,410 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 218 | 10,137,600 | n, t = int(input()), list(map(int, input().split()))
print(max(max(t), (sum(t) - 1) // (n - 1) + 1)) | Title: Mafia
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a... | ```python
n, t = int(input()), list(map(int, input().split()))
print(max(max(t), (sum(t) - 1) // (n - 1) + 1))
``` | 3 | |
909 | A | Generate Login | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"sortings"
] | null | null | The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and ... | The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. | Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. | [
"harry potter\n",
"tom riddle\n"
] | [
"hap\n",
"tomr\n"
] | none | 500 | [
{
"input": "harry potter",
"output": "hap"
},
{
"input": "tom riddle",
"output": "tomr"
},
{
"input": "a qdpinbmcrf",
"output": "aq"
},
{
"input": "wixjzniiub ssdfodfgap",
"output": "wis"
},
{
"input": "z z",
"output": "zz"
},
{
"input": "ertuyivhfg v"... | 1,663,487,277 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | s = input().split()
s1 = ''
count = 0
num = 0
for i in s[0]:
if count == 0:
s1 += i
count += 1
num = ord(i)
else:
if num >= ord(i):
num = ord(i)
s1 += i
else:
break
count = 0
num = 0
print(s1 + s[1][0]) | Title: Generate Login
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the fu... | ```python
s = input().split()
s1 = ''
count = 0
num = 0
for i in s[0]:
if count == 0:
s1 += i
count += 1
num = ord(i)
else:
if num >= ord(i):
num = ord(i)
s1 += i
else:
break
count = 0
num = 0
print(s1 + s[1][0])
``` | 0 | |
919 | B | Perfect Number | PROGRAMMING | 1,100 | [
"binary search",
"brute force",
"dp",
"implementation",
"number theory"
] | null | null | We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. | A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). | A single number, denoting the $k$-th smallest perfect integer. | [
"1\n",
"2\n"
] | [
"19\n",
"28\n"
] | The first perfect integer is $19$ and the second one is $28$. | 750 | [
{
"input": "1",
"output": "19"
},
{
"input": "2",
"output": "28"
},
{
"input": "13",
"output": "136"
},
{
"input": "101",
"output": "1432"
},
{
"input": "1023",
"output": "100270"
},
{
"input": "9999",
"output": "10800010"
},
{
"input": "10... | 1,697,954,613 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 311 | 3,174,400 | import math
def solve():
k = int(input())
start = 10
cnt = 0
while cnt < k:
start += 9
if sum(list(map(int, str(start)))) == 10:
cnt += 1
print(start)
if __name__ == '__main__':
solve()
| Title: Perfect Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
Input Specification:
A singl... | ```python
import math
def solve():
k = int(input())
start = 10
cnt = 0
while cnt < k:
start += 9
if sum(list(map(int, str(start)))) == 10:
cnt += 1
print(start)
if __name__ == '__main__':
solve()
``` | 3 | |
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,591,870,042 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 78 | 0 | n,m=map(int,input().split())
k1=[int(x) for x in input().split()]
k2=[int(x) for x in input().split()]
k3=[]
c=len(k1)
[k3.append(i) for i in k2 if i not in k3]
for i in k1:
if i in k3:c-=1
print(c)
| 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())
k1=[int(x) for x in input().split()]
k2=[int(x) for x in input().split()]
k3=[]
c=len(k1)
[k3.append(i) for i in k2 if i not in k3]
for i in k1:
if i in k3:c-=1
print(c)
``` | 0 | |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,696,925,334 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 92 | 0 | n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
x=0
for i in range(len(a)):
if x>sum(a)-x:
print(i)
break
else:
x+=a[i]
else:
print(n)
| Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
x=0
for i in range(len(a)):
if x>sum(a)-x:
print(i)
break
else:
x+=a[i]
else:
print(n)
``` | 3 | |
622 | B | The Time | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read more about 24-hour format here [https://en.wikipedia.org/wiki/24-hour_clock](https://en.wikipedi... | The first line contains the current time in the format hh:mm (0<=≤<=*hh*<=<<=24,<=0<=≤<=*mm*<=<<=60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes).
The second line contains integer *a* (0<=≤<=*a*<=≤<=104) — the number of the minutes... | The only line should contain the time after *a* minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed).
See the examples to check the input/output format. | [
"23:59\n10\n",
"20:20\n121\n",
"10:10\n0\n"
] | [
"00:09\n",
"22:21\n",
"10:10\n"
] | none | 0 | [
{
"input": "23:59\n10",
"output": "00:09"
},
{
"input": "20:20\n121",
"output": "22:21"
},
{
"input": "10:10\n0",
"output": "10:10"
},
{
"input": "12:34\n10000",
"output": "11:14"
},
{
"input": "00:00\n10000",
"output": "22:40"
},
{
"input": "00:00\n14... | 1,644,591,590 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | a,b = map(int,input().split(":"))
c = int(input())
total = (a*60+b+c)%1440
h = total//60
m = total-(60*h)
if m<10:
print(str(h)+":"+"0"+str(m))
else:
print(str(h)+":"+str(m)) | Title: The Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read mo... | ```python
a,b = map(int,input().split(":"))
c = int(input())
total = (a*60+b+c)%1440
h = total//60
m = total-(60*h)
if m<10:
print(str(h)+":"+"0"+str(m))
else:
print(str(h)+":"+str(m))
``` | 0 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,691,074,161 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 62 | 921,600 | import string
v=list(string.ascii_lowercase)
v2="a"+input();c=0
for i in range(len(v2)-1):
w=abs(v.index(v2[i])-v.index(v2[i+1]))
if w<26-w:
c+=w
else:
c+=26-w
print(c) | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
import string
v=list(string.ascii_lowercase)
v2="a"+input();c=0
for i in range(len(v2)-1):
w=abs(v.index(v2[i])-v.index(v2[i+1]))
if w<26-w:
c+=w
else:
c+=26-w
print(c)
``` | 3 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,473,591,733 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 124 | 0 | d = {}
m = 0
w = ''
for i in range(int(input())):
n, s = input().split()
s = int(s)
if n in d:
d[n] += s
else:
d[n] = s
t = max(d.values())
if t > m:
m = t
w = n
print(w)
| Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
d = {}
m = 0
w = ''
for i in range(int(input())):
n, s = input().split()
s = int(s)
if n in d:
d[n] += s
else:
d[n] = s
t = max(d.values())
if t > m:
m = t
w = n
print(w)
``` | 0 |
120 | B | Quiz League | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=1000 and 1<=≤<=*k*<=≤<=*n*) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains *n* numbers: *a**i*<==<=0 if the question from sector *i* has already been asked and *a**i*<==<=1 ... | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | [
"5 5\n0 1 0 1 0\n",
"2 1\n1 1\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "5 5\n0 1 0 1 0",
"output": "2"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "3 2\n1 0 0",
"output": "1"
},
{
"input": "3 3\n0 1 0",
"output": "2"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "6 3\n0 0 1 1 0 1",
"output":... | 1,543,496,574 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 109 | 0 | f = open("input.txt","r")
f1 = open("output.txt","w")
n,k = map(str,f.readline().split())
a = list(map(str,f.readline().split()))
n,k = int(n),int(k); l = 1
if a[k-1] == "1": f1.write(str(k))
else:
for i in range(k,n):
if a[i] == "1" and l: f1.write(str(i+1)); l = 0
for i in range(k):
... | Title: Quiz League
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a quest... | ```python
f = open("input.txt","r")
f1 = open("output.txt","w")
n,k = map(str,f.readline().split())
a = list(map(str,f.readline().split()))
n,k = int(n),int(k); l = 1
if a[k-1] == "1": f1.write(str(k))
else:
for i in range(k,n):
if a[i] == "1" and l: f1.write(str(i+1)); l = 0
for i in range(k):... | 3 | |
948 | A | Protect Sheep | PROGRAMMING | 900 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or... | First line contains two integers *R* (1<=≤<=*R*<=≤<=500) and *C* (1<=≤<=*C*<=≤<=500), denoting the number of rows and the numbers of columns respectively.
Each of the following *R* lines is a string consisting of exactly *C* characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' a... | If it is impossible to protect all sheep, output a single line with the word "No".
Otherwise, output a line with the word "Yes". Then print *R* lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a she... | [
"6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n",
"1 2\nSW\n",
"5 5\n.S...\n...S.\nS....\n...S.\n.S...\n"
] | [
"Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......\n",
"No\n",
"Yes\n.S...\n...S.\nS.D..\n...S.\n.S...\n"
] | In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.
In the second example, there are no empty spots to put dogs that would guard the lone sheep.
In the third example, there are no wolves... | 500 | [
{
"input": "1 2\nSW",
"output": "No"
},
{
"input": "10 10\n....W.W.W.\n.........S\n.S.S...S..\nW.......SS\n.W..W.....\n.W...W....\nS..S...S.S\n....W...S.\n..S..S.S.S\nSS.......S",
"output": "Yes\nDDDDWDWDWD\nDDDDDDDDDS\nDSDSDDDSDD\nWDDDDDDDSS\nDWDDWDDDDD\nDWDDDWDDDD\nSDDSDDDSDS\nDDDDWDDDSD\nDDSD... | 1,619,578,794 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def main():
r,c = map(int, input().split(' '))
s = []
w = []
r_dir = [1,-1,0,0]
c_dir = [0,0,1,-1]
for i in range(r):
inpt = input()
for j in range(c):
if inpt[j] == "S":
s.append([i,j])
elif inpt[j] == "W":
w.ap... | Title: Protect Sheep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is ... | ```python
def main():
r,c = map(int, input().split(' '))
s = []
w = []
r_dir = [1,-1,0,0]
c_dir = [0,0,1,-1]
for i in range(r):
inpt = input()
for j in range(c):
if inpt[j] == "S":
s.append([i,j])
elif inpt[j] == "W":
... | 0 | |
552 | D | Vanya and Triangles | PROGRAMMING | 1,900 | [
"brute force",
"combinatorics",
"data structures",
"geometry",
"math",
"sortings"
] | null | null | Vanya got bored and he painted *n* distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area. | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of the points painted on the plane.
Next *n* lines contain two integers each *x**i*,<=*y**i* (<=-<=100<=≤<=*x**i*,<=*y**i*<=≤<=100) — the coordinates of the *i*-th point. It is guaranteed that no two given points coincide. | In the first line print an integer — the number of triangles with the non-zero area among the painted points. | [
"4\n0 0\n1 1\n2 0\n2 2\n",
"3\n0 0\n1 1\n2 0\n",
"1\n1 1\n"
] | [
"3\n",
"1\n",
"0\n"
] | Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle. | 2,000 | [
{
"input": "4\n0 0\n1 1\n2 0\n2 2",
"output": "3"
},
{
"input": "3\n0 0\n1 1\n2 0",
"output": "1"
},
{
"input": "1\n1 1",
"output": "0"
},
{
"input": "5\n0 0\n1 1\n2 2\n3 3\n4 4",
"output": "0"
},
{
"input": "5\n0 0\n1 1\n2 3\n3 6\n4 10",
"output": "10"
},
... | 1,538,020,557 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 307,200 | import itertools
n=int(input())
c=[]
for x in range(n):
c.append(input())
d=dict()
for z in list(itertools.combinations(c,2)):
z0x,z0y=map(int,z[0].split())
z1x,z1y=map(int,z[1].split())
datos=[]
m=(z1y-z0y)/(z1x-z0x) if (z1x-z0x)!=0 else "v"
b=z0y-m*z0x if m!="v" else z0x
try:
d[(m,b)]+=1
exc... | Title: Vanya and Triangles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got bored and he painted *n* distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you t... | ```python
import itertools
n=int(input())
c=[]
for x in range(n):
c.append(input())
d=dict()
for z in list(itertools.combinations(c,2)):
z0x,z0y=map(int,z[0].split())
z1x,z1y=map(int,z[1].split())
datos=[]
m=(z1y-z0y)/(z1x-z0x) if (z1x-z0x)!=0 else "v"
b=z0y-m*z0x if m!="v" else z0x
try:
d[(m,b)... | 0 | |
960 | A | Check the string | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gi... | The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'. | Print "YES" or "NO", according to the condition. | [
"aaabccc\n",
"bbacc\n",
"aabc\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | Consider first example: the number of 'c' is equal to the number of 'a'.
Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.
Consider third example: the number of 'c' is equal to the number of 'b'. | 500 | [
{
"input": "aaabccc",
"output": "YES"
},
{
"input": "bbacc",
"output": "NO"
},
{
"input": "aabc",
"output": "YES"
},
{
"input": "aabbcc",
"output": "YES"
},
{
"input": "aaacccbb",
"output": "NO"
},
{
"input": "abc",
"output": "YES"
},
{
"in... | 1,523,470,589 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 186 | 7,065,600 | s = input()
x=1
for i in range(len(s)-1):
if s[i]=='b' and s[i+1]=='a':
x=0
break
elif s[i]=='c' and s[i+1]=='a':
x=0
break
elif s[i]=='c' and s[i+1]=='b':
x=0
break
else:
if s.count('a')==s.count('b') or s.count('b')==s.count('c') or ... | Title: Check the string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b... | ```python
s = input()
x=1
for i in range(len(s)-1):
if s[i]=='b' and s[i+1]=='a':
x=0
break
elif s[i]=='c' and s[i+1]=='a':
x=0
break
elif s[i]=='c' and s[i+1]=='b':
x=0
break
else:
if s.count('a')==s.count('b') or s.count('b')==s.coun... | 0 | |
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
... | 1,690,394,650 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n = int(input())
wgt = [int(i) for i in input().split()]
for i in range(2):
del wgt[wgt.index(max(wgt))]
summ = 0
for i in range(int(len(wgt)/2)):
summ += wgt[len(wgt) - 1 - i] - wgt[i]
print(summ) | Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they hav... | ```python
n = int(input())
wgt = [int(i) for i in input().split()]
for i in range(2):
del wgt[wgt.index(max(wgt))]
summ = 0
for i in range(int(len(wgt)/2)):
summ += wgt[len(wgt) - 1 - i] - wgt[i]
print(summ)
``` | 0 | |
274 | A | k-Multiple Free Set | PROGRAMMING | 1,500 | [
"binary search",
"greedy",
"sortings"
] | null | null | A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<==<=*x*·*k*.
You're given a set of *n* distinct positive integers. Your task is to find th... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
All the numbers in the lines are separated by single spaces. | On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}. | [
"6 2\n2 3 6 5 4 10\n"
] | [
"3\n"
] | In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | 500 | [
{
"input": "6 2\n2 3 6 5 4 10",
"output": "3"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "6"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 1... | 1,585,039,774 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 1,964 | 12,083,200 | n, k = map(int,input().split())
a = sorted(list(map(int,input().split())))
ans= []
for i in range(n) :
if a[i] % k != 0 :
ans.append(a[i])
else :
if a[i] // k not in ans :
ans.append(a[i])
print(len(ans)) | Title: k-Multiple Free Set
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, ... | ```python
n, k = map(int,input().split())
a = sorted(list(map(int,input().split())))
ans= []
for i in range(n) :
if a[i] % k != 0 :
ans.append(a[i])
else :
if a[i] // k not in ans :
ans.append(a[i])
print(len(ans))
``` | 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,648,053,560 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using Multiset = tree<T,... | 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
#include<bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using Multiset... | -1 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,679,142,080 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | a, b = map(int, input().split())
pairs = min(a, b) // 2
remaining_socks = max(a, b) - 2 * pairs
same_socks_days = remaining_socks // 2 if remaining_socks > 0 else 0
different_socks_days = pairs
print(different_socks_days, same_socks_days)
| Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
a, b = map(int, input().split())
pairs = min(a, b) // 2
remaining_socks = max(a, b) - 2 * pairs
same_socks_days = remaining_socks // 2 if remaining_socks > 0 else 0
different_socks_days = pairs
print(different_socks_days, same_socks_days)
``` | 0 | |
62 | A | A Student's Dream | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | A. A Student's Dream | 2 | 256 | Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.
A poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the most formidable profess... | The first line contains two positive integers not exceeding 100. They are the number of fingers on the Venusian girl's left and right hand correspondingly. The second line contains two integers not exceeding 100. They are the number of fingers on the Marsian boy's left and right hands correspondingly. | Print YES or NO, that is, the answer to Petr Palych's question. | [
"5 1\n10 5\n",
"4 5\n3 3\n",
"1 2\n11 6\n"
] | [
"YES",
"YES",
"NO"
] | The boy and the girl don't really care who goes to the left. | 500 | [
{
"input": "5 1\n10 5",
"output": "YES"
},
{
"input": "4 5\n3 3",
"output": "YES"
},
{
"input": "1 2\n11 6",
"output": "NO"
},
{
"input": "1 1\n1 1",
"output": "YES"
},
{
"input": "2 2\n1 1",
"output": "YES"
},
{
"input": "3 3\n1 1",
"output": "NO"... | 1,384,256,255 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 92 | 307,200 | m,n=map(int,input().split())
k,p=map(int,input().split())
l=0
if (m-p>1)or(p-m>2):
l+=1
if (n-k>1)or(k-n>2):
l+=1
if l>1:
print('NO')
else:print('YES') | Title: A Student's Dream
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.
A poor student is dreaming t... | ```python
m,n=map(int,input().split())
k,p=map(int,input().split())
l=0
if (m-p>1)or(p-m>2):
l+=1
if (n-k>1)or(k-n>2):
l+=1
if l>1:
print('NO')
else:print('YES')
``` | 0 |
960 | A | Check the string | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gi... | The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'. | Print "YES" or "NO", according to the condition. | [
"aaabccc\n",
"bbacc\n",
"aabc\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | Consider first example: the number of 'c' is equal to the number of 'a'.
Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.
Consider third example: the number of 'c' is equal to the number of 'b'. | 500 | [
{
"input": "aaabccc",
"output": "YES"
},
{
"input": "bbacc",
"output": "NO"
},
{
"input": "aabc",
"output": "YES"
},
{
"input": "aabbcc",
"output": "YES"
},
{
"input": "aaacccbb",
"output": "NO"
},
{
"input": "abc",
"output": "YES"
},
{
"in... | 1,524,403,645 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 78 | 7,065,600 | def perform():
text = input()
if text[0] != 'a':
return 'NO'
i = 0
char = text[i]
while char == 'a':
i+=1
char = text[i]
if text[i] == 'c':
return 'NO'
number_of_a = text.count('a')
number_of_b = text.count('b')
number_of_c = text.co... | Title: Check the string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b... | ```python
def perform():
text = input()
if text[0] != 'a':
return 'NO'
i = 0
char = text[i]
while char == 'a':
i+=1
char = text[i]
if text[i] == 'c':
return 'NO'
number_of_a = text.count('a')
number_of_b = text.count('b')
number_of_c... | 0 | |
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water... | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the f... | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 ... | 1,645,538,629 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
print(l)
s=0
if n==0:
print("0")
else:
for i in range(12):
s=s+l[i]
if s>=n:
print(i+1)
break
if sum(l)<n:
print("-1")
| Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya open... | ```python
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
print(l)
s=0
if n==0:
print("0")
else:
for i in range(12):
s=s+l[i]
if s>=n:
print(i+1)
break
if sum(l)<n:
print("-1")
``` | 0 | |
914 | A | Perfect Squares | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — the elements of the array.
It is guaranteed that at least one element of the array is not a perfect square. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | [
"2\n4 2\n",
"8\n1 2 4 8 16 32 64 576\n"
] | [
"2\n",
"32\n"
] | In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | 500 | [
{
"input": "2\n4 2",
"output": "2"
},
{
"input": "8\n1 2 4 8 16 32 64 576",
"output": "32"
},
{
"input": "3\n-1 -4 -9",
"output": "-1"
},
{
"input": "5\n918375 169764 598796 76602 538757",
"output": "918375"
},
{
"input": "5\n804610 765625 2916 381050 93025",
... | 1,638,301,071 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 31 | 0 | n = int(input())
d = list(map(int, input().split()))
mx = 0
for i in range(len(d)):
if (int(d[i] ** 0.5) * int(d[i] ** 0.5) != d[i]) and (d[i] > mx):
mx = d[i]
print(mx)
| Title: Perfect Squares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<... | ```python
n = int(input())
d = list(map(int, input().split()))
mx = 0
for i in range(len(d)):
if (int(d[i] ** 0.5) * int(d[i] ** 0.5) != d[i]) and (d[i] > mx):
mx = d[i]
print(mx)
``` | -1 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of *m* points *p*1,<=*p*2,<=...,<=*p**m* with integer coordinates, do the following: denote its initial location by *p*0. First, the robot will move from *p*0 to *p*1 along one of the shortest paths betwe... | The first line of input contains the only positive integer *n* (1<=≤<=*n*<=≤<=2·105) which equals the number of unit segments the robot traveled. The second line contains the movements protocol, which consists of *n* letters, each being equal either L, or R, or U, or D. *k*-th letter stands for the direction which Robo... | The only line of input should contain the minimum possible length of the sequence. | [
"4\nRURD\n",
"6\nRRULDD\n",
"26\nRRRULURURUULULLLDLDDRDRDLD\n",
"3\nRLL\n",
"4\nLRLR\n"
] | [
"2\n",
"2\n",
"7\n",
"2\n",
"4\n"
] | The illustrations to the first three tests are given below.
<img class="tex-graphics" src="https://espresso.codeforces.com/832fb8f97a482be815e0f87edde26c9791a0d330.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/119a8ba68772b2c2bf76f2acdc58027f6c5cde1... | 0 | [
{
"input": "4\nRURD",
"output": "2"
},
{
"input": "6\nRRULDD",
"output": "2"
},
{
"input": "26\nRRRULURURUULULLLDLDDRDRDLD",
"output": "7"
},
{
"input": "3\nRLL",
"output": "2"
},
{
"input": "4\nLRLR",
"output": "4"
},
{
"input": "5\nLRDLR",
"outpu... | 1,560,777,923 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 186 | 409,600 | n = int(input())
s = input()
res, c1, c2 = 1, '', ''
for i in range(len(s)):
if s[i] in 'UD':
if c1 != '' and c1 != s[i]:
res += 1
c1 = s[i]
c2 = ''
elif c1 == '':
c1 = s[i]
else:
if c2 != '' and c2 != s[i]:
res += ... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of *m* points *p*1,<=*p*2,<=...,<=*p**m* with integer coordinates, do the following: denote its initial location b... | ```python
n = int(input())
s = input()
res, c1, c2 = 1, '', ''
for i in range(len(s)):
if s[i] in 'UD':
if c1 != '' and c1 != s[i]:
res += 1
c1 = s[i]
c2 = ''
elif c1 == '':
c1 = s[i]
else:
if c2 != '' and c2 != s[i]:
... | 3 | |
760 | A | Petr and a calendar | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
Petr wants to ... | The only line contain two integers *m* and *d* (1<=≤<=*m*<=≤<=12, 1<=≤<=*d*<=≤<=7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday). | Print single integer: the number of columns the table should have. | [
"1 7\n",
"1 1\n",
"11 6\n"
] | [
"6\n",
"5\n",
"5\n"
] | The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough. | 500 | [
{
"input": "1 7",
"output": "6"
},
{
"input": "1 1",
"output": "5"
},
{
"input": "11 6",
"output": "5"
},
{
"input": "2 7",
"output": "5"
},
{
"input": "2 1",
"output": "4"
},
{
"input": "8 6",
"output": "6"
},
{
"input": "1 1",
"output... | 1,485,109,910 | 1,010 | Python 3 | OK | TESTS | 104 | 109 | 4,710,400 | def check_month(day, month):
return sum(months[:month]) <= day < sum(months[:month + 1])
A = [0] * 365
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(365):
A[i] = i % 7
m, d = map(int, input().split())
m -= 1
first_day = 0
while not check_month(first_day, m):
... | Title: Petr and a calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells... | ```python
def check_month(day, month):
return sum(months[:month]) <= day < sum(months[:month + 1])
A = [0] * 365
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(365):
A[i] = i % 7
m, d = map(int, input().split())
m -= 1
first_day = 0
while not check_month(first_day... | 3 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,652,353,794 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 3 | 124 | 0 | def solve():
n = int(input())
if 360 % (180 - n) == 0:
return "YES"
else:
return "NO"
for i in range(int(input())):
print(solve()) | Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can... | ```python
def solve():
n = int(input())
if 360 % (180 - n) == 0:
return "YES"
else:
return "NO"
for i in range(int(input())):
print(solve())
``` | 3 | |
845 | B | Luba And The Ticket | PROGRAMMING | 1,600 | [
"brute force",
"greedy",
"implementation"
] | null | null | Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of las... | You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0. | Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky. | [
"000000\n",
"123456\n",
"111000\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one re... | 0 | [
{
"input": "000000",
"output": "0"
},
{
"input": "123456",
"output": "2"
},
{
"input": "111000",
"output": "1"
},
{
"input": "120111",
"output": "0"
},
{
"input": "999999",
"output": "0"
},
{
"input": "199880",
"output": "1"
},
{
"input": "... | 1,511,851,246 | 2,147,483,647 | Python 3 | OK | TESTS | 145 | 280 | 5,632,000 | s = [int(x) for x in input()]
ans = 6
k = 0
for d0 in range(10):
for d1 in range(10):
for d2 in range(10):
for d3 in range(10):
for d4 in range(10):
d5 = d0 + d1 + d2 - d3 - d4
if 0 <= d5 <= 9:
d = [d0,d1,d... | Title: Luba And The Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make th... | ```python
s = [int(x) for x in input()]
ans = 6
k = 0
for d0 in range(10):
for d1 in range(10):
for d2 in range(10):
for d3 in range(10):
for d4 in range(10):
d5 = d0 + d1 + d2 - d3 - d4
if 0 <= d5 <= 9:
d ... | 3 | |
998 | A | Balloons | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation"
] | null | null | There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $n$ packets with inflatable balloons, where $i$-th of them has exactly $a_i$ balloons insi... | The first line of input contains a single integer $n$ ($1 \le n \le 10$) — the number of packets with balloons.
The second line contains $n$ integers: $a_1$, $a_2$, $\ldots$, $a_n$ ($1 \le a_i \le 1000$) — the number of balloons inside the corresponding packet. | If it's impossible to divide the balloons satisfying the conditions above, print $-1$.
Otherwise, print an integer $k$ — the number of packets to give to Grigory followed by $k$ distinct integers from $1$ to $n$ — the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons... | [
"3\n1 2 1\n",
"2\n5 5\n",
"1\n10\n"
] | [
"2\n1 2\n",
"-1\n",
"-1\n"
] | In the first test Grigory gets $3$ balloons in total while Andrey gets $1$.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all. | 500 | [
{
"input": "3\n1 2 1",
"output": "1\n1"
},
{
"input": "2\n5 5",
"output": "-1"
},
{
"input": "1\n10",
"output": "-1"
},
{
"input": "1\n1",
"output": "-1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "1\n1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 9",... | 1,626,718,453 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 62 | 20,172,800 |
n = int(input())
a = [int(x) for x in input().split()]
ans = -1
i = 0
while i < n-1:
print(sum(a[:i+1]), sum(a[i+1:]))
if sum(a[:i+1]) != sum(a[i+1:]):
break
i += 1
else:
print(-1)
exit()
print(len(a[:i+1]))
print(*(x for x in range(1, i+2)))
| Title: Balloons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bou... | ```python
n = int(input())
a = [int(x) for x in input().split()]
ans = -1
i = 0
while i < n-1:
print(sum(a[:i+1]), sum(a[i+1:]))
if sum(a[:i+1]) != sum(a[i+1:]):
break
i += 1
else:
print(-1)
exit()
print(len(a[:i+1]))
print(*(x for x in range(1, i+2)))
``` | 0 | |
485 | B | Valuable Resources | PROGRAMMING | 1,300 | [
"brute force",
"greedy"
] | null | null | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes.... | The first line of the input contains number *n* — the number of mines on the map (2<=≤<=*n*<=≤<=1000). Each of the next *n* lines contains a pair of integers *x**i* and *y**i* — the coordinates of the corresponding mine (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109). All points are pairwise distinct. | Print the minimum area of the city that can cover all the mines with valuable resources. | [
"2\n0 0\n2 2\n",
"2\n0 0\n0 3\n"
] | [
"4\n",
"9\n"
] | none | 500 | [
{
"input": "2\n0 0\n2 2",
"output": "4"
},
{
"input": "2\n0 0\n0 3",
"output": "9"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "3\n2 2\n1 1\n3 3",
"output": "4"
},
{
"input": "3\n3 1\n1 3\n2 2",
"output": "4"
},
{
"input": "3\n0 1\n1 0\n2 ... | 1,541,693,919 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 108 | 0 | def splIn():
return list(map(int,input().split()))
n = int(input())
firstxy = splIn()
xmin = firstxy[0]
xmax = firstxy[0]
ymin = firstxy[1]
ymax = firstxy[1]
for i in range(n-1):
xy = splIn()
if xy[0]>xmax:
xmax = xy[0]
if xy[0]<xmin:
xmin = xy[0]
if xy[1]>ymax:
ymax = xy[1]
if xy[1]<ymin:
... | Title: Valuable Resources
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. Th... | ```python
def splIn():
return list(map(int,input().split()))
n = int(input())
firstxy = splIn()
xmin = firstxy[0]
xmax = firstxy[0]
ymin = firstxy[1]
ymax = firstxy[1]
for i in range(n-1):
xy = splIn()
if xy[0]>xmax:
xmax = xy[0]
if xy[0]<xmin:
xmin = xy[0]
if xy[1]>ymax:
ymax = xy[1]
if xy... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. ... | The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants | Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | 0 | [
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
... | 1,511,415,702 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 62 | 0 | num1,num2,num3,num4,num5,num6 =input().split()
num1=int(num1)
num2=int(num2)
num3=int(num3)
num4=int(num4)
num5=int(num5)
num6=int(num6)
if num1+num2+num3==num4+num5+num6 or num1+num3+num5==num2+num4+num6 or num2+num3+num4==num1+num5+num6 or num3+num4+num5==num1+num2+num6 or num1+num3+num4==num2+num5+num6 or num... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exac... | ```python
num1,num2,num3,num4,num5,num6 =input().split()
num1=int(num1)
num2=int(num2)
num3=int(num3)
num4=int(num4)
num5=int(num5)
num6=int(num6)
if num1+num2+num3==num4+num5+num6 or num1+num3+num5==num2+num4+num6 or num2+num3+num4==num1+num5+num6 or num3+num4+num5==num1+num2+num6 or num1+num3+num4==num2+num5+n... | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,577,523,290 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 0 | n1=list(input())
n2=list(input())
l=[]
for i in range(len(n1)-1,-1,-1):
if n1[i]!=n2[i]:
l.append("1")
else:
l.append("0")
#print(l)
print(int("".join(l[::-1])))
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
n1=list(input())
n2=list(input())
l=[]
for i in range(len(n1)-1,-1,-1):
if n1[i]!=n2[i]:
l.append("1")
else:
l.append("0")
#print(l)
print(int("".join(l[::-1])))
``` | 0 |
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy start... | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second lin... | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fanta... | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
... | 1,630,944,225 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 6,963,200 |
def solve():
s_main = input()
s1 = input()
s2 = input()
second = s1 + s2
#print(second)
len1 = len(s_main);len2 = len(second)
c1 = 0;s = 0
while c1 < len2 and s < len1:
if second[c1] == s_main[s]:
s+=1;c1+=1
else:
s+=1
c2 = len2 - 1;s =... | Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the... | ```python
def solve():
s_main = input()
s1 = input()
s2 = input()
second = s1 + s2
#print(second)
len1 = len(s_main);len2 = len(second)
c1 = 0;s = 0
while c1 < len2 and s < len1:
if second[c1] == s_main[s]:
s+=1;c1+=1
else:
s+=1
c2 = le... | 0 |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,614,506,832 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 61 | 307,200 | word = input().lower()
word1 = word.replace(word[:word.find('h')],'')
if len(word1[1:word1.find('e')]) == 1 and word1[1:word1.find('e')] == 'h':
word2 = word1[1:]
else:
word2 = word1.replace(word1[1:word1.find('e')],'')
if len(word2[2:word2.find('l')]) == 1 and word2[2:word2.find('l')] == ... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
word = input().lower()
word1 = word.replace(word[:word.find('h')],'')
if len(word1[1:word1.find('e')]) == 1 and word1[1:word1.find('e')] == 'h':
word2 = word1[1:]
else:
word2 = word1.replace(word1[1:word1.find('e')],'')
if len(word2[2:word2.find('l')]) == 1 and word2[2:word2.find... | -1 |
876 | A | Trip For Meal | PROGRAMMING | 900 | [
"math"
] | null | null | Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's ... | First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits.
Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses.
Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses.
Fourth line contains an integer *c* ... | Output one number — minimum distance in meters Winnie must go through to have a meal *n* times. | [
"3\n2\n3\n1\n",
"1\n2\n3\n5\n"
] | [
"3\n",
"0\n"
] | In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.
In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all. | 500 | [
{
"input": "3\n2\n3\n1",
"output": "3"
},
{
"input": "1\n2\n3\n5",
"output": "0"
},
{
"input": "10\n1\n8\n3",
"output": "9"
},
{
"input": "7\n10\n5\n6",
"output": "30"
},
{
"input": "9\n9\n7\n5",
"output": "42"
},
{
"input": "9\n37\n85\n76",
"outpu... | 1,518,431,946 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 62 | 5,632,000 | n=int(input())
a=int(input())
b=int(input())
c=int(input())
sum=0
while n>1:
n-=1
sum+=min(a,b)
if min(a,b)==a:
b=c
else:
a=c
print(sum)
| Title: Trip For Meal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair... | ```python
n=int(input())
a=int(input())
b=int(input())
c=int(input())
sum=0
while n>1:
n-=1
sum+=min(a,b)
if min(a,b)==a:
b=c
else:
a=c
print(sum)
``` | 3 | |
835 | B | The number on the board | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbe... | The first line contains integer *k* (1<=≤<=*k*<=≤<=109).
The second line contains integer *n* (1<=≤<=*n*<=<<=10100000).
There are no leading zeros in *n*. It's guaranteed that this situation is possible. | Print the minimum number of digits in which the initial number and *n* can differ. | [
"3\n11\n",
"3\n99\n"
] | [
"1\n",
"0\n"
] | In the first example, the initial number could be 12.
In the second example the sum of the digits of *n* is not less than *k*. The initial number could be equal to *n*. | 750 | [
{
"input": "3\n11",
"output": "1"
},
{
"input": "3\n99",
"output": "0"
},
{
"input": "10\n5205602270",
"output": "0"
},
{
"input": "70\n3326631213",
"output": "6"
},
{
"input": "200\n100000001000000000000000000001000000000000000100000100000000000000000000000000000... | 1,577,013,979 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 7 | 109 | 0 | n=int(input())
j=str(input())
u=list(j)
r=0
for i in range(len(u)):
r+=int(u[i])
if n<=r:
print(0)
else:
i=0
sun=0
u.sort()
while sun<=abs(r-n):
sun+=9-int(u[i])
i+=1
print(i)
| Title: The number on the board
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that th... | ```python
n=int(input())
j=str(input())
u=list(j)
r=0
for i in range(len(u)):
r+=int(u[i])
if n<=r:
print(0)
else:
i=0
sun=0
u.sort()
while sun<=abs(r-n):
sun+=9-int(u[i])
i+=1
print(i)
``` | -1 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,693,718,133 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | a,b = map(int,input().split())
ms = min(a,b)
md = ms
rr = a - ms
rb = b - ms
sd(rr + rb) // 2
print(md,sd) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
a,b = map(int,input().split())
ms = min(a,b)
md = ms
rr = a - ms
rb = b - ms
sd(rr + rb) // 2
print(md,sd)
``` | -1 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,675,798,418 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 93 | 2,867,200 | import string
w = input()
a = abs(string.ascii_lowercase.index(w[0]))
b = 26 - string.ascii_lowercase.index(w[0])
count = min(a, b)
for i in range(1, len(w)):
a, b = string.ascii_lowercase.index(w[i - 1]), string.ascii_lowercase.index(w[i])
c = abs(a - b)
d = 26 - max(a, b) + min(a, b)
coun... | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
import string
w = input()
a = abs(string.ascii_lowercase.index(w[0]))
b = 26 - string.ascii_lowercase.index(w[0])
count = min(a, b)
for i in range(1, len(w)):
a, b = string.ascii_lowercase.index(w[i - 1]), string.ascii_lowercase.index(w[i])
c = abs(a - b)
d = 26 - max(a, b) + min(a, b)... | 3 | |
637 | C | Promocodes with Mistakes | PROGRAMMING | 1,400 | [
"*special",
"brute force",
"constructive algorithms",
"implementation"
] | null | null | During a New Year special offer the "Sudislavl Bars" offered *n* promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ.
As the "Mosquito Shelter" opens only at 9, and partying in Sudislavl usually begins at a... | The first line of the output contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of promocodes.
Each of the next *n* lines contains a single promocode, consisting of exactly 6 digits. It is guaranteed that all the promocodes are distinct. Promocodes can start from digit "0". | Print the maximum *k* (naturally, not exceeding the length of the promocode), such that any promocode can be uniquely identified if it is typed with at most *k* mistakes. | [
"2\n000000\n999999\n",
"6\n211111\n212111\n222111\n111111\n112111\n121111\n"
] | [
"2\n",
"0\n"
] | In the first sample *k* < 3, so if a bar customer types in value "090909", then it will be impossible to define which promocode exactly corresponds to it. | 1,500 | [
{
"input": "2\n000000\n999999",
"output": "2"
},
{
"input": "6\n211111\n212111\n222111\n111111\n112111\n121111",
"output": "0"
},
{
"input": "1\n123456",
"output": "6"
},
{
"input": "2\n000000\n099999",
"output": "2"
},
{
"input": "2\n000000\n009999",
"output"... | 1,510,832,410 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | s, r = 12, range(int(input()))
t = [input() for i in r]
for i in r:
for j in r[i + 1:]: s = min(s, sum(x != y for x, y in zip(t[i], t[j])))
print(s >> 1) | Title: Promocodes with Mistakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During a New Year special offer the "Sudislavl Bars" offered *n* promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all th... | ```python
s, r = 12, range(int(input()))
t = [input() for i in r]
for i in r:
for j in r[i + 1:]: s = min(s, sum(x != y for x, y in zip(t[i], t[j])))
print(s >> 1)
``` | 0 | |
304 | B | Calendar | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap yea... | The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900<=≤<=*yyyy*<=≤<=2038 and yyyy:mm:dd is a legal date). | Print a single integer — the answer to the problem. | [
"1900:01:01\n2038:12:31\n",
"1996:03:09\n1991:11:12\n"
] | [
"50768\n",
"1579\n"
] | none | 1,000 | [
{
"input": "1900:01:01\n2038:12:31",
"output": "50768"
},
{
"input": "1996:03:09\n1991:11:12",
"output": "1579"
},
{
"input": "1999:12:31\n2000:02:29",
"output": "60"
},
{
"input": "1903:09:27\n1988:06:15",
"output": "30943"
},
{
"input": "1913:11:14\n1901:05:11",... | 1,650,488,092 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | from math import sqrt
months = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
def how_much_mod(b, e, x):
ans = int((e - b) // x)
if((e - 1) % x < b % x):
ans += 1
return ans
def vis(b, e):
return how_much_mod(f_y + 1, s_y, 4) - how_much_mod(f_y + 1, s_y, 100) + how_much_mod(f_y + 1, s_y,... | Title: Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's... | ```python
from math import sqrt
months = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
def how_much_mod(b, e, x):
ans = int((e - b) // x)
if((e - 1) % x < b % x):
ans += 1
return ans
def vis(b, e):
return how_much_mod(f_y + 1, s_y, 4) - how_much_mod(f_y + 1, s_y, 100) + how_much_mod(f_y... | 0 | |
165 | A | Supercentral Point | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*):
- point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=><=*x* and *y*'... | The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one spac... | Print the only number — the number of supercentral points of the given set. | [
"8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n",
"5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n"
] | [
"2\n",
"1\n"
] | In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0). | 500 | [
{
"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3",
"output": "2"
},
{
"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0",
"output": "1"
},
{
"input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1",
"output": "1"
},
{
"input": "25\n-651 897\n... | 1,598,438,055 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 310 | 307,200 | l,c=[],0
for _ in range(int(input())):
m,n=map(int,input().split())
l.append([m,n])
for i in range(len(l)):
f1=0
f2=0
f3=0
f4=0
for j in range(len(l)):
if i==j:
continue
if l[i][0] == l[j][0] and l[i][1] > l[j][1]:
f1=1
if l[i][0] == l[j][0] and l[i][1] < l[j][1]:
f2=1
if l[i][0]... | Title: Supercentral Point
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the give... | ```python
l,c=[],0
for _ in range(int(input())):
m,n=map(int,input().split())
l.append([m,n])
for i in range(len(l)):
f1=0
f2=0
f3=0
f4=0
for j in range(len(l)):
if i==j:
continue
if l[i][0] == l[j][0] and l[i][1] > l[j][1]:
f1=1
if l[i][0] == l[j][0] and l[i][1] < l[j][1]:
f2=1
... | 3 | |
27 | A | Next Test | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Next Test | 2 | 256 | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. | Output the required default value for the next test index. | [
"3\n1 7 2\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
... | 1,632,914,658 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 122 | 6,963,200 | # https://codeforces.com/problemset/problem/27/A
if __name__ == '__main__':
n = int(input())
A = list(map(int, input().split()))
A = sorted(A)
ans = 1
for i in range(n):
if ans == A[i]:
ans += 1
print(ans)
| Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the... | ```python
# https://codeforces.com/problemset/problem/27/A
if __name__ == '__main__':
n = int(input())
A = list(map(int, input().split()))
A = sorted(A)
ans = 1
for i in range(n):
if ans == A[i]:
ans += 1
print(ans)
``` | 3.95653 |
0 | none | none | none | 0 | [
"none"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 0 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,693,533,767 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 202 | 12,800,000 | from collections import Counter
n = int(input())
f = Counter(map(int, input().split()))
mx = max(f)+1
dp = [0]*mx
dp[1]=f[1]
for i in range(2, mx):
dp[i] = max(dp[i-1], dp[i-2] + f[i]*i)
print(dp[-1]) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make sev... | ```python
from collections import Counter
n = int(input())
f = Counter(map(int, input().split()))
mx = max(f)+1
dp = [0]*mx
dp[1]=f[1]
for i in range(2, mx):
dp[i] = max(dp[i-1], dp[i-2] + f[i]*i)
print(dp[-1])
``` | 3 | |
181 | A | Series of Crimes | PROGRAMMING | 800 | [
"brute force",
"geometry",
"implementation"
] | null | null | The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital.
The capital's main detective Polycarpus took a map and m... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly.
Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A charact... | Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. | [
"3 2\n.*\n..\n**\n",
"3 3\n*.*\n*..\n...\n"
] | [
"1 1\n",
"2 3\n"
] | none | 500 | [
{
"input": "3 2\n.*\n..\n**",
"output": "1 1"
},
{
"input": "2 5\n*....\n*...*",
"output": "1 5"
},
{
"input": "7 2\n..\n**\n..\n..\n..\n..\n.*",
"output": "7 1"
},
{
"input": "7 2\n*.\n..\n..\n..\n..\n..\n**",
"output": "1 2"
},
{
"input": "2 10\n*......*..\n....... | 1,585,691,068 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 218 | 307,200 | n,m=map(int,input().split())
l2=[]
xa=0
ya=0
for i in range(n):
l=list(x for x in input())
v=l.count("*")
if(v==1):
xa=i+1
ya=l.index("*")+1
if(v==2):
for j in range(m):
if(l[j]=="*"):
l2.append(j+1)
#print(l2)
#print(xa,... | Title: Series of Crimes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the ma... | ```python
n,m=map(int,input().split())
l2=[]
xa=0
ya=0
for i in range(n):
l=list(x for x in input())
v=l.count("*")
if(v==1):
xa=i+1
ya=l.index("*")+1
if(v==2):
for j in range(m):
if(l[j]=="*"):
l2.append(j+1)
#print(l2)
... | 3 | |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,685,601,402 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | b=q=0
for y in[0]*int(input()):q-=eval(input().replace(' ','-'));b=max(b,q)
print(b) | Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
b=q=0
for y in[0]*int(input()):q-=eval(input().replace(' ','-'));b=max(b,q)
print(b)
``` | 3 | |
266 | A | Stones on the Table | PROGRAMMING | 800 | [
"implementation"
] | null | null | There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red... | Print a single integer — the answer to the problem. | [
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] | [
"1\n",
"4\n",
"0\n"
] | none | 500 | [
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "... | 1,695,183,250 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | strr = input()
print(len(list(strr)) - len(set(list(strr))))
'''21''' | Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ... | ```python
strr = input()
print(len(list(strr)) - len(set(list(strr))))
'''21'''
``` | 0 | |
801 | B | Valued Keys | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th cha... | The first line of input contains the string *x*.
The second line of input contains the string *y*.
Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100. | If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1.
Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters. | [
"ab\naa\n",
"nzwzl\nniwel\n",
"ab\nba\n"
] | [
"ba\n",
"xiyez\n",
"-1\n"
] | The first case is from the statement.
Another solution for the second case is "zizez"
There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) = "ba". | 1,000 | [
{
"input": "ab\naa",
"output": "ba"
},
{
"input": "nzwzl\nniwel",
"output": "xiyez"
},
{
"input": "ab\nba",
"output": "-1"
},
{
"input": "r\nl",
"output": "l"
},
{
"input": "d\ny",
"output": "-1"
},
{
"input": "yvowz\ncajav",
"output": "cajav"
},... | 1,628,949,404 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 108 | 20,172,800 | # Much easier solution, ripped from solved ones
x=input()
y=input()
print(-1 if any(x[i]<y[i] for i in range(len(x)))else y) | Title: Valued Keys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string... | ```python
# Much easier solution, ripped from solved ones
x=input()
y=input()
print(-1 if any(x[i]<y[i] for i in range(len(x)))else y)
``` | 3 | |
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all c... | Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). | Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
... | 1,499,690,133 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | from fractions import gcd
n,s= int(input()),0
for i in range(2,n):
temp=n
while temp:
s+=(temp%i)
temp//=i
g=gcd(s,n-2)
print(s//g,end="")
print("/",end="")
print(n-2//g)
from fractions import gcd
n,s= int(input()),0
for i in range(2,n):
temp=n
while temp:
... | Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of su... | ```python
from fractions import gcd
n,s= int(input()),0
for i in range(2,n):
temp=n
while temp:
s+=(temp%i)
temp//=i
g=gcd(s,n-2)
print(s//g,end="")
print("/",end="")
print(n-2//g)
from fractions import gcd
n,s= int(input()),0
for i in range(2,n):
temp=n
while temp... | -1 |
35 | A | Shell Game | PROGRAMMING | 1,000 | [
"implementation"
] | A. Shell Game | 2 | 64 | Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so ... | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered... | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | [
"1\n1 2\n2 1\n2 1\n",
"1\n2 1\n3 1\n1 3\n"
] | [
"2\n",
"2\n"
] | none | 500 | [
{
"input": "1\n1 2\n2 1\n2 1",
"output": "2"
},
{
"input": "1\n2 1\n3 1\n1 3",
"output": "2"
},
{
"input": "3\n3 1\n2 1\n1 2",
"output": "1"
},
{
"input": "1\n1 3\n1 2\n2 3",
"output": "2"
},
{
"input": "3\n3 2\n3 1\n3 1",
"output": "2"
},
{
"input": "... | 1,693,659,812 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | f = open("input.txt","r")
v = open("output.txt","w")
x = int(f.readline())
#y = f.readline()
#print(int(y[0]),int(y[2]))
lst = [1, 2, 3]
q = []
cpy = list(lst)
for i in range(3):
o = f.readline()
q = [int(o[0]) - 1 , int(o[2]) - 1]
#print(q)
lst[q[0]] = cpy[q[1]]
lst[q[1]] = cpy[q[0]]... | Title: Shell Game
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly put... | ```python
f = open("input.txt","r")
v = open("output.txt","w")
x = int(f.readline())
#y = f.readline()
#print(int(y[0]),int(y[2]))
lst = [1, 2, 3]
q = []
cpy = list(lst)
for i in range(3):
o = f.readline()
q = [int(o[0]) - 1 , int(o[2]) - 1]
#print(q)
lst[q[0]] = cpy[q[1]]
lst[q[1]] =... | 3.977 |
0 | none | none | none | 0 | [
"none"
] | null | null | You've gotten an *n*<=×<=*m* sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as *A*. Set *A* is connected. Your task is to find the minimum number of squares that we can delete from set *A* to make it not connected.
A set of painted squares is called connected, if for... | The first input line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the sizes of the sheet of paper.
Each of the next *n* lines contains *m* characters — the description of the sheet of paper: the *j*-th character of the *i*-th line equals either "#", if the corresponding square is paint... | On the first line print the minimum number of squares that need to be deleted to make set *A* not connected. If it is impossible, print -1. | [
"5 4\n####\n#..#\n#..#\n#..#\n####\n",
"5 5\n#####\n#...#\n#####\n#...#\n#####\n"
] | [
"2\n",
"2\n"
] | In the first sample you can delete any two squares that do not share a side. After that the set of painted squares is not connected anymore.
The note to the second sample is shown on the figure below. To the left there is a picture of the initial set of squares. To the right there is a set with deleted squares. The de... | 0 | [
{
"input": "5 4\n####\n#..#\n#..#\n#..#\n####",
"output": "2"
},
{
"input": "5 5\n#####\n#...#\n#####\n#...#\n#####",
"output": "2"
},
{
"input": "1 10\n.########.",
"output": "1"
},
{
"input": "1 1\n#",
"output": "-1"
},
{
"input": "3 3\n.#.\n###\n.#.",
"outp... | 1,594,294,038 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 2,000 | 30,412,800 | from sys import stdin
def dfs(x, y):
visit = [[0 for _ in range(m)] for _ in range(n)]
visit[x][y], stack, cur = 1, [], 1
for i in range(4):
x1, y1 = x + dx[i], y + dy[i]
if valid(x1, y1) and mat[x1][y1] == '#':
stack.append((x1, y1))
break
while ... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've gotten an *n*<=×<=*m* sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as *A*. Set *A* is connected. Your task is to find the minimum number of squares that we can delete fr... | ```python
from sys import stdin
def dfs(x, y):
visit = [[0 for _ in range(m)] for _ in range(n)]
visit[x][y], stack, cur = 1, [], 1
for i in range(4):
x1, y1 = x + dx[i], y + dy[i]
if valid(x1, y1) and mat[x1][y1] == '#':
stack.append((x1, y1))
break
... | 0 | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,611,683,580 | 2,147,483,647 | PyPy 3 | OK | TESTS | 38 | 93 | 0 | s = input()
while not 1<= len(s) <= 50:
s = input()
vogais = ['a','e','i','o','u']
numimp = ['1','3','5','7','9']
res = 0
for i in s:
if i in vogais:
res += 1
elif i in numimp:
res += 1
print(res)
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
s = input()
while not 1<= len(s) <= 50:
s = input()
vogais = ['a','e','i','o','u']
numimp = ['1','3','5','7','9']
res = 0
for i in s:
if i in vogais:
res += 1
elif i in numimp:
res += 1
print(res)
``` | 3 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,607,433,911 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 0 | d1,d2,d3=list(map(int,input().split()))
t=(d1+d2)*2
l=d1+d2+d3
ans=min(t,l)
print(ans) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
d1,d2,d3=list(map(int,input().split()))
t=(d1+d2)*2
l=d1+d2+d3
ans=min(t,l)
print(ans)
``` | 0 | |
690 | C2 | Brain Network (medium) | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Further research on zombie thought processes yielded interesting results. As we know from the previous problem, the nervous system of a zombie consists of *n* brains and *m* brain connectors joining some pairs of brains together. It was observed that the intellectual abilities of a zombie depend mainly on the topology ... | The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100000) denoting the number of brains (which are conveniently numbered from 1 to *n*) and the number of brain connectors in the nervous system, respectively. In the next *m* lines, descriptions of brain connectors follow.... | Print one number – the brain latency. | [
"4 3\n1 2\n1 3\n1 4\n",
"5 4\n1 2\n2 3\n3 4\n3 5\n"
] | [
"2",
"3"
] | none | 0 | [
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "3 2\n2 1\n3 2",
"output": "2"
},
{
"input": "10 9\n5 1\n1 2\n9 3\n10 5\n6 3\n8 5\n2 7\n2 3\n9 4",
"output": "6"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "2"
},
{
"input": "5 4\n1 2\n2 3\n3 4\n3 5",
"outp... | 1,672,490,540 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 155 | 3,072,000 | from functools import lru_cache
from collections import defaultdict, deque, Counter
import sys
class Solution:
def brainNetwork(self, graph):
# TODO write an algorithm here
start_node = 1
for key in graph:
if len(graph[key]) == 1:
start_node = key
... | Title: Brain Network (medium)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Further research on zombie thought processes yielded interesting results. As we know from the previous problem, the nervous system of a zombie consists of *n* brains and *m* brain connectors joining some pairs of... | ```python
from functools import lru_cache
from collections import defaultdict, deque, Counter
import sys
class Solution:
def brainNetwork(self, graph):
# TODO write an algorithm here
start_node = 1
for key in graph:
if len(graph[key]) == 1:
start_node... | 0 | |
10 | C | Digital Root | PROGRAMMING | 2,000 | [
"number theory"
] | C. Digital Root | 2 | 256 | Not long ago Billy came across such a problem, where there were given three natural numbers *A*, *B* and *C* from the range [1,<=*N*], and it was asked to check whether the equation *AB*<==<=*C* is correct. Recently Billy studied the concept of a digital root of a number. We should remind you that a digital root *d*(*x... | The first line contains the only number *N* (1<=≤<=*N*<=≤<=106). | Output one number — the amount of required *A*, *B* and *C* from the range [1,<=*N*]. | [
"4\n",
"5\n"
] | [
"2\n",
"6\n"
] | For the first sample the required triples are (3, 4, 3) and (4, 3, 3). | 0 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "6"
},
{
"input": "6",
"output": "14"
},
{
"input": "7",
"output": "25"
},
{
"input": "1",
"output": "0"
},
{
"input": "8",
"output": "40"
},
{
"input": "10",
"output": "82"
}... | 1,614,629,183 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 218 | 1,433,600 | '''
Jana Goodman6
10C Digital Root
this is true: d(xy) = d(d(x)d(y))
need to count AB
question is how many d(AB) == d(C)
but AB != C
'''
import math
import time
def dr(n):
return (n - 1) % 9 + 1
def digsum(n):
return sum(map(int, list(str(n))))
def persist(n):
m = n
... | Title: Digital Root
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Not long ago Billy came across such a problem, where there were given three natural numbers *A*, *B* and *C* from the range [1,<=*N*], and it was asked to check whether the equation *AB*<==<=*C* is correct. Recently Billy stud... | ```python
'''
Jana Goodman6
10C Digital Root
this is true: d(xy) = d(d(x)d(y))
need to count AB
question is how many d(AB) == d(C)
but AB != C
'''
import math
import time
def dr(n):
return (n - 1) % 9 + 1
def digsum(n):
return sum(map(int, list(str(n))))
def persist(n):
... | 3.94283 |
625 | A | Guest From the Past | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plas... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers *a*, *b* and *c* (1<=≤<=*a*<=≤<=1018, 1<=≤<=*c*<=<<=*b*<=≤<=1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and t... | Print the only integer — maximum number of liters of kefir, that Kolya can drink. | [
"10\n11\n9\n8\n",
"10\n5\n6\n1\n"
] | [
"2\n",
"2\n"
] | In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he ... | 750 | [
{
"input": "10\n11\n9\n8",
"output": "2"
},
{
"input": "10\n5\n6\n1",
"output": "2"
},
{
"input": "2\n2\n2\n1",
"output": "1"
},
{
"input": "10\n3\n3\n1",
"output": "4"
},
{
"input": "10\n1\n2\n1",
"output": "10"
},
{
"input": "10\n2\n3\n1",
"outpu... | 1,559,821,414 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 33 | 109 | 716,800 | def f(n, a, b, c):
if(n < a and n < b):
return 0
ans1 = 0
ans2 = 0
ans3 = 0
ans4 = 0
ans1 = n // a
if(n >= a):
ans2 = f(n % a, a, b, c)
if(n >= b):
ans3 = f(n % b + (n // b) * c, a, b, c)
ans4 = n // b
return max(ans1 + ans2, ans4 ... | Title: Guest From the Past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much mor... | ```python
def f(n, a, b, c):
if(n < a and n < b):
return 0
ans1 = 0
ans2 = 0
ans3 = 0
ans4 = 0
ans1 = n // a
if(n >= a):
ans2 = f(n % a, a, b, c)
if(n >= b):
ans3 = f(n % b + (n // b) * c, a, b, c)
ans4 = n // b
return max(ans1 + a... | -1 | |
416 | D | Population Size | PROGRAMMING | 2,400 | [
"greedy",
"implementation",
"math"
] | null | null | Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions.
Polycarpus believes that if... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of elements in the sequence. The second line contains integer values *a*1,<=*a*2,<=...,<=*a**n* separated by a space (1<=≤<=*a**i*<=≤<=109 or *a**i*<==<=<=-<=1). | Print the minimum number of arithmetic progressions that you need to write one after another to get sequence *a*. The positions marked as -1 in *a* can be represented by any positive integers. | [
"9\n8 6 4 2 1 4 7 10 2\n",
"9\n-1 6 -1 2 -1 4 7 -1 2\n",
"5\n-1 -1 -1 -1 -1\n",
"7\n-1 -1 4 5 1 2 3\n"
] | [
"3\n",
"3\n",
"1\n",
"2\n"
] | none | 2,000 | [
{
"input": "9\n8 6 4 2 1 4 7 10 2",
"output": "3"
},
{
"input": "9\n-1 6 -1 2 -1 4 7 -1 2",
"output": "3"
},
{
"input": "5\n-1 -1 -1 -1 -1",
"output": "1"
},
{
"input": "7\n-1 -1 4 5 1 2 3",
"output": "2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input... | 1,397,381,738 | 5,738 | Python 3 | RUNTIME_ERROR | PRETESTS | 13 | 77 | 0 | """
Codeforces Round 241 Div 1 Problem D
Author : chaotic_iak
Language: Python 3.3.4
"""
class InputHandlerObject(object):
inputs = []
def getInput(self, n = 0):
res = ""
inputs = self.inputs
if not inputs: inputs.extend(input().split(" "))
if n == 0:
... | Title: Population Size
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an... | ```python
"""
Codeforces Round 241 Div 1 Problem D
Author : chaotic_iak
Language: Python 3.3.4
"""
class InputHandlerObject(object):
inputs = []
def getInput(self, n = 0):
res = ""
inputs = self.inputs
if not inputs: inputs.extend(input().split(" "))
if n == 0:
... | -1 | |
632 | A | Grandma Laura and Apples | PROGRAMMING | 1,200 | [] | null | null | Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers she had *n* buyers and each of them bought exactly half of the apples she had at the moment of the purchase and ... | The first line contains two integers *n* and *p* (1<=≤<=*n*<=≤<=40,<=2<=≤<=*p*<=≤<=1000) — the number of the buyers and the cost of one apple. It is guaranteed that the number *p* is even.
The next *n* lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of th... | Print the only integer *a* — the total money grandma should have at the end of the day.
Note that the answer can be 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. | [
"2 10\nhalf\nhalfplus\n",
"3 10\nhalfplus\nhalfplus\nhalfplus\n"
] | [
"15\n",
"55\n"
] | In the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer. | 0 | [
{
"input": "2 10\nhalf\nhalfplus",
"output": "15"
},
{
"input": "3 10\nhalfplus\nhalfplus\nhalfplus",
"output": "55"
},
{
"input": "10 328\nhalf\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalf\nhalf\nhalfplus\nhalfplus",
"output": "258300"
},
{
"input": "1 2\nhalfplus",
"... | 1,456,846,096 | 1,696 | PyPy 3 | OK | TESTS | 9 | 109 | 0 | n, price = map(int, input().split())
history = []
ans = 0
cnt = 0
for i in range(n):
history.append(input())
for s in history[::-1]:
if s == 'halfplus':
cnt = cnt * 2 + 1
else:
cnt *= 2
ans += cnt / 2 * price
print(int(ans)) | Title: Grandma Laura and Apples
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers sh... | ```python
n, price = map(int, input().split())
history = []
ans = 0
cnt = 0
for i in range(n):
history.append(input())
for s in history[::-1]:
if s == 'halfplus':
cnt = cnt * 2 + 1
else:
cnt *= 2
ans += cnt / 2 * price
print(int(ans))
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,692,188,827 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | s=input()
def b(b, s):
i=s.find(b)
if i==-1:
print("NO")
exit()
s=s[i+1:]
return s
for i in "hello":
s=b(i, s)
print("YES")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=input()
def b(b, s):
i=s.find(b)
if i==-1:
print("NO")
exit()
s=s[i+1:]
return s
for i in "hello":
s=b(i, s)
print("YES")
``` | 3.977 |
266 | A | Stones on the Table | PROGRAMMING | 800 | [
"implementation"
] | null | null | There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red... | Print a single integer — the answer to the problem. | [
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] | [
"1\n",
"4\n",
"0\n"
] | none | 500 | [
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "... | 1,696,601,127 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | t= int(input())
s=input()
res=0
for i in range(t-1):
if s[i]==s[i+1]:
res+=1
print(res) | Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ... | ```python
t= int(input())
s=input()
res=0
for i in range(t-1):
if s[i]==s[i+1]:
res+=1
print(res)
``` | 3 | |
388 | C | Fox and Card Game | PROGRAMMING | 2,000 | [
"games",
"greedy",
"sortings"
] | null | null | Fox Ciel is playing a card game with her friend Fox Jiro. There are *n* piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom... | The first line contain an integer *n* (1<=≤<=*n*<=≤<=100). Each of the next *n* lines contains a description of the pile: the first integer in the line is *s**i* (1<=≤<=*s**i*<=≤<=100) — the number of cards in the *i*-th pile; then follow *s**i* positive integers *c*1, *c*2, ..., *c**k*, ..., *c**s**i* (1<=≤<=*c**k*<=≤... | Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally. | [
"2\n1 100\n2 1 10\n",
"1\n9 2 8 6 5 9 4 7 1 3\n",
"3\n3 1 3 2\n3 5 4 6\n2 8 7\n",
"3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000\n"
] | [
"101 10\n",
"30 15\n",
"18 18\n",
"7000 7000\n"
] | In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3. | 1,500 | [
{
"input": "2\n1 100\n2 1 10",
"output": "101 10"
},
{
"input": "1\n9 2 8 6 5 9 4 7 1 3",
"output": "30 15"
},
{
"input": "3\n3 1 3 2\n3 5 4 6\n2 8 7",
"output": "18 18"
},
{
"input": "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000",
"out... | 1,394,537,608 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<fstream>
#include<map>
#include<ctime>
#include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<bitset>
#include<functional>
#define x first
#define y second
#define mp make_pair
#define ... | Title: Fox and Card Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a card game with her friend Fox Jiro. There are *n* piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn ... | ```python
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<fstream>
#include<map>
#include<ctime>
#include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<bitset>
#include<functional>
#define x first
#define y second
#define mp make_pair... | -1 | |
515 | C | Drazil and Factorial | PROGRAMMING | 1,400 | [
"greedy",
"math",
"sortings"
] | null | null | Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they shoul... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*.
The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes. | Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. | [
"4\n1234\n",
"3\n555\n"
] | [
"33222\n",
"555\n"
] | In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "4\n1234",
"output": "33222"
},
{
"input": "3\n555",
"output": "555"
},
{
"input": "15\n012345781234578",
"output": "7777553333222222222222"
},
{
"input": "1\n8",
"output": "7222"
},
{
"input": "10\n1413472614",
"output": "75333332222222"
},
{
... | 1,685,206,039 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 46 | 0 | import sys
def convert(digit_string):
prime_replacement = {2: [2], 3: [3], 4: [2, 2, 3], 5: [5], 6: [3, 5],
7: [7], 8: [2, 2, 2, 7], 9: [2, 3, 3, 7]}
converted_digits = []
for dig in digit_string:
if int(dig) not in (0, 1):
converted_digits.extend(prim... | Title: Drazil and Factorial
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that cont... | ```python
import sys
def convert(digit_string):
prime_replacement = {2: [2], 3: [3], 4: [2, 2, 3], 5: [5], 6: [3, 5],
7: [7], 8: [2, 2, 2, 7], 9: [2, 3, 3, 7]}
converted_digits = []
for dig in digit_string:
if int(dig) not in (0, 1):
converted_digits.e... | 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,665,153,350 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n,m,a = map(int,input().split())
if n%a == 0:
r1 = n//a
else : r1 = (n//a)+1
if m%a == 0:
r2 = m//a
else : r2 = (m//a)+1
print(int(r1*r2)) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n,m,a = map(int,input().split())
if n%a == 0:
r1 = n//a
else : r1 = (n//a)+1
if m%a == 0:
r2 = m//a
else : r2 = (m//a)+1
print(int(r1*r2))
``` | 3.977 |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,695,029,918 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | l=int(input())
if l%5==0:
print(l//5)
else:
print(l//5+1) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
l=int(input())
if l%5==0:
print(l//5)
else:
print(l//5+1)
``` | -1 | |
18 | C | Stripe | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | C. Stripe | 2 | 64 | Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | [
"9\n1 5 -6 7 9 -16 0 -2 2\n",
"3\n1 1 1\n",
"2\n0 0\n"
] | [
"3\n",
"0\n",
"1\n"
] | none | 0 | [
{
"input": "9\n1 5 -6 7 9 -16 0 -2 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "4\n100 1 10 111",
"output": "1"
},
{
"input": "10\n0 4 -3 0 -2 2 -3 -3 2 5",
"output": "3"
},
{
"input": "... | 1,494,400,440 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | def Cortar(A):
c = -1
Sumd = 0
Sumi = 0
j=0
k=0
while k<len(A):
Sumd += A[k]
if k==j:
for i in range (k,len(A)):
Sumi += A[i]
if i==len(A)-1:
if Sumd == Sumi:
c+=1
j+=1
... | Title: Stripe
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that ... | ```python
def Cortar(A):
c = -1
Sumd = 0
Sumi = 0
j=0
k=0
while k<len(A):
Sumd += A[k]
if k==j:
for i in range (k,len(A)):
Sumi += A[i]
if i==len(A)-1:
if Sumd == Sumi:
c+=1
... | 0 |
31 | A | Worms Evolution | PROGRAMMING | 1,200 | [
"implementation"
] | A. Worms Evolution | 2 | 256 | Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. | Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. | [
"5\n1 2 3 5 7\n",
"5\n1 8 1 5 1\n"
] | [
"3 2 1\n",
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 5 7",
"output": "3 2 1"
},
{
"input": "5\n1 8 1 5 1",
"output": "-1"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "6\n86 402 133 524 405 610",
"output": "6 4 1"
},
{
"input": "8\n217 779 418 895 996 473 3 22",
"output":... | 1,690,471,322 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <fstream>
#include <stack>
#include <iomanip>
#include <cmath>
#include <queue>
#include <list>
#include <algorithm>
#include <utility>
#include <bits/stdc++.h>
#include <string>
#ifndef ONLINE_JUDGE
#include "LeetCode.h"
#endif
using namespace std;
typedef long lon... | Title: Worms Evolution
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his... | ```python
#include <iostream>
#include <fstream>
#include <stack>
#include <iomanip>
#include <cmath>
#include <queue>
#include <list>
#include <algorithm>
#include <utility>
#include <bits/stdc++.h>
#include <string>
#ifndef ONLINE_JUDGE
#include "LeetCode.h"
#endif
using namespace std;
typede... | -1 |
651 | A | Joysticks | PROGRAMMING | 1,100 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if n... | The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. | Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. | [
"3 5\n",
"4 4\n"
] | [
"6\n",
"5\n"
] | In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joyst... | 500 | [
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
... | 1,582,035,818 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 140 | 0 | (a1, a2) = [int(x) for x in input().split(" ")]
answer = 0
while a1 > 1 or a2 > 1:
ost = max(a1 // 2, a2 // 2)
if ost == 0:
break
if a1 > a2:
if a1 - ost * 2 == 0 and ost != 1:
ost -= 1
a1 -= ost * 2
a2 += ost
else:
if a2 - ost * 2 ==... | Title: Joysticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick on... | ```python
(a1, a2) = [int(x) for x in input().split(" ")]
answer = 0
while a1 > 1 or a2 > 1:
ost = max(a1 // 2, a2 // 2)
if ost == 0:
break
if a1 > a2:
if a1 - ost * 2 == 0 and ost != 1:
ost -= 1
a1 -= ost * 2
a2 += ost
else:
if a2 - ... | 3 | |
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* woode... | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal... | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ... | 1,560,763,061 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 248 | 102,400 | n=int(input())
l=[0]*n
r=[0]*n
for i in range(n):
l[i],r[i]=map(int,input().split())
lc=l.count(0)
rc=r.count(0)
lc=min(lc,n-lc)
rc=min(rc,n-rc)
print(lc+rc) | Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long... | ```python
n=int(input())
l=[0]*n
r=[0]*n
for i in range(n):
l[i],r[i]=map(int,input().split())
lc=l.count(0)
rc=r.count(0)
lc=min(lc,n-lc)
rc=min(rc,n-rc)
print(lc+rc)
``` | 3 | |
656 | G | You're a Professional | PROGRAMMING | 1,900 | [
"*special"
] | null | null | A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.
You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be... | The first line of the input will contain three space-separated integers: the number of friends *F* (1<=≤<=*F*<=≤<=10), the number of items *I* (1<=≤<=*I*<=≤<=10) and the threshold *T* (1<=≤<=*T*<=≤<=*F*).
The following *F* lines of input contain user's friends' opinions. *j*-th character of *i*-th line is 'Y' if *i*-t... | Output an integer — the number of items liked by at least *T* of user's friends. | [
"3 3 2\nYYY\nNNN\nYNY\n",
"4 4 1\nNNNY\nNNYN\nNYNN\nYNNN\n"
] | [
"2\n",
"4\n"
] | none | 0 | [
{
"input": "3 3 2\nYYY\nNNN\nYNY",
"output": "2"
},
{
"input": "4 4 1\nNNNY\nNNYN\nNYNN\nYNNN",
"output": "4"
},
{
"input": "3 5 2\nNYNNY\nYNNNN\nNNYYN",
"output": "0"
},
{
"input": "1 10 1\nYYYNYNNYNN",
"output": "5"
},
{
"input": "10 1 5\nY\nN\nN\nN\nY\nN\nN\nY\... | 1,501,241,725 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 0 | 0 | n, m, t = map(int,input().split())
ans = 0
cnt = 0
a = [input() for _ in range(n)]
for j in range (m):
for i in range (n):
if a[i][j] == 'Y':
cnt += 1
if cnt >= t:
ans += 1
cnt = 0
print (ans)
| Title: You're a Professional
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.
You are given user's friends' opinions about a li... | ```python
n, m, t = map(int,input().split())
ans = 0
cnt = 0
a = [input() for _ in range(n)]
for j in range (m):
for i in range (n):
if a[i][j] == 'Y':
cnt += 1
if cnt >= t:
ans += 1
cnt = 0
print (ans)
``` | 0 | |
35 | A | Shell Game | PROGRAMMING | 1,000 | [
"implementation"
] | A. Shell Game | 2 | 64 | Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so ... | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered... | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | [
"1\n1 2\n2 1\n2 1\n",
"1\n2 1\n3 1\n1 3\n"
] | [
"2\n",
"2\n"
] | none | 500 | [
{
"input": "1\n1 2\n2 1\n2 1",
"output": "2"
},
{
"input": "1\n2 1\n3 1\n1 3",
"output": "2"
},
{
"input": "3\n3 1\n2 1\n1 2",
"output": "1"
},
{
"input": "1\n1 3\n1 2\n2 3",
"output": "2"
},
{
"input": "3\n3 2\n3 1\n3 1",
"output": "2"
},
{
"input": "... | 1,634,864,134 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 4,505,600 | correct = int(input())
arr = [None] * 4
arr[correct] = 'yes'
for i in range(3):
start, end = input().split()
start = int(start)
end = int(end)
arr[start], arr[end] = arr[end], arr[start]
print(arr.index('yes'))
| Title: Shell Game
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly put... | ```python
correct = int(input())
arr = [None] * 4
arr[correct] = 'yes'
for i in range(3):
start, end = input().split()
start = int(start)
end = int(end)
arr[start], arr[end] = arr[end], arr[start]
print(arr.index('yes'))
``` | -1 |
670 | D1 | Magic Powder - 1 | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation"
] | null | null | This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.
Waking up in the ... | The first line of the input contains two positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1000) — the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of... | Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. | [
"3 1\n2 1 4\n11 3 16\n",
"4 3\n4 3 5 6\n11 12 14 20\n"
] | [
"4\n",
"3\n"
] | In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.
In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredie... | 1,000 | [
{
"input": "3 1\n2 1 4\n11 3 16",
"output": "4"
},
{
"input": "4 3\n4 3 5 6\n11 12 14 20",
"output": "3"
},
{
"input": "10 926\n5 6 8 1 2 5 1 8 4 4\n351 739 998 725 953 970 906 691 707 1000",
"output": "137"
},
{
"input": "20 925\n7 3 1 2 1 3 1 3 1 2 3 1 5 8 1 3 7 3 4 2\n837 ... | 1,680,170,529 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | def make_cookies_yum_yum(required, available, k):
# could refactor this into its own function
make_one_cookie = 0
grams_available = 0
for i in range(len(required)):
make_one_cookie += required[i]
grams_available += available[i]
l, r = 0, 2147483647
... | Title: Magic Powder - 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too dif... | ```python
def make_cookies_yum_yum(required, available, k):
# could refactor this into its own function
make_one_cookie = 0
grams_available = 0
for i in range(len(required)):
make_one_cookie += required[i]
grams_available += available[i]
l, r = 0, 214748364... | 0 | |
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th... | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\... | 1,698,795,087 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | n = int(input())
count = 0
for i in range(n):
string = input()
if string == "X++" or string == "++X":
count += 1
elif string == "X--" or string == "--X":
count -= 1
print(count) | Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ incre... | ```python
n = int(input())
count = 0
for i in range(n):
string = input()
if string == "X++" or string == "++X":
count += 1
elif string == "X--" or string == "--X":
count -= 1
print(count)
``` | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.