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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
... | 1,663,101,830 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 88 | 93 | 13,516,800 | n = int(input())
lst = list(map(int, input().split()))
lst.sort()
res = 0
for i in range(n):
if lst[i] != lst[0] and lst[i] != lst[-1]:
res += 1
res += 2
if res < 3:
print(0)
else:
print(res - 2) | Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am... | ```python
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
res = 0
for i in range(n):
if lst[i] != lst[0] and lst[i] != lst[-1]:
res += 1
res += 2
if res < 3:
print(0)
else:
print(res - 2)
``` | 3 | |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479"... | 1,626,201,810 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 12,800,000 | a,b,n=map(int,input().split())
x,i=a,0
while i<n:
for j in range(10):
if (a*10+j)%b==0:
a=a*10+j
break
i+=1
if a==x:
print(-1)
else:
print(a) | Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
a,b,n=map(int,input().split())
x,i=a,0
while i<n:
for j in range(10):
if (a*10+j)%b==0:
a=a*10+j
break
i+=1
if a==x:
print(-1)
else:
print(a)
``` | 0 | |
190 | B | Surrounded | PROGRAMMING | 1,800 | [
"geometry"
] | null | null | So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation.
Right now the situation in Berland is dismal — their both cities are surrounded! The armies of flatlanders stand on the borders of circles, the circles' centers are in the surround... | The input files consist of two lines. Each line represents the city and the flatland ring that surrounds it as three space-separated integers *x**i*, *y**i*, *r**i* (|*x**i*|,<=|*y**i*|<=≤<=104; 1<=≤<=*r**i*<=≤<=104) — the city's coordinates and the distance from the city to the flatlanders, correspondingly.
It is gua... | Print a single real number — the minimum detection radius of the described radar. The answer is considered correct if the absolute or relative error does not exceed 10<=-<=6. | [
"0 0 1\n6 0 3\n",
"-10 10 3\n10 -10 3\n"
] | [
"1.000000000000000",
"11.142135623730951"
] | The figure below shows the answer to the first sample. In this sample the best decision is to put the radar at point with coordinates (2, 0).
The figure below shows the answer for the second sample. In this sample the best decision is to put the radar at point with coordinates (0, 0). | 1,000 | [
{
"input": "0 0 1\n6 0 3",
"output": "1.000000000000000"
},
{
"input": "-10 10 3\n10 -10 3",
"output": "11.142135623730951"
},
{
"input": "2 1 3\n8 9 5",
"output": "1.000000000000000"
},
{
"input": "0 0 1\n-10 -10 9",
"output": "2.071067811865475"
},
{
"input": "1... | 1,594,384,191 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 109 | 6,963,200 | x1,y1,r1=list(map(float,input().split()))
x2,y2,r2=list(map(float,input().split()))
if r1>r2:
r2,r1=r1,r2
d=((x2-x1)**2 + (y2-y1)**2)**(0.5)
if d>r1+r2:
print((d-(r1+r2))/2)
elif r2>d+r1:
print((r2-(r1+d))/2)
else:
print(0) | Title: Surrounded
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation.
Right now the situation in Berland is dismal — their both cities are surrounded! The... | ```python
x1,y1,r1=list(map(float,input().split()))
x2,y2,r2=list(map(float,input().split()))
if r1>r2:
r2,r1=r1,r2
d=((x2-x1)**2 + (y2-y1)**2)**(0.5)
if d>r1+r2:
print((d-(r1+r2))/2)
elif r2>d+r1:
print((r2-(r1+d))/2)
else:
print(0)
``` | 3 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,689,587,453 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | def solve():
string = input()
character, cnt = "", 0
arr = []
for char in string:
if character == "":
character, cnt = char, 1
elif character == char:
cnt += 1
else:
arr.append(cnt)
character, cnt = char, 1
print("YE... | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
def solve():
string = input()
character, cnt = "", 0
arr = []
for char in string:
if character == "":
character, cnt = char, 1
elif character == char:
cnt += 1
else:
arr.append(cnt)
character, cnt = char, 1
... | 0 |
459 | A | Pashmak and Garden | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al... | The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct. | If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<... | [
"0 0 0 1\n",
"0 0 1 1\n",
"0 0 1 2\n"
] | [
"1 0 1 1\n",
"0 1 1 0\n",
"-1\n"
] | none | 500 | [
{
"input": "0 0 0 1",
"output": "1 0 1 1"
},
{
"input": "0 0 1 1",
"output": "0 1 1 0"
},
{
"input": "0 0 1 2",
"output": "-1"
},
{
"input": "-100 -100 100 100",
"output": "-100 100 100 -100"
},
{
"input": "-100 -100 99 100",
"output": "-1"
},
{
"input... | 1,657,634,365 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | def pashmak_and_garden():
points = [int(point) for point in input().split()]
conj_points = (points[0] == points[2]) or (points[1] == points[3])
diff = [points[i] - points[i+2] for i in range(2)]
print(diff)
unique_diff = list(set(diff))
nunique_diff = len(unique_diff)
if (nunique_diff... | Title: Pashmak and Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is... | ```python
def pashmak_and_garden():
points = [int(point) for point in input().split()]
conj_points = (points[0] == points[2]) or (points[1] == points[3])
diff = [points[i] - points[i+2] for i in range(2)]
print(diff)
unique_diff = list(set(diff))
nunique_diff = len(unique_diff)
if (nu... | 0 | |
165 | E | Compatible Numbers | PROGRAMMING | 2,200 | [
"bitmasks",
"brute force",
"dfs and similar",
"dp"
] | null | null | Two integers *x* and *y* are compatible, if the result of their bitwise "AND" equals zero, that is, *a* & *b*<==<=0. For example, numbers 90 (10110102) and 36 (1001002) are compatible, as 10110102 & 1001002<==<=02, and numbers 3 (112) and 6 (1102) are not compatible, as 112 & 1102<==<=102.
You are given an... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the number of elements in the given array. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=4·106) — the elements of the given array. The numbers in the array can coincide. | Print *n* integers *ans**i*. If *a**i* isn't compatible with any other element of the given array *a*1,<=*a*2,<=...,<=*a**n*, then *ans**i* should be equal to -1. Otherwise *ans**i* is any such number, that *a**i* & *ans**i*<==<=0, and also *ans**i* occurs in the array *a*1,<=*a*2,<=...,<=*a**n*. | [
"2\n90 36\n",
"4\n3 6 3 6\n",
"5\n10 6 9 8 2\n"
] | [
"36 90",
"-1 -1 -1 -1",
"-1 8 2 2 8"
] | none | 2,500 | [
{
"input": "2\n90 36",
"output": "36 90"
},
{
"input": "4\n3 6 3 6",
"output": "-1 -1 -1 -1"
},
{
"input": "5\n10 6 9 8 2",
"output": "-1 8 2 2 8"
},
{
"input": "10\n4 9 8 3 2 6 8 2 9 7",
"output": "8 4 4 8 8 8 4 8 4 8"
},
{
"input": "10\n3 5 18 12 4 20 11 19 15 6... | 1,684,740,709 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 0 | 1,776 | 268,390,400 | # for I/O for local system
import sys
from os import path
if(path.exists('Input.txt')):
sys.stdin = open("Input.txt","r")
sys.stdout = open("Output.txt","w")
# For fast I/O
input = sys.stdin.buffer.readline
# input = sys.stdin.readline
print = sys.stdout.write
# Import libraries here whenever requ... | Title: Compatible Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two integers *x* and *y* are compatible, if the result of their bitwise "AND" equals zero, that is, *a* & *b*<==<=0. For example, numbers 90 (10110102) and 36 (1001002) are compatible, as 10110102 & 1001002<=... | ```python
# for I/O for local system
import sys
from os import path
if(path.exists('Input.txt')):
sys.stdin = open("Input.txt","r")
sys.stdout = open("Output.txt","w")
# For fast I/O
input = sys.stdin.buffer.readline
# input = sys.stdin.readline
print = sys.stdout.write
# Import libraries here whe... | 0 | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,691,366,352 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 26 | 46 | 0 | n = int(input())
x = set(input().split())
y = set(input().split())
x.update(y)
if '0' in x:
n += 1
if len(x) == n:
print('I become the guy.')
else:
print('Oh, my keyboard!') | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
n = int(input())
x = set(input().split())
y = set(input().split())
x.update(y)
if '0' in x:
n += 1
if len(x) == n:
print('I become the guy.')
else:
print('Oh, my keyboard!')
``` | 0 | |
222 | B | Cosmic Tables | PROGRAMMING | 1,300 | [
"data structures",
"implementation"
] | null | null | The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an *n*<=×<=*m* table with integers in its cells. The order of mete... | The first line contains three space-separated integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=500000) — the number of table columns and rows and the number of queries, correspondingly.
Next *n* lines contain *m* space-separated numbers each — the initial state of the table. Each number *p* in the ta... | For each query to obtain a number (*s**i* = "g") print the required number. Print the answers to the queries in the order of the queries in the input. | [
"3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2\n",
"2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3\n"
] | [
"8\n9\n6\n",
"5\n"
] | Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) wi... | 1,000 | [
{
"input": "3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2",
"output": "8\n9\n6"
},
{
"input": "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3",
"output": "5"
},
{
"input": "1 1 15\n1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1... | 1,552,637,448 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 3,000 | 31,129,600 | m, n, k = [int(i) for i in input().split()]
p = []
for i in range(m):
p.append([int(i) for i in input().split()])
for i in range(k):
s, x, y = input().split()
x = int(x)-1
y = int(y)-1
if s == "c":
q = list(zip(*p))
q[x], q[y] = q[y], q[x]
p = list(zip(*q))
elif s == "r":
p[x], p[y] = ... | Title: Cosmic Tables
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some sec... | ```python
m, n, k = [int(i) for i in input().split()]
p = []
for i in range(m):
p.append([int(i) for i in input().split()])
for i in range(k):
s, x, y = input().split()
x = int(x)-1
y = int(y)-1
if s == "c":
q = list(zip(*p))
q[x], q[y] = q[y], q[x]
p = list(zip(*q))
elif s == "r":
p[x... | 0 | |
769 | A | Year of University Entrance | PROGRAMMING | 800 | [
"*special",
"implementation",
"sortings"
] | null | null | There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university.
Each of students joins the group of his course and joins all groups f... | The first line contains the positive odd integer *n* (1<=≤<=*n*<=≤<=5) — the number of groups which Igor joined.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (2010<=≤<=*a**i*<=≤<=2100) — years of student's university entrance for each group in which Igor is the member.
It is guaranteed tha... | Print the year of Igor's university entrance. | [
"3\n2014 2016 2015\n",
"1\n2050\n"
] | [
"2015\n",
"2050\n"
] | In the first test the value *x* = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016.
In the second test the value *x* = 0. Igor entered only the group which corresponds to the year of his university entrance. | 500 | [
{
"input": "3\n2014 2016 2015",
"output": "2015"
},
{
"input": "1\n2050",
"output": "2050"
},
{
"input": "1\n2010",
"output": "2010"
},
{
"input": "1\n2011",
"output": "2011"
},
{
"input": "3\n2010 2011 2012",
"output": "2011"
},
{
"input": "3\n2049 20... | 1,629,742,409 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 109 | 22,323,200 | n = int(input())
L = list(map(int, input.split()))
L.sort()
print(L[n//2]) | Title: Year of University Entrance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of correspond... | ```python
n = int(input())
L = list(map(int, input.split()))
L.sort()
print(L[n//2])
``` | -1 | |
482 | A | Diverse Permutation | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*.
Your task is to find such permutation *p* of length *n*, that the group of number... | The single line of the input contains two space-separated positive integers *n*, *k* (1<=≤<=*k*<=<<=*n*<=≤<=105). | Print *n* integers forming the permutation. If there are multiple answers, print any of them. | [
"3 2\n",
"3 1\n",
"5 2\n"
] | [
"1 3 2\n",
"1 2 3\n",
"1 3 2 4 5\n"
] | By |*x*| we denote the absolute value of number *x*. | 500 | [
{
"input": "3 2",
"output": "1 3 2"
},
{
"input": "3 1",
"output": "1 2 3"
},
{
"input": "5 2",
"output": "1 3 2 4 5"
},
{
"input": "5 4",
"output": "1 5 2 4 3"
},
{
"input": "10 4",
"output": "1 10 2 9 8 7 6 5 4 3"
},
{
"input": "10 3",
"output": ... | 1,535,934,909 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 514 | 614,400 | n, k = map(int, input().split())
cur = 1
x = 0
a = [0] * (n + 1)
while k > 0:
a[cur] = 1
print(cur, end=(' '))
if x == 0:
cur = cur + k
x = 1
else:
cur = cur - k
x = 0
k = k - 1
for i in range(1, n + 1):
if a[i] == 0:
print(i, end=' ') | Title: Diverse Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<... | ```python
n, k = map(int, input().split())
cur = 1
x = 0
a = [0] * (n + 1)
while k > 0:
a[cur] = 1
print(cur, end=(' '))
if x == 0:
cur = cur + k
x = 1
else:
cur = cur - k
x = 0
k = k - 1
for i in range(1, n + 1):
if a[i] == 0:
print(i, end... | 3 | |
825 | A | Binary Protocol | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in ord... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*.
The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts... | Print the decoded number. | [
"3\n111\n",
"9\n110011101\n"
] | [
"3\n",
"2031\n"
] | none | 0 | [
{
"input": "3\n111",
"output": "3"
},
{
"input": "9\n110011101",
"output": "2031"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "3\n100",
"output": "100"
},
{
"input": "5\n10001",
"output": "1001"
},
{
"input": "14\n11001100011000",
"output": "... | 1,500,742,616 | 2,147,483,647 | Python 3 | OK | TESTS | 13 | 77 | 4,608,000 | n = int(input())
# print(n)
s = input()
# print(s)
k = 0
ans = ''
for c in s:
# print(c)
if c == '0':
ans += str(k)
k = 0
else:
k += 1
print(ans + str(k))
| Title: Binary Protocol
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' charact... | ```python
n = int(input())
# print(n)
s = input()
# print(s)
k = 0
ans = ''
for c in s:
# print(c)
if c == '0':
ans += str(k)
k = 0
else:
k += 1
print(ans + str(k))
``` | 3 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,691,690,065 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 340 | 13,824,000 | from fractions import Fraction
a,b=list(map(int,input().split()))
n=6-max(a,b)+1
fraction = Fraction(n, 6).limit_denominator()
print(fraction)
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
from fractions import Fraction
a,b=list(map(int,input().split()))
n=6-max(a,b)+1
fraction = Fraction(n, 6).limit_denominator()
print(fraction)
``` | 0 |
892 | A | Greed | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans.
The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<... | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower). | [
"2\n3 5\n3 6\n",
"3\n6 8 9\n6 10 12\n",
"5\n0 0 5 0 0\n1 1 8 10 5\n",
"4\n4 1 0 3\n5 2 2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] | In the first sample, there are already 2 cans, so the answer is "YES". | 500 | [
{
"input": "2\n3 5\n3 6",
"output": "YES"
},
{
"input": "3\n6 8 9\n6 10 12",
"output": "NO"
},
{
"input": "5\n0 0 5 0 0\n1 1 8 10 5",
"output": "YES"
},
{
"input": "4\n4 1 0 3\n5 2 2 3",
"output": "YES"
},
{
"input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 9... | 1,659,184,237 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 108 | 18,739,200 |
_ = int(input())
soda = list(map(int, input().split()))
cans = sorted(list(map(int, input().split())))
max_capacity = cans[-1] + cans[-2]
result = "YES"
for s in soda:
max_capacity -= s
if max_capacity < 0:
result = "NO"
break
print(result) | Title: Greed
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he c... | ```python
_ = int(input())
soda = list(map(int, input().split()))
cans = sorted(list(map(int, input().split())))
max_capacity = cans[-1] + cans[-2]
result = "YES"
for s in soda:
max_capacity -= s
if max_capacity < 0:
result = "NO"
break
print(result)
``` | 3 | |
967 | B | Watering System | PROGRAMMING | 1,000 | [
"math",
"sortings"
] | null | null | Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After... | The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$)... | Print a single integer — the number of holes Arkady should block. | [
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] | [
"1\n",
"0\n",
"4\n"
] | In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not les... | 1,000 | [
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 ... | 1,673,785,531 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 14,028,800 | from sys import stdin; inp = stdin.readline
from math import dist, ceil, floor, sqrt, log
from collections import defaultdict, Counter, deque
def IA(sep=' '): return list(map(int, inp().split(sep)))
def FA(): return list(map(float, inp().split()))
def SA(): return inp().split()
def I(): return int(inp())
def F()... | Title: Watering System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the fi... | ```python
from sys import stdin; inp = stdin.readline
from math import dist, ceil, floor, sqrt, log
from collections import defaultdict, Counter, deque
def IA(sep=' '): return list(map(int, inp().split(sep)))
def FA(): return list(map(float, inp().split()))
def SA(): return inp().split()
def I(): return int(inp()... | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,687,430,328 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | import math
#s=input()
#x = s[0]
#x = x.capitalize()
#b = n[1:]
#print(x+b)
#s1=s[0].upper() + s[1:len(s)]
#print(s1)
#s=input()
#s=input()
#s.lower()
#if :
# print('1')
#elif:
# print('-1')
#else:
# print('0')
#
#string=input().lower()
#
#l=['a','e','i','o','u','y']
#k=list(s... | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
import math
#s=input()
#x = s[0]
#x = x.capitalize()
#b = n[1:]
#print(x+b)
#s1=s[0].upper() + s[1:len(s)]
#print(s1)
#s=input()
#s=input()
#s.lower()
#if :
# print('1')
#elif:
# print('-1')
#else:
# print('0')
#
#string=input().lower()
#
#l=['a','e','i','o','u','y']
... | 0 |
893 | C | Rumor | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Ove... | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
... | Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example ... | 0 | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n10000000... | 1,653,746,548 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n, m = map(int, input().split())
arr = list(map(int, input().split()))
parent = [i for i in range(len(arr))]
rank = [arr[i] for i in range(len(arr))]
def find(idx):
if parent[idx] == idx:
return idx
parent[idx] = find(parent[idx])
return parent[idx]
def union(i, j):
pi = find(i... | Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte... | ```python
n, m = map(int, input().split())
arr = list(map(int, input().split()))
parent = [i for i in range(len(arr))]
rank = [arr[i] for i in range(len(arr))]
def find(idx):
if parent[idx] == idx:
return idx
parent[idx] = find(parent[idx])
return parent[idx]
def union(i, j):
p... | -1 | |
526 | A | King of Thieves | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.
An interesting feature of the game is that you can design your own levels that wil... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of segments on the level.
Next line contains the scheme of the level represented as a string of *n* characters '*' and '.'. | If the level is good, print the word "yes" (without the quotes), otherwise print the word "no" (without the quotes). | [
"16\n.**.*..*.***.**.\n",
"11\n.*.*...*.*.\n"
] | [
"yes",
"no"
] | In the first sample test you may perform a sequence of jumps through platforms 2, 5, 8, 11, 14. | 500 | [
{
"input": "16\n.**.*..*.***.**.",
"output": "yes"
},
{
"input": "11\n.*.*...*.*.",
"output": "no"
},
{
"input": "53\n*.*.****.*.*......**....**.***.*.*.**.*.*.***...*..*.",
"output": "yes"
},
{
"input": "71\n**.**..*****.*.*.*.********.....*****.****.*..***...*.*.*.**.****.*... | 1,428,167,298 | 1,998 | Python 3 | RUNTIME_ERROR | PRETESTS | 0 | 46 | 0 | #fin = open("input.txt")
#n = int(fin.readline())
#s = list(fin.readline())
n = int(input())
s = input()
a, b, c, d = -1, -1, -1, -1
for i in range(n):
if s[i] == "*":
if c == -1 or i > 0 and not s[i - 1]:
c = i
d = i
if a == -1:
a = i
else:
if b == -1 and i > 0 and s[i - 1]:
b = i - 1
s[i] = (s[i] ... | Title: King of Thieves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obsta... | ```python
#fin = open("input.txt")
#n = int(fin.readline())
#s = list(fin.readline())
n = int(input())
s = input()
a, b, c, d = -1, -1, -1, -1
for i in range(n):
if s[i] == "*":
if c == -1 or i > 0 and not s[i - 1]:
c = i
d = i
if a == -1:
a = i
else:
if b == -1 and i > 0 and s[i - 1]:
b = i - 1
s[i... | -1 | |
858 | C | Did you mean... | PROGRAMMING | 1,500 | [
"dp",
"greedy",
"implementation"
] | null | null | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are thr... | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | [
"hellno\n",
"abacaba\n",
"asdfasdf\n"
] | [
"hell no \n",
"abacaba \n",
"asd fasd f \n"
] | none | 1,500 | [
{
"input": "hellno",
"output": "hell no "
},
{
"input": "abacaba",
"output": "abacaba "
},
{
"input": "asdfasdf",
"output": "asd fasd f "
},
{
"input": "ooo",
"output": "ooo "
},
{
"input": "moyaoborona",
"output": "moyaoborona "
},
{
"input": "jxegxxx... | 1,505,658,255 | 4,755 | Python 3 | WRONG_ANSWER | TESTS | 32 | 62 | 5,529,600 | def insert_char(txt, chir, pos):
out = ""
for i in range(len(txt)):
out += txt[i]
if(i == pos):
out += chir
return out
s = str(input())
esog = "aeuio"
repeat = 0
repchar = ""
np = True
i=0
while(i<len(s)):
if(repeat>2):
if(s[i] == s[i-1] == s[i-2]):
np ... | Title: Did you mean...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (... | ```python
def insert_char(txt, chir, pos):
out = ""
for i in range(len(txt)):
out += txt[i]
if(i == pos):
out += chir
return out
s = str(input())
esog = "aeuio"
repeat = 0
repchar = ""
np = True
i=0
while(i<len(s)):
if(repeat>2):
if(s[i] == s[i-1] == s[i-2]):
... | 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,596,799,506 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 6,656,000 | a, b, c = map(int, input().split())
d = a*2+b*2
e = a+b+c
print(min(d, e))
| 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
a, b, c = map(int, input().split())
d = a*2+b*2
e = a+b+c
print(min(d, e))
``` | 0 | |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,686,008,825 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | n = int(input())
a = [int(i) for i in input().split()]
d = 0 # max el index
f = 0 # min el index
answer = 0
index = 0 # 10 58 331 63 40 6 44
if a[0] != max(a) and a[-1] != min(a):
for i in range(len(a)):
if a[i] == max(a):
d = i
b = a[i]
if a[i] == min(a):
... | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
n = int(input())
a = [int(i) for i in input().split()]
d = 0 # max el index
f = 0 # min el index
answer = 0
index = 0 # 10 58 331 63 40 6 44
if a[0] != max(a) and a[-1] != min(a):
for i in range(len(a)):
if a[i] == max(a):
d = i
b = a[i]
if a[i] == min... | 0 | |
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen... | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"o... | 1,693,589,232 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 0 | a=int(input())
count_100 = a//100
a%=100
count_20 = a//20
a%=20
count_10 = a//10
a%=10
count_5 = a//5
a%=5
count_1 = a
tot = count_100 + count_20 + count_10 + count_5 + count_1
print(tot) | Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$... | ```python
a=int(input())
count_100 = a//100
a%=100
count_20 = a//20
a%=20
count_10 = a//10
a%=10
count_5 = a//5
a%=5
count_1 = a
tot = count_100 + count_20 + count_10 + count_5 + count_1
print(tot)
``` | 3 | |
721 | B | Passwords | PROGRAMMING | 1,100 | [
"implementation",
"math",
"sortings",
"strings"
] | null | null | Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitr... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of ... | Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively. | [
"5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n",
"4 100\n11\n22\n1\n2\n22\n"
] | [
"1 15\n",
"3 4\n"
] | Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he ente... | 1,000 | [
{
"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc",
"output": "1 15"
},
{
"input": "4 100\n11\n22\n1\n2\n22",
"output": "3 4"
},
{
"input": "1 1\na1\na1",
"output": "1 1"
},
{
"input": "1 100\na1\na1",
"output": "1 1"
},
{
"input": "2 1\nabc\nAbc\nAbc",
"output": ... | 1,576,210,869 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | def fnd1(s,x):
hi=len(s)-1
lo=0
ans=-1
while hi>=lo:
mid=(hi+lo)//2
if s[mid]>=x:
hi=mid-1
ans=mid+1
else: lo=mid+1
return ans
def fnd2(s,x):
hi=len(s)-1
lo=0
ans=-1
while hi>=lo:
mid=(hi+lo)//2
if s[m... | Title: Passwords
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords... | ```python
def fnd1(s,x):
hi=len(s)-1
lo=0
ans=-1
while hi>=lo:
mid=(hi+lo)//2
if s[mid]>=x:
hi=mid-1
ans=mid+1
else: lo=mid+1
return ans
def fnd2(s,x):
hi=len(s)-1
lo=0
ans=-1
while hi>=lo:
mid=(hi+lo)//2
... | 0 | |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,643,463,324 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 451 | 8,089,600 | import math
def main():
# t = int(input())
# for _ in range(t):
(case())
def case():
n = int(input())
a = list(map(int, input().split()))
print(f'{abs(a[0]-a[1])} {abs(a[0]-a[-1])}')
for i in range(1, n-1):
head = a[0]
tail = a[-1]
print(min(abs(a[i]-a[i+1]), abs(a[i]-a[i-1])), end=' ')... | Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
import math
def main():
# t = int(input())
# for _ in range(t):
(case())
def case():
n = int(input())
a = list(map(int, input().split()))
print(f'{abs(a[0]-a[1])} {abs(a[0]-a[-1])}')
for i in range(1, n-1):
head = a[0]
tail = a[-1]
print(min(abs(a[i]-a[i+1]), abs(a[i]-a[i-1]))... | 3 | |
135 | B | Rectangle and Square | PROGRAMMING | 1,600 | [
"brute force",
"geometry",
"math"
] | null | null | Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing 4 points so that the points from the first set lay at the vertexes of some square and the ... | You are given 8 pairs of integers, a pair per line — the coordinates of the points Petya has. The absolute value of all coordinates does not exceed 104. It is guaranteed that no two points coincide. | Print in the first output line "YES" (without the quotes), if the desired partition exists. In the second line output 4 space-separated numbers — point indexes from the input, which lie at the vertexes of the square. The points are numbered starting from 1. The numbers can be printed in any order. In the third line pri... | [
"0 0\n10 11\n10 0\n0 11\n1 1\n2 2\n2 1\n1 2\n",
"0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n",
"0 0\n4 4\n4 0\n0 4\n1 2\n2 3\n3 2\n2 1\n"
] | [
"YES\n5 6 7 8\n1 2 3 4\n",
"NO\n",
"YES\n1 2 3 4\n5 6 7 8\n"
] | Pay attention to the third example: the figures do not necessarily have to be parallel to the coordinate axes. | 1,000 | [
{
"input": "0 0\n10 11\n10 0\n0 11\n1 1\n2 2\n2 1\n1 2",
"output": "YES\n5 6 7 8\n1 2 3 4"
},
{
"input": "0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7",
"output": "NO"
},
{
"input": "0 0\n4 4\n4 0\n0 4\n1 2\n2 3\n3 2\n2 1",
"output": "YES\n1 2 3 4\n5 6 7 8"
},
{
"input": "-160 336\... | 1,605,106,474 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 204,800 | def is_rectangle(a, b, c, d):
ab = (b[0]-a[0], b[1]-a[1])
ad = (d[0]-a[0], d[1]-a[1])
dp = ab[0]*ad[0] + ab[1]*ad[1]
ne = len(set((a, b, c, d))) == 4
return ne and dp == 0 and (a[0]+ab[0]+ad[0], a[1]+ab[1]+ad[1]) == c
def is_square(a, b, c, d):
abl = (b[0]-a[0])**2 + (b[1]-a[1])**2
... | Title: Rectangle and Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets ... | ```python
def is_rectangle(a, b, c, d):
ab = (b[0]-a[0], b[1]-a[1])
ad = (d[0]-a[0], d[1]-a[1])
dp = ab[0]*ad[0] + ab[1]*ad[1]
ne = len(set((a, b, c, d))) == 4
return ne and dp == 0 and (a[0]+ab[0]+ad[0], a[1]+ab[1]+ad[1]) == c
def is_square(a, b, c, d):
abl = (b[0]-a[0])**2 + (b[1]-a[1... | -1 | |
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"i... | 1,698,689,846 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 154 | 11,776,000 | k=int(input())
l=int(input())
m=int(input())
n=int(input())
d=int(input())
if k==1 or l==1 or m==1 or n==1:
print(d)
else:
di={}
escaped=0
for i in range(1,d+1):
di[i]=0
for j in range(k,d+1,k):
di[j]=1
for j in range(l,d+1,l):
di[j]=1
for j in r... | Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entert... | ```python
k=int(input())
l=int(input())
m=int(input())
n=int(input())
d=int(input())
if k==1 or l==1 or m==1 or n==1:
print(d)
else:
di={}
escaped=0
for i in range(1,d+1):
di[i]=0
for j in range(k,d+1,k):
di[j]=1
for j in range(l,d+1,l):
di[j]=1
... | 3 | |
441 | A | Valera and Antique Items | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfec... | The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has.
Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space... | In the first line, print integer *p* — the number of sellers with who Valera can make a deal.
In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order. | [
"3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n",
"3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n"
] | [
"3\n1 2 3\n",
"0\n\n"
] | In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.
In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the... | 500 | [
{
"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000",
"output": "3\n1 2 3"
},
{
"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000",
"output": "0"
},
{
"input": "2 100001\n1 895737\n1 541571",
"output": "0"
},
{
"input": "1 1000000\n1 100... | 1,632,583,500 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 61 | 6,963,200 | n,v=map(int,input().split())
result=[]
for i in range(n):
l=list(map(int,input().split()))
b=l[1:]
li=0
for k in range(len(b)):
if(b[k]<v and li==0):
result.append(i+1)
li=1
print(sort(result))
| Title: Valera and Antique Items
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the... | ```python
n,v=map(int,input().split())
result=[]
for i in range(n):
l=list(map(int,input().split()))
b=l[1:]
li=0
for k in range(len(b)):
if(b[k]<v and li==0):
result.append(i+1)
li=1
print(sort(result))
``` | -1 | |
168 | A | Wizards and Demonstration | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city... | The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to... | Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). | [
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] | [
"1\n",
"0\n",
"1108\n"
] | In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 1... | 500 | [
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
... | 1,614,263,749 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | from math import ceil
n,w,perc=list(map(int,input().split()))
print(ceil(n*(perc/100))-w) | Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n... | ```python
from math import ceil
n,w,perc=list(map(int,input().split()))
print(ceil(n*(perc/100))-w)
``` | 0 | |
733 | A | Grasshopper And the String | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ... | The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100. | Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels. | [
"ABABBBACFEYUKOTT\n",
"AAA\n"
] | [
"4",
"1"
] | none | 500 | [
{
"input": "ABABBBACFEYUKOTT",
"output": "4"
},
{
"input": "AAA",
"output": "1"
},
{
"input": "A",
"output": "1"
},
{
"input": "B",
"output": "2"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU",
... | 1,655,550,376 | 2,147,483,647 | PyPy 3 | OK | TESTS | 70 | 93 | 0 | def solve(s:str):
a=[]
vowels=['A','E','I','O','U','Y']
flag=False
for i in range(0,len(s)):
if s[i] in vowels:
flag=True
a.append(i)
a.insert(0,-1)
a.append(len(s))
m=-1
if not flag:
print(len(s)+1)
else:
for i in ran... | Title: Grasshopper And the String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far en... | ```python
def solve(s:str):
a=[]
vowels=['A','E','I','O','U','Y']
flag=False
for i in range(0,len(s)):
if s[i] in vowels:
flag=True
a.append(i)
a.insert(0,-1)
a.append(len(s))
m=-1
if not flag:
print(len(s)+1)
else:
fo... | 3 | |
489 | B | BerSU Ball | PROGRAMMING | 1,200 | [
"dfs and similar",
"dp",
"graph matchings",
"greedy",
"sortings",
"two pointers"
] | null | null | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in eac... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of boys. The second line contains sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is the *i*-th boy's dancing skill.
Similarly, the third line contains an integer *m* (1<=≤<=*m*<=≤<=100) — the number of girls. The fourth l... | Print a single number — the required maximum possible number of pairs. | [
"4\n1 4 6 2\n5\n5 1 5 7 9\n",
"4\n1 2 3 4\n4\n10 11 12 13\n",
"5\n1 1 1 1 1\n3\n1 2 3\n"
] | [
"3\n",
"0\n",
"2\n"
] | none | 1,000 | [
{
"input": "4\n1 4 6 2\n5\n5 1 5 7 9",
"output": "3"
},
{
"input": "4\n1 2 3 4\n4\n10 11 12 13",
"output": "0"
},
{
"input": "5\n1 1 1 1 1\n3\n1 2 3",
"output": "2"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 10\n1\n9",
"output": "1"
},
{... | 1,687,093,972 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 81 | 77 | 1,638,400 | import bisect
left = lambda l,a : bisect.bisect_left(l,a) #returns index of value>=a
right = lambda l,a : bisect.bisect_right(l,a) #returns index of value >a
import sys
def input(): return sys.stdin.readline().strip()
def getints(): return map(int,sys.stdin.readline().strip().split())
n = int(input())
b = so... | Title: BerSU Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy... | ```python
import bisect
left = lambda l,a : bisect.bisect_left(l,a) #returns index of value>=a
right = lambda l,a : bisect.bisect_right(l,a) #returns index of value >a
import sys
def input(): return sys.stdin.readline().strip()
def getints(): return map(int,sys.stdin.readline().strip().split())
n = int(input(... | 3 | |
799 | A | Carrot Cakes | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady... | The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. | If it is reasonable to build the second oven, print "YES". Otherwise print "NO". | [
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] | In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whe... | 500 | [
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"... | 1,629,720,841 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 311 | 6,963,200 | import math
n,t,k,d=map(int,input().split())
x=math.ceil(n/k)*t
y,i=0,1
while n>0:
if i%t==0:
y=i
n-=k
# print(y,n)
if (i-d)>0 and (i-d)%t==0 and i!=d:
y=i
n-=k
# print(y,n)
i+=1
if y<x:
print("YES")
else:
print("NO") | Title: Carrot Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu... | ```python
import math
n,t,k,d=map(int,input().split())
x=math.ceil(n/k)*t
y,i=0,1
while n>0:
if i%t==0:
y=i
n-=k
# print(y,n)
if (i-d)>0 and (i-d)%t==0 and i!=d:
y=i
n-=k
# print(y,n)
i+=1
if y<x:
print("YES")
else:
print("NO")
``` | 3 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,692,904,688 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = int(input())
elif n % 2 == 0 and n != 2:
print("YES")
elif n % 2 == 1 or n == 2:
print("NO") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
n = int(input())
elif n % 2 == 0 and n != 2:
print("YES")
elif n % 2 == 1 or n == 2:
print("NO")
``` | -1 |
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should cons... | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letter... | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcde... | 1,638,042,177 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | import random
n,k = (int(i) for i in input('').split(' '))
alpha = 'abcdefghijklmnobqrstuvwxyz'
password = ''
distinct = []
i=0
for i in range(k):
ran = alpha[i]
for i in range(n):
password+=distinct[i%k]
print(password) | Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the foll... | ```python
import random
n,k = (int(i) for i in input('').split(' '))
alpha = 'abcdefghijklmnobqrstuvwxyz'
password = ''
distinct = []
i=0
for i in range(k):
ran = alpha[i]
for i in range(n):
password+=distinct[i%k]
print(password)
``` | -1 | |
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number ... | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25"... | 1,486,239,897 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 77 | 4,608,000 | string=input()
a,b=map(int,string.split(' '))
if a==0 and b==0:
print('NO')
elif a-b==1 or b-a==1:
print('YES')
elif a==b:
print('YES')
else:
print('NO')
| Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has so... | ```python
string=input()
a,b=map(int,string.split(' '))
if a==0 and b==0:
print('NO')
elif a-b==1 or b-a==1:
print('YES')
elif a==b:
print('YES')
else:
print('NO')
``` | 3 | |
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"... | 1,537,648,847 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 124 | 0 | ch=str(input())
n=int(ch)
res=0
if len(ch)>1:
for i in range(1,len(ch)):
res+=i*(10**i-10**(i-1))
res+=len(ch)*(n+1-10**(len(ch)-1))
print(res) | Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assig... | ```python
ch=str(input())
n=int(ch)
res=0
if len(ch)>1:
for i in range(1,len(ch)):
res+=i*(10**i-10**(i-1))
res+=len(ch)*(n+1-10**(len(ch)-1))
print(res)
``` | 3 | |
940 | C | Phone Numbers | PROGRAMMING | 1,500 | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | And where the are the phone numbers?
You are given a string *s* consisting of lowercase English letters and an integer *k*. Find the lexicographically smallest string *t* of length *k*, such that its set of letters is a subset of the set of letters of *s* and *s* is lexicographically smaller than *t*.
It's guaranteed... | The first line of input contains two space separated integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the length of *s* and the required length of *t*.
The second line of input contains the string *s* consisting of *n* lowercase English letters. | Output the string *t* conforming to the requirements above.
It's guaranteed that the answer exists. | [
"3 3\nabc\n",
"3 2\nabc\n",
"3 3\nayy\n",
"2 3\nba\n"
] | [
"aca\n",
"ac\n",
"yaa\n",
"baa\n"
] | In the first example the list of strings *t* of length 3, such that the set of letters of *t* is a subset of letters of *s* is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca. | 1,250 | [
{
"input": "3 3\nabc",
"output": "aca"
},
{
"input": "3 2\nabc",
"output": "ac"
},
{
"input": "3 3\nayy",
"output": "yaa"
},
{
"input": "2 3\nba",
"output": "baa"
},
{
"input": "1 3\nf",
"output": "fff"
},
{
"input": "3 1\nazz",
"output": "z"
},
... | 1,520,270,704 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 62 | 6,656,000 | def rec(i,s2,test):
if i<k:
if i==0:
rec(1,s2+s[i],0)
x=st.index(s[i])
if x+1<len(st):
rec(1,s2+st[x+1],1)
elif test:
rec(i+1,s2+st[0],1)
elif i<n:
rec(i+1,s2+s[i],0)
x=st.index(s[i])
... | Title: Phone Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
And where the are the phone numbers?
You are given a string *s* consisting of lowercase English letters and an integer *k*. Find the lexicographically smallest string *t* of length *k*, such that its set of letters is a ... | ```python
def rec(i,s2,test):
if i<k:
if i==0:
rec(1,s2+s[i],0)
x=st.index(s[i])
if x+1<len(st):
rec(1,s2+st[x+1],1)
elif test:
rec(i+1,s2+st[0],1)
elif i<n:
rec(i+1,s2+s[i],0)
x=st.index(s[i])... | -1 | |
557 | B | Pasha and Tea | PROGRAMMING | 1,500 | [
"constructive algorithms",
"implementation",
"math",
"sortings"
] | null | null | Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water.
It turned out that among Pasha's friends there are exactly *n* boys a... | The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters.
The second line of the input contains the sequence of integers *... | Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6. | [
"2 4\n1 1 1 1\n",
"3 18\n4 4 4 2 2 2\n",
"1 5\n2 3\n"
] | [
"3",
"18",
"4.5"
] | Pasha also has candies that he is going to give to girls but that is another task... | 1,000 | [
{
"input": "2 4\n1 1 1 1",
"output": "3.0000000000"
},
{
"input": "3 18\n4 4 4 2 2 2",
"output": "18.0000000000"
},
{
"input": "1 5\n2 3",
"output": "4.5000000000"
},
{
"input": "1 1\n1000000000 1000000000",
"output": "1.0000000000"
},
{
"input": "4 1000000000\n1 ... | 1,590,390,664 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 109 | 0 | n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort(reverse=True)
m=k
for i in range(2*n):
s=l[i]*n+(l[i]/2)*n
if(s<=k):
m=max(s,m)
print(m) | Title: Pasha and Tea
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most ... | ```python
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort(reverse=True)
m=k
for i in range(2*n):
s=l[i]*n+(l[i]/2)*n
if(s<=k):
m=max(s,m)
print(m)
``` | 0 | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,696,166,369 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | a = int(input())
b = list(map(int, input().split()))
ans = 0
maxh = b[0]
minh = b[0]
for i in range(a):
maxh = max(maxh, b[i])
minh = min(minh, b[i])
if b[i] > maxh:
ans += 1
if b[i] < minh:
ans += 1
print(ans)
| Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
a = int(input())
b = list(map(int, input().split()))
ans = 0
maxh = b[0]
minh = b[0]
for i in range(a):
maxh = max(maxh, b[i])
minh = min(minh, b[i])
if b[i] > maxh:
ans += 1
if b[i] < minh:
ans += 1
print(ans)
``` | 0 | |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,695,582,784 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 62 | 0 | inpa = input().split(' ')
inpb = input().split(' ')
counter = 0
for x in inpb:
if int(x) > int(inpa[1]):
counter += 2
else:
counter += 1
print(counter) | Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
inpa = input().split(' ')
inpb = input().split(' ')
counter = 0
for x in inpb:
if int(x) > int(inpa[1]):
counter += 2
else:
counter += 1
print(counter)
``` | 3 | |
366 | A | Dima and Guards | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can b... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers *a*,<=*b*,<=*c*,<=*d* (1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=105) — the minimum price of the chocolate and the minimum price of the juice for... | In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to t... | [
"10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9\n",
"10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8\n",
"5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3\n"
] | [
"1 5 5\n",
"3 4 6\n",
"-1\n"
] | Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fo... | 500 | [
{
"input": "10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9",
"output": "1 5 5"
},
{
"input": "10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8",
"output": "3 4 6"
},
{
"input": "5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3",
"output": "-1"
},
{
"input": "100000\n100000 100000 100000 100000\n100000 10... | 1,589,740,885 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 109 | 6,656,000 | n=int(input())
for i in range(4):
a,b,c,d=map(int,input().split())
a=min(a,b)
c=min(c,d)
if a+c<=n:
print(i+1,a,n-a)
break
else: print(-1)
| Title: Dima and Guards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardpost... | ```python
n=int(input())
for i in range(4):
a,b,c,d=map(int,input().split())
a=min(a,b)
c=min(c,d)
if a+c<=n:
print(i+1,a,n-a)
break
else: print(-1)
``` | 3 | |
389 | A | Fox and Number Game | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100). | Output a single integer — the required minimal sum. | [
"2\n1 2\n",
"3\n2 4 6\n",
"2\n12 18\n",
"5\n45 12 27 30 18\n"
] | [
"2\n",
"6\n",
"12\n",
"15\n"
] | In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub... | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n2 4 6",
"output": "6"
},
{
"input": "2\n12 18",
"output": "12"
},
{
"input": "5\n45 12 27 30 18",
"output": "15"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n100 100",
"output": "200"
... | 1,573,004,935 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 109 | 0 | n=int(input())
a=list(map(int,input().split()))
a.sort()
i=n-1
while i>0:
a[i]=a[i]-a[i-1]
i=i-1
x=min(a)
print(x*n)
| Title: Fox and Number Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that ... | ```python
n=int(input())
a=list(map(int,input().split()))
a.sort()
i=n-1
while i>0:
a[i]=a[i]-a[i-1]
i=i-1
x=min(a)
print(x*n)
``` | 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,637,120,237 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 512,000 | n=int(input())
l=list(map(int,input().split()))
for i in range(2,len(l)):
if l[i-2]%2==0 and l[i-1]%2==0 and l[i]%2==1:
print(i)
break
if l[i-2]%2==1 and l[i-1]%2==0 and l[i]%2==0:
print(i-2)
break
if l[i-2]%2==0 and l[i-1]%2==1 and l[i]%2==0:
print(i-1)
... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n=int(input())
l=list(map(int,input().split()))
for i in range(2,len(l)):
if l[i-2]%2==0 and l[i-1]%2==0 and l[i]%2==1:
print(i)
break
if l[i-2]%2==1 and l[i-1]%2==0 and l[i]%2==0:
print(i-2)
break
if l[i-2]%2==0 and l[i-1]%2==1 and l[i]%2==0:
prin... | 0 |
538 | A | Cutting Banner | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case ... | The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES. | Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes). | [
"CODEWAITFORITFORCES\n",
"BOTTOMCODER\n",
"DECODEFORCES\n",
"DOGEFORCES\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "CODEWAITFORITFORCES",
"output": "YES"
},
{
"input": "BOTTOMCODER",
"output": "NO"
},
{
"input": "DECODEFORCES",
"output": "YES"
},
{
"input": "DOGEFORCES",
"output": "NO"
},
{
"input": "ABACABA",
"output": "NO"
},
{
"input": "CODEFORCE",
... | 1,621,503,927 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 11 | 93 | 0 | s1=input()
s2='CODEFORCES'
n1,n2=len(s1),len(s2)
i,j = 0,0
while i<n1 and j<n2:
if s1[i]==s2[j]:
j+=1
i+=1
if j==n2:
print('YES')
else:
print('NO') | Title: Cutting Banner
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody ... | ```python
s1=input()
s2='CODEFORCES'
n1,n2=len(s1),len(s2)
i,j = 0,0
while i<n1 and j<n2:
if s1[i]==s2[j]:
j+=1
i+=1
if j==n2:
print('YES')
else:
print('NO')
``` | 0 | |
437 | A | The Child and Homework | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The chi... | The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description... | Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). | [
"A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"A.ab\nB.abcde\nC.ab\nD.abc\n",
"A.c\nB.cc\nC.c\nD.c\n"
] | [
"D\n",
"C\n",
"B\n"
] | In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no ... | 500 | [
{
"input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute",
"output": "D"
},
{
"input": "A.ab\nB.abcde\nC.ab\nD.abc",
"output": "C"
},
{
"input": "A.c\nB.cc\nC.c\nD.c",
"output": "B"
},
... | 1,595,488,935 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 109 | 6,656,000 | arr = sorted([(len(input())-2,i) for i in 'ABCD'])
p=0
if 2 * arr[0][0] <= arr[1][0]:
p+=1
if 2 * arr[-2][0] <= arr[-1][0]:
p+=2
print(['C',arr[0][1],arr[-1][1],'C'][p]) | Title: The Child and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should fin... | ```python
arr = sorted([(len(input())-2,i) for i in 'ABCD'])
p=0
if 2 * arr[0][0] <= arr[1][0]:
p+=1
if 2 * arr[-2][0] <= arr[-1][0]:
p+=2
print(['C',arr[0][1],arr[-1][1],'C'][p])
``` | 3 | |
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right aft... | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1... | 1,586,288,805 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 307,200 | n=int(input())
a=list(map(int,input().split()))
temp=[0]*(n+1)
block=[]
for i in range(n):
temp[a[i]]=1
coup=1
for j in range(a[i]+1,n+1):
if temp[j]!=1:
coup=0
break
if coup==1:
block.append(a[i])
block.sort(reverse=True)
print(*bloc... | Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents sh... | ```python
n=int(input())
a=list(map(int,input().split()))
temp=[0]*(n+1)
block=[]
for i in range(n):
temp[a[i]]=1
coup=1
for j in range(a[i]+1,n+1):
if temp[j]!=1:
coup=0
break
if coup==1:
block.append(a[i])
block.sort(reverse=True)
p... | 0 | |
558 | A | Lala Land and Apple Trees | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"sortings"
] | null | null | Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from t... | The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guarant... | Output the maximum number of apples Amr can collect. | [
"2\n-1 5\n1 5\n",
"3\n-2 2\n1 4\n-1 3\n",
"3\n1 9\n3 5\n7 10\n"
] | [
"10",
"9",
"9"
] | In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, ... | 500 | [
{
"input": "2\n-1 5\n1 5",
"output": "10"
},
{
"input": "3\n-2 2\n1 4\n-1 3",
"output": "9"
},
{
"input": "3\n1 9\n3 5\n7 10",
"output": "9"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000",
"output": "3... | 1,544,291,725 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 5 | 109 | 0 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 8 22:14:24 2018
@author: mach
"""
l= []
i = int(input())
for _ in range(i):
n,m = map(int, input().strip().split())
l.append((n,m))
l.sort(key = lambda x:x[0])
for i in range(len(l)):
if l[i][0] > 0:
g = i
break
sums =... | Title: Lala Land and Apple Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree num... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 8 22:14:24 2018
@author: mach
"""
l= []
i = int(input())
for _ in range(i):
n,m = map(int, input().strip().split())
l.append((n,m))
l.sort(key = lambda x:x[0])
for i in range(len(l)):
if l[i][0] > 0:
g = i
bre... | -1 | |
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,606,211,038 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 746 | 5,939,200 | # hashing,implementation
# https://codeforces.com/problemset/problem/2/A
# A. Winner
import sys
from typing import Dict
numInputs: int = int(sys.stdin.readline())
scoreMap: Dict[str, int] = {}
highScore: int = 0
highScoreName: str = ""
for _i in range(numInputs):
name, score = sys.stdin.readline().s... | 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
# hashing,implementation
# https://codeforces.com/problemset/problem/2/A
# A. Winner
import sys
from typing import Dict
numInputs: int = int(sys.stdin.readline())
scoreMap: Dict[str, int] = {}
highScore: int = 0
highScoreName: str = ""
for _i in range(numInputs):
name, score = sys.stdin.re... | 0 |
633 | B | A Trivial Problem | PROGRAMMING | 1,300 | [
"brute force",
"constructive algorithms",
"math",
"number theory"
] | null | null | Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem? | The only line of input contains an integer *m* (1<=≤<=*m*<=≤<=100<=000) — the required number of trailing zeroes in factorial. | First print *k* — the number of values of *n* such that the factorial of *n* ends with *m* zeroes. Then print these *k* integers in increasing order. | [
"1\n",
"5\n"
] | [
"5\n5 6 7 8 9 ",
"0"
] | The factorial of *n* is equal to the product of all integers from 1 to *n* inclusive, that is *n*! = 1·2·3·...·*n*.
In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880. | 500 | [
{
"input": "1",
"output": "5\n5 6 7 8 9 "
},
{
"input": "5",
"output": "0"
},
{
"input": "2",
"output": "5\n10 11 12 13 14 "
},
{
"input": "3",
"output": "5\n15 16 17 18 19 "
},
{
"input": "7",
"output": "5\n30 31 32 33 34 "
},
{
"input": "12",
"ou... | 1,461,004,996 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 327 | 27,136,000 | #import time
n = int(input())
#start = time.time()
some_dict = {0: [0,1,2,3,4]}
for i in range(1, 5):
some_dict[i] = list(map(lambda x: x + 5, some_dict[i-1]))
#print(some_dict)
count = 1
elements = 1
misses = 6
j = 0
for i in range(5, 100001):
j += 1
#print( 'i:', i, 'misses:', misses, 'j:', ... | Title: A Trivial Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zer... | ```python
#import time
n = int(input())
#start = time.time()
some_dict = {0: [0,1,2,3,4]}
for i in range(1, 5):
some_dict[i] = list(map(lambda x: x + 5, some_dict[i-1]))
#print(some_dict)
count = 1
elements = 1
misses = 6
j = 0
for i in range(5, 100001):
j += 1
#print( 'i:', i, 'misses:', miss... | 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,580,302,676 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 155 | 1,024,000 | import re
s=str(input())
if re.search("h.*e.*l.*l.*o", s):
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
import re
s=str(input())
if re.search("h.*e.*l.*l.*o", s):
print("YES")
else:
print("NO")
``` | 3.920593 |
23 | B | Party | PROGRAMMING | 1,600 | [
"constructive algorithms",
"graphs",
"math"
] | B. Party | 2 | 256 | *n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among those who stayed by the moment of their leaving, did the same.
What is the maximum amo... | The first input line contains one number *t* — amount of tests (1<=≤<=*t*<=≤<=105). Each of the following *t* lines contains one integer number *n* (1<=≤<=*n*<=≤<=105). | For each test output in a separate line one number — the maximum amount of people that could stay in the end. | [
"1\n3\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "1\n3",
"output": "1"
}
] | 1,666,435,472 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | # LUOGU_RID: 91028436
n=int(input())
print(0 if n==1 else n-2) | Title: Party
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among ... | ```python
# LUOGU_RID: 91028436
n=int(input())
print(0 if n==1 else n-2)
``` | 0 |
14 | A | Letter | PROGRAMMING | 800 | [
"implementation"
] | A. Letter | 1 | 64 | A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the w... | The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that ... | Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better. | [
"6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n",
"3 3\n***\n*.*\n***\n"
] | [
"***\n*..\n***\n*..\n***\n",
"***\n*.*\n***\n"
] | none | 0 | [
{
"input": "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..",
"output": "***\n*..\n***\n*..\n***"
},
{
"input": "3 3\n***\n*.*\n***",
"output": "***\n*.*\n***"
},
{
"input": "1 1\n*",
"output": "*"
},
{
"input": "2 1\n*\n*",
"output": "*\n*"
},
{
"input"... | 1,633,622,807 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 6,963,200 | #%%
rc=input().split()
r,c=[int(x) for x in rc]
matrix=[]
for i in range(r):
matrix.append(input())
max_i=0
max_j=0
min_i=r-1
min_j=c-1
for i in range(r):
for j in range(c):
if matrix[i][j]=='*':
if i<min_i:
min_i=i
if i>max_i:
max_... | Title: Letter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brothe... | ```python
#%%
rc=input().split()
r,c=[int(x) for x in rc]
matrix=[]
for i in range(r):
matrix.append(input())
max_i=0
max_j=0
min_i=r-1
min_j=c-1
for i in range(r):
for j in range(c):
if matrix[i][j]=='*':
if i<min_i:
min_i=i
if i>max_i:
... | 3.88612 |
340 | A | The Wall | PROGRAMMING | 1,200 | [
"math"
] | null | null | Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints th... | The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*). | Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink. | [
"2 3 6 18\n"
] | [
"3"
] | Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. | 500 | [
{
"input": "2 3 6 18",
"output": "3"
},
{
"input": "4 6 20 201",
"output": "15"
},
{
"input": "15 27 100 10000",
"output": "74"
},
{
"input": "105 60 3456 78910",
"output": "179"
},
{
"input": "1 1 1000 100000",
"output": "99001"
},
{
"input": "3 2 5 5... | 1,589,825,175 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 218 | 307,200 | def editor():
import sys
sys.stdin=open("input.txt",'r')
sys.stdout=open("output.txt",'w')
def solve():
x,y,a,b=I()
import math
# hcf=math.gcd(a, b)
# lcm= a*b//hcf
# print(lcm)
# ans=(b-a)//hcf
# ans=b//hcf - (a-1)//hcf
lcm=x*y//math.gcd(x,y)
ans=b//lcm - (a-1)//lcm
print(ans)
if __name... | Title: The Wall
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub ... | ```python
def editor():
import sys
sys.stdin=open("input.txt",'r')
sys.stdout=open("output.txt",'w')
def solve():
x,y,a,b=I()
import math
# hcf=math.gcd(a, b)
# lcm= a*b//hcf
# print(lcm)
# ans=(b-a)//hcf
# ans=b//hcf - (a-1)//hcf
lcm=x*y//math.gcd(x,y)
ans=b//lcm - (a-1)//lcm
print(ans)
... | 3 | |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportio... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ... | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39... | 1,692,825,526 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 122 | 0 | n=int(input())
sum=0
l=[]
l=list(map(int,input().split()))
for i in range(n):
sum =sum+l[i]
print(sum/n) | Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*... | ```python
n=int(input())
sum=0
l=[]
l=list(map(int,input().split()))
for i in range(n):
sum =sum+l[i]
print(sum/n)
``` | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,687,105,289 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 93 | 0 | n = int(input())
l = []
for i in range(n):
l.append(input())
if len(l[i]) <= 10:
print(l[i])
else:
print(l[i][0] + str(len(l[i]) - 2) + l[i][-1]) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
n = int(input())
l = []
for i in range(n):
l.append(input())
if len(l[i]) <= 10:
print(l[i])
else:
print(l[i][0] + str(len(l[i]) - 2) + l[i][-1])
``` | 3.9535 |
464 | A | No to Palindromes! | PROGRAMMING | 1,700 | [
"greedy",
"strings"
] | null | null | Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or more.
Paul has found a tolerable string *s* of length *n*. Help him find the lexicographically next to... | The first line contains two space-separated integers: *n* and *p* (1<=≤<=*n*<=≤<=1000; 1<=≤<=*p*<=≤<=26). The second line contains string *s*, consisting of *n* small English letters. It is guaranteed that the string is tolerable (according to the above definition). | If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes). | [
"3 3\ncba\n",
"3 4\ncba\n",
"4 4\nabcd\n"
] | [
"NO\n",
"cbd\n",
"abda\n"
] | String *s* is lexicographically larger (or simply larger) than string *t* with the same length, if there is number *i*, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, ..., *s*<sub class="lower-index">*i*</sub> = *t*<sub class="lower-index">*i*</sub>, *s*<sub class="lower-index">*i*... | 500 | [
{
"input": "3 3\ncba",
"output": "NO"
},
{
"input": "3 4\ncba",
"output": "cbd"
},
{
"input": "4 4\nabcd",
"output": "abda"
},
{
"input": "2 2\nab",
"output": "ba"
},
{
"input": "2 2\nba",
"output": "NO"
},
{
"input": "1 2\na",
"output": "b"
},
... | 1,634,647,482 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 78 | 0 | # Author Name: Ajay Meena
# Codeforce : https://codeforces.com/profile/majay1638
import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout
# -------------- INPUT FUNCTIONS ------------------
def get_ints_in_variables(): return map(
int, sys.stdin... | Title: No to Palindromes!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or... | ```python
# Author Name: Ajay Meena
# Codeforce : https://codeforces.com/profile/majay1638
import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout
# -------------- INPUT FUNCTIONS ------------------
def get_ints_in_variables(): return map(
int,... | 0 | |
202 | A | LLPS | PROGRAMMING | 800 | [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*... | The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. | Print the lexicographically largest palindromic subsequence of string *s*. | [
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] | [
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] | Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | 500 | [
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
... | 1,598,967,860 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 156 | 0 | n = intput()
a = max(n)
print(n.count(i)*a) | Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ... | ```python
n = intput()
a = max(n)
print(n.count(i)*a)
``` | -1 | |
869 | B | The Eternal Immortality | PROGRAMMING | 1,100 | [
"math"
] | null | null | Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! deno... | The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018). | Output one line containing a single decimal digit — the last digit of the value that interests Koyomi. | [
"2 4\n",
"0 10\n",
"107 109\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2;
In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso... | 1,000 | [
{
"input": "2 4",
"output": "2"
},
{
"input": "0 10",
"output": "0"
},
{
"input": "107 109",
"output": "2"
},
{
"input": "10 13",
"output": "6"
},
{
"input": "998244355 998244359",
"output": "4"
},
{
"input": "999999999000000000 1000000000000000000",
... | 1,606,980,560 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 5 | 93 | 0 | m,n=input().split()
m=int(m)
n=int(n)
if m==0:
m=m+1
if n==0:
n=n+1
factor=list(range(m+1,n+1))
f=1
for i in factor:
f=f*i
print(f%10)
| Title: The Eternal Immortality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like... | ```python
m,n=input().split()
m=int(m)
n=int(n)
if m==0:
m=m+1
if n==0:
n=n+1
factor=list(range(m+1,n+1))
f=1
for i in factor:
f=f*i
print(f%10)
``` | -1 | |
585 | A | Gennady the Dentist | PROGRAMMING | 1,800 | [
"brute force",
"implementation"
] | null | null | Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office.
All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to *n* in the order they go in the line. Every child is associated ... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=4000) — the number of kids in the line.
Next *n* lines contain three integers each *v**i*,<=*d**i*,<=*p**i* (1<=≤<=*v**i*,<=*d**i*,<=*p**i*<=≤<=106) — the volume of the cry in the doctor's office, the volume of the cry in the hall and the conf... | In the first line print number *k* — the number of children whose teeth Gennady will cure.
In the second line print *k* integers — the numbers of the children who will make it to the end of the line in the increasing order. | [
"5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n",
"5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n"
] | [
"2\n1 3 ",
"4\n1 2 4 5 "
] | In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to... | 500 | [
{
"input": "5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2",
"output": "2\n1 3 "
},
{
"input": "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9",
"output": "4\n1 2 4 5 "
},
{
"input": "10\n10 7 10\n3 6 11\n8 4 10\n10 1 11\n7 3 13\n7 2 13\n7 6 14\n3 4 17\n9 4 20\n5 2 24",
"output": "3\n1 2 5 "
},
{
... | 1,444,918,345 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | import io
import math
n=list(map(int,input().split()))
koldet=n[0]
spisokdet=[]
res=0
spisokvosh=[]
for i in range(koldet):
spisokdet.append(list(map(int,input().split())))
for i in range(koldet):
if spisokdet[i][0]>=0:
if spisokdet[i][2]>=0:
res+=1
spisokvosh.appe... | Title: Gennady the Dentist
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office.
All children love to cry loudly at the reception at the dentist. We enumer... | ```python
import io
import math
n=list(map(int,input().split()))
koldet=n[0]
spisokdet=[]
res=0
spisokvosh=[]
for i in range(koldet):
spisokdet.append(list(map(int,input().split())))
for i in range(koldet):
if spisokdet[i][0]>=0:
if spisokdet[i][2]>=0:
res+=1
spiso... | 0 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,693,232,270 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | n = int(input())
s = list(map(int, input().split()))
for i in range(0, len(s)):
print(s.index(i+1)+1, end='')
if i != len(s):
print(' ', end='')
| Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
n = int(input())
s = list(map(int, input().split()))
for i in range(0, len(s)):
print(s.index(i+1)+1, end='')
if i != len(s):
print(' ', end='')
``` | 3 | |
276 | D | Little Girl and Maximum XOR | PROGRAMMING | 1,700 | [
"bitmasks",
"dp",
"greedy",
"implementation",
"math"
] | null | null | A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers *l* and *r*. Let's consider the values of for all pairs of integers *a* and *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*). Your task is to find the maximum value among all considered ones.
Expression means applying bitw... | The single line contains space-separated integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | In a single line print a single integer — the maximum value of for all pairs of integers *a*, *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*). | [
"1 2\n",
"8 16\n",
"1 1\n"
] | [
"3\n",
"31\n",
"0\n"
] | none | 2,000 | [
{
"input": "1 2",
"output": "3"
},
{
"input": "8 16",
"output": "31"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "506 677",
"output": "1023"
},
{
"input": "33 910",
"output": "1023"
},
{
"input": "36 94",
"output": "127"
},
{
"input": ... | 1,642,912,228 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | p, q = map(int, input().split())
if p==q:
print(p^q)
else:
m=0
for i in range(p,q):
for j in range(i+1,q):
m = max(m,i^j)
print(m)
| Title: Little Girl and Maximum XOR
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers *l* and *r*. Let's consider the values of for all pairs of integers *a* and *b* (*l*<=≤<=*a*<=≤<... | ```python
p, q = map(int, input().split())
if p==q:
print(p^q)
else:
m=0
for i in range(p,q):
for j in range(i+1,q):
m = max(m,i^j)
print(m)
``` | 0 | |
110 | A | Nearly Lucky Number | PROGRAMMING | 800 | [
"implementation"
] | A. Nearly Lucky Number | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d... | The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). | [
"40047\n",
"7747774\n",
"1000000000000000000\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | 500 | [
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
... | 1,699,091,504 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | n = int(input())
digits = [int(i) for i in str(n)]
number_of_lucky_digits = digits.count(4) + digits.count(7)
if number_of_lucky_digits == 4 or number_of_lucky_digits == 7:
print('YES')
else:
print('NO') | Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n = int(input())
digits = [int(i) for i in str(n)]
number_of_lucky_digits = digits.count(4) + digits.count(7)
if number_of_lucky_digits == 4 or number_of_lucky_digits == 7:
print('YES')
else:
print('NO')
``` | 3.977 |
955 | C | Sad powers | PROGRAMMING | 2,100 | [
"binary search",
"math",
"number theory"
] | null | null | You're given *Q* queries of the form (*L*,<=*R*).
For each query you have to find the number of such *x* that *L*<=≤<=*x*<=≤<=*R* and there exist integer numbers *a*<=><=0, *p*<=><=1 such that *x*<==<=*a**p*. | The first line contains the number of queries *Q* (1<=≤<=*Q*<=≤<=105).
The next *Q* lines contains two integers *L*, *R* each (1<=≤<=*L*<=≤<=*R*<=≤<=1018). | Output *Q* lines — the answers to the queries. | [
"6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000\n"
] | [
"2\n1\n0\n3\n17\n1111\n"
] | In query one the suitable numbers are 1 and 4. | 1,500 | [
{
"input": "6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000",
"output": "2\n1\n0\n3\n17\n1111"
},
{
"input": "20\n862 928\n758 964\n541 789\n622 943\n328 900\n14 764\n217 972\n461 847\n442 468\n900 986\n518 529\n938 993\n549 851\n690 944\n484 601\n320 910\n98 868\n816 915\n765 880\n551 770",
"output... | 1,521,826,785 | 3,885 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 2 | 2,000 | 20,377,600 | def steps(a):
global num
p = 0
p += a
a *= a
while a <= 10 ** 18:
num.append(a)
a *= p
def bin_r(num, x):
r = len(num)
l = -1
while r - l > 1:
mid = (r + l) // 2
if num[mid] > x:
r = mid
else:
... | Title: Sad powers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given *Q* queries of the form (*L*,<=*R*).
For each query you have to find the number of such *x* that *L*<=≤<=*x*<=≤<=*R* and there exist integer numbers *a*<=><=0, *p*<=><=1 such that *x*<==<=*a**p*.
Input ... | ```python
def steps(a):
global num
p = 0
p += a
a *= a
while a <= 10 ** 18:
num.append(a)
a *= p
def bin_r(num, x):
r = len(num)
l = -1
while r - l > 1:
mid = (r + l) // 2
if num[mid] > x:
r = mid
... | 0 | |
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first positi... | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4... | 1,686,979,657 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 77 | 2,150,400 | n = int(input())
lst = list(map(int, input().split()))
cpy = lst.copy()
cpy.sort()
cpy.reverse()
res = [1 + cpy.index(x) for x in lst]
print(" ".join(str(x) for x in res)) | Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the star... | ```python
n = int(input())
lst = list(map(int, input().split()))
cpy = lst.copy()
cpy.sort()
cpy.reverse()
res = [1 + cpy.index(x) for x in lst]
print(" ".join(str(x) for x in res))
``` | 3 | |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,589,101,746 | 2,147,483,647 | PyPy 3 | OK | TESTS | 83 | 312 | 20,172,800 | sides = list(map(int, input().split()))
sides.sort()
if sides[0]+sides[1]>sides[2]:
print("TRIANGLE")
elif sides[1]+sides[2]>sides[3]:
print("TRIANGLE")
elif sides[1]+sides[2]==sides[3]:
print("SEGMENT")
elif sides[0]+sides[1]==sides[2]:
print("SEGMENT")
else:
print("IMPOSSIBLE") | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
sides = list(map(int, input().split()))
sides.sort()
if sides[0]+sides[1]>sides[2]:
print("TRIANGLE")
elif sides[1]+sides[2]>sides[3]:
print("TRIANGLE")
elif sides[1]+sides[2]==sides[3]:
print("SEGMENT")
elif sides[0]+sides[1]==sides[2]:
print("SEGMENT")
else:
print("IMPOSSIBLE"... | 3.771701 |
53 | C | Little Frog | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | C. Little Frog | 2 | 256 | Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For tha... | The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds. | Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1).
If there are several solutions, output any. | [
"2\n",
"3\n"
] | [
"1 2 ",
"1 3 2 "
] | none | 1,500 | [
{
"input": "2",
"output": "1 2 "
},
{
"input": "3",
"output": "1 3 2 "
},
{
"input": "4",
"output": "1 4 2 3 "
},
{
"input": "5",
"output": "1 5 2 4 3 "
},
{
"input": "6",
"output": "1 6 2 5 3 4 "
},
{
"input": "1",
"output": "1 "
},
{
"inp... | 1,621,862,488 | 2,147,483,647 | PyPy 3 | OK | TESTS | 22 | 186 | 5,529,600 | def solve():
n = int(input())
j=0
i=1
k=n
# print("k")
s = ""
if n%2==0:
while j<n:
s = s + str(k)+" "+str(i)+" "
k-=1
i+=1
j+=2
else:
while j<n-1:
s = s + str(k)+" "+str(i)+" "
i+=1
... | Title: Little Frog
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants ... | ```python
def solve():
n = int(input())
j=0
i=1
k=n
# print("k")
s = ""
if n%2==0:
while j<n:
s = s + str(k)+" "+str(i)+" "
k-=1
i+=1
j+=2
else:
while j<n-1:
s = s + str(k)+" "+str(i)+" "
... | 3.9432 |
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,504,096,539 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 0 | string = input()
a = sorted([int(char) for char in string[:3]])
b = sorted([int(char) for char in string[3:]])
count = 0
while sum(a) != sum(b):
if sum(a) < sum(b):
k = sum(b) - sum(a)
new = a.pop(0)
a.append(min(k + new, 9))
elif sum(a) > sum(b):
k = sum(a) - sum(b... | 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
string = input()
a = sorted([int(char) for char in string[:3]])
b = sorted([int(char) for char in string[3:]])
count = 0
while sum(a) != sum(b):
if sum(a) < sum(b):
k = sum(b) - sum(a)
new = a.pop(0)
a.append(min(k + new, 9))
elif sum(a) > sum(b):
k = sum(... | 0 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,687,933,698 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | n,c=map(int,input().split())
students=list(map(int,input().split()))
count=0
for i in students:
sub=(5-c)
if(sub>=i):
count+=1
ans=count//3
print(ans) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n,c=map(int,input().split())
students=list(map(int,input().split()))
count=0
for i in students:
sub=(5-c)
if(sub>=i):
count+=1
ans=count//3
print(ans)
``` | 3 | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,692,453,137 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input())
a = input().split()
b = input().split()
print(a, b)
ans = 0
for i in range(1, n+1):
if str(i) not in a:
if str(i) not in b:
print("Oh, my keyboard!")
ans = 1
break
if ans == 0:
print("I become the guy.") | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
n = int(input())
a = input().split()
b = input().split()
print(a, b)
ans = 0
for i in range(1, n+1):
if str(i) not in a:
if str(i) not in b:
print("Oh, my keyboard!")
ans = 1
break
if ans == 0:
print("I become the guy.")
``` | 0 | |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#... | 1,695,112,431 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | a,b=map(int,input())
pat1='#' * b +'\n'
pat2='.' * (b-1) + '#'
n=n//2
for i in range(n):
pattern=pat1+pat2
print(pattern)
pat2=pat2[::-1]
print(pat1) | Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*... | ```python
a,b=map(int,input())
pat1='#' * b +'\n'
pat2='.' * (b-1) + '#'
n=n//2
for i in range(n):
pattern=pat1+pat2
print(pattern)
pat2=pat2[::-1]
print(pat1)
``` | -1 | |
493 | B | Vasya and Wrestling | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of... | The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* poin... | If the first wrestler wins, print string "first", otherwise print "second" | [
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] | [
"second\n",
"first\n",
"second\n"
] | Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |... | 1,000 | [
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-... | 1,597,042,795 | 2,147,483,647 | PyPy 3 | OK | TESTS | 57 | 1,481 | 30,003,200 | n = int(input())
lastinp = 0
sums1 = 0
sums2 = 0
l = []
r = []
for i in range(0, n):
x = int(input())
if(x > 0):
sums1 += x
l.append(x)
else:
sums2 += abs(x)
r.append(abs(x))
lastinp = x
flag = -1
if(sums1 < sums2):
print("second")
elif(sum... | Title: Vasya and Wrestling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers ... | ```python
n = int(input())
lastinp = 0
sums1 = 0
sums2 = 0
l = []
r = []
for i in range(0, n):
x = int(input())
if(x > 0):
sums1 += x
l.append(x)
else:
sums2 += abs(x)
r.append(abs(x))
lastinp = x
flag = -1
if(sums1 < sums2):
print("second")... | 3 | |
25 | B | Phone numbers | PROGRAMMING | 1,100 | [
"implementation"
] | B. Phone numbers | 2 | 256 | Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups. | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | [
"6\n549871\n",
"7\n1198733\n"
] | [
"54-98-71",
"11-987-33\n"
] | none | 0 | [
{
"input": "6\n549871",
"output": "54-98-71"
},
{
"input": "7\n1198733",
"output": "119-87-33"
},
{
"input": "2\n74",
"output": "74"
},
{
"input": "2\n33",
"output": "33"
},
{
"input": "3\n074",
"output": "074"
},
{
"input": "3\n081",
"output": "08... | 1,630,173,101 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 154 | 6,963,200 | # بسم الله الرحمن الرحيم
def main():
n = int(input())
assert n >= 2
phone = input()
if n == 2 or n == 3:
print(phone)
return
remember = ''
for i in range(0, len(phone), 2):
rem = n - i
if rem == 3 or rem == 2:
remember += phone[i:]
... | Title: Phone numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33.... | ```python
# بسم الله الرحمن الرحيم
def main():
n = int(input())
assert n >= 2
phone = input()
if n == 2 or n == 3:
print(phone)
return
remember = ''
for i in range(0, len(phone), 2):
rem = n - i
if rem == 3 or rem == 2:
remember += phone[i:... | 3.94853 |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,681,316,615 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 31 | 46 | 0 | n, k = map(int, input().split())
data = sorted(map(int, input().split()))
while data[-1] + k > 5:
data.pop()
print(len(data) // 3) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n, k = map(int, input().split())
data = sorted(map(int, input().split()))
while data[-1] + k > 5:
data.pop()
print(len(data) // 3)
``` | -1 | |
747 | A | Display Size | PROGRAMMING | 800 | [
"brute force",
"math"
] | null | null | A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that:
- there are exactly *n* pixels o... | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have. | Print two integers — the number of rows and columns on the display. | [
"8\n",
"64\n",
"5\n",
"999999\n"
] | [
"2 4\n",
"8 8\n",
"1 5\n",
"999 1001\n"
] | In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 ro... | 500 | [
{
"input": "8",
"output": "2 4"
},
{
"input": "64",
"output": "8 8"
},
{
"input": "5",
"output": "1 5"
},
{
"input": "999999",
"output": "999 1001"
},
{
"input": "716539",
"output": "97 7387"
},
{
"input": "1",
"output": "1 1"
},
{
"input":... | 1,594,728,937 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 109 | 6,758,400 | n=int(input())
a=[]
x=int(n**(1/2))
# print(x)
for i in range(1,x+1):
if n%i==0:
a.append((i,n//i))
print(*max(a)) | Title: Display Size
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) ... | ```python
n=int(input())
a=[]
x=int(n**(1/2))
# print(x)
for i in range(1,x+1):
if n%i==0:
a.append((i,n//i))
print(*max(a))
``` | 3 | |
765 | D | Artsem and Saunders | PROGRAMMING | 1,700 | [
"constructive algorithms",
"dsu",
"math"
] | null | null | Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [*n*] denote the set {1,<=...,<=*n*}. We will also write *f*:<=[*x*]<=→<=[*y*] when a function *f* is defined in integer points 1, ..., *x*, and all its values are integers from 1 to *y*.
Now then, you are ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers — values *f*(1),<=...,<=*f*(*n*) (1<=≤<=*f*(*i*)<=≤<=*n*). | If there is no answer, print one integer -1.
Otherwise, on the first line print the number *m* (1<=≤<=*m*<=≤<=106). On the second line print *n* numbers *g*(1),<=...,<=*g*(*n*). On the third line print *m* numbers *h*(1),<=...,<=*h*(*m*).
If there are several correct answers, you may output any of them. It is guarant... | [
"3\n1 2 3\n",
"3\n2 2 2\n",
"2\n2 1\n"
] | [
"3\n1 2 3\n1 2 3\n",
"1\n1 1 1\n2\n",
"-1\n"
] | none | 2,000 | [
{
"input": "3\n1 2 3",
"output": "3\n1 2 3\n1 2 3"
},
{
"input": "3\n2 2 2",
"output": "1\n1 1 1\n2"
},
{
"input": "2\n2 1",
"output": "-1"
},
{
"input": "1\n1",
"output": "1\n1\n1"
},
{
"input": "2\n2 1",
"output": "-1"
},
{
"input": "2\n2 2",
"ou... | 1,487,070,195 | 10,695 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 17 | 2,000 | 11,980,800 | n = int(input())
f = [0] + list(map(int, input().split()))
possible = True
for x in range(1, n + 1):
if f[f[x]] != f[x]:
possible = False
break
if possible:
m = len(set(f[1:]))
h = sorted(set(f))
g = [0]
for x in range(1, n+1):
g.append(h.index(f[x]))
print(m)
print(*... | Title: Artsem and Saunders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [*n*] denote the set {1,<=...,<=*n*}. We will also write *f*:<=[*x*]<=→<=[*y*] when a function *f* is ... | ```python
n = int(input())
f = [0] + list(map(int, input().split()))
possible = True
for x in range(1, n + 1):
if f[f[x]] != f[x]:
possible = False
break
if possible:
m = len(set(f[1:]))
h = sorted(set(f))
g = [0]
for x in range(1, n+1):
g.append(h.index(f[x]))
print(m)
... | 0 | |
518 | A | Vitaly and Strings | PROGRAMMING | 1,600 | [
"constructive algorithms",
"strings"
] | null | null | Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase Engli... | The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string.
The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings *s* and *t* are the same and str... | If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them. | [
"a\nc\n",
"aaa\nzzz\n",
"abcdefg\nabcdefh\n"
] | [
"b\n",
"kkk\n",
"No such string\n"
] | String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that ... | 500 | [
{
"input": "a\nc",
"output": "b"
},
{
"input": "aaa\nzzz",
"output": "kkk"
},
{
"input": "abcdefg\nabcdefh",
"output": "No such string"
},
{
"input": "abcdefg\nabcfefg",
"output": "abcdefh"
},
{
"input": "frt\nfru",
"output": "No such string"
},
{
"inp... | 1,621,935,466 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 13 | 92 | 0 | a=input()
b=input()
x=len(a)
s=b[:x-1]+chr(ord(b[-1])-1)
if s>a and s<b:
print(s)
else:
print("No such string") | Title: Vitaly and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provi... | ```python
a=input()
b=input()
x=len(a)
s=b[:x-1]+chr(ord(b[-1])-1)
if s>a and s<b:
print(s)
else:
print("No such string")
``` | 0 | |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,697,213,627 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | def es(m):
r=-1
c=-1
risr=2
risc=2
for i in range(len(m)):
for j in range (len(m)):
if m[i][j]==1:
r=i
c=j
break
return abs(risr-r)+abs(risc-c) | Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
def es(m):
r=-1
c=-1
risr=2
risc=2
for i in range(len(m)):
for j in range (len(m)):
if m[i][j]==1:
r=i
c=j
break
return abs(risr-r)+abs(risc-c)
``` | 0 | |
901 | A | Hashing Trees | PROGRAMMING | 1,500 | [
"constructive algorithms",
"trees"
] | null | null | Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of tree... | The first line contains a single integer *h* (2<=≤<=*h*<=≤<=105) — the height of the tree.
The second line contains *h*<=+<=1 integers — the sequence *a*0,<=*a*1,<=...,<=*a**h* (1<=≤<=*a**i*<=≤<=2·105). The sum of all *a**i* does not exceed 2·105. It is guaranteed that there is at least one tree matching this sequence... | If there is only one tree matching this sequence, print "perfect".
Otherwise print "ambiguous" in the first line. In the second and in the third line print descriptions of two trees in the following format: in one line print integers, the *k*-th of them should be the parent of vertex *k* or be equal to zero, if the *... | [
"2\n1 1 1\n",
"2\n1 2 2\n"
] | [
"perfect\n",
"ambiguous\n0 1 1 3 3\n0 1 1 3 2\n"
] | The only tree in the first example and the two printed trees from the second example are shown on the picture:
<img class="tex-graphics" src="https://espresso.codeforces.com/ae5d1889e09854f9d8ad6e29ab7afbe690ca4702.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 500 | [
{
"input": "2\n1 1 1",
"output": "perfect"
},
{
"input": "2\n1 2 2",
"output": "ambiguous\n0 1 1 3 3\n0 1 1 3 2"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1 1",
"output": "perfect"
},
{
"input": "10\n1 1 1 1 1 2 1 1 1 1 1",
"output": "perfect"
},
{
"input": "10\n1 1 1 ... | 1,659,333,322 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 62 | 2,867,200 | class tree ( object ) :
def __init__( self , data , parent=None ) :
self.data = data
self.children = [ ]
self.parent = parent
def __str__( self ) :
return str ( self.data )
def addChild( self , obj ) :
self.children.append ( obj )
def getChildren( s... | Title: Hashing Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she gue... | ```python
class tree ( object ) :
def __init__( self , data , parent=None ) :
self.data = data
self.children = [ ]
self.parent = parent
def __str__( self ) :
return str ( self.data )
def addChild( self , obj ) :
self.children.append ( obj )
def getC... | -1 | |
747 | B | Mammoth's Genome Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s... | The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome.
The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. | If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). | [
"8\nAG?C??CT\n",
"4\nAGCT\n",
"6\n????G?\n",
"4\nAA??\n"
] | [
"AGACGTCT\n",
"AGCT\n",
"===\n",
"===\n"
] | In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is ... | 1,000 | [
{
"input": "8\nAG?C??CT",
"output": "AGACGTCT"
},
{
"input": "4\nAGCT",
"output": "AGCT"
},
{
"input": "6\n????G?",
"output": "==="
},
{
"input": "4\nAA??",
"output": "==="
},
{
"input": "4\n????",
"output": "ACGT"
},
{
"input": "252\n???????GCG??T??TT... | 1,622,099,456 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n=int(input())
str=input()
if n%4!=0:
print('===')
else:
for i in 'ACGT':
if 4*str.count(i)>n:
print('===')
r=''
for i in 'ACGT':
r+=i*(n//4-str.count(i))
j=0
res=""
for i in range(len(str)):
if str[i]=='?':
res+=r[j]
j+=1
else:
res+=str[i]
print(res)
| Title: Mammoth's Genome Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter... | ```python
n=int(input())
str=input()
if n%4!=0:
print('===')
else:
for i in 'ACGT':
if 4*str.count(i)>n:
print('===')
r=''
for i in 'ACGT':
r+=i*(n//4-str.count(i))
j=0
res=""
for i in range(len(str)):
if str[i]=='?':
res+=r[j]
j+=1
else:
res+=str[i]
print(res)
... | 0 | |
862 | A | Mahmoud and Ehab and the MEX | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX... | The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX.
The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set. | The only line should contain one integer — the minimal number of operations Dr. Evil should perform. | [
"5 3\n0 4 5 6 7\n",
"1 0\n0\n",
"5 0\n1 2 3 4 5\n"
] | [
"2\n",
"1\n",
"0\n"
] | For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.
For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.
In the third test case the set is already evil. | 500 | [
{
"input": "5 3\n0 4 5 6 7",
"output": "2"
},
{
"input": "1 0\n0",
"output": "1"
},
{
"input": "5 0\n1 2 3 4 5",
"output": "0"
},
{
"input": "10 5\n57 1 47 9 93 37 76 70 78 15",
"output": "4"
},
{
"input": "10 5\n99 98 93 97 95 100 92 94 91 96",
"output": "5"
... | 1,597,637,331 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | # 已经存在--剔除(1步)
# 不存在--加入(x-n({y:y<x}))
#
# Input
# 5 3
# 0 4 5 6 7
# Output
# 2
# #
if __name__ == "__main__":
n,x= map(int, input().split())
Nums = list(map(int, input().split()))
step=x
for i in Nums:
if i<x:
step-=1
if Nums.count(x)>0:
step+=1
print(ste... | Title: Mahmoud and Ehab and the MEX
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in ... | ```python
# 已经存在--剔除(1步)
# 不存在--加入(x-n({y:y<x}))
#
# Input
# 5 3
# 0 4 5 6 7
# Output
# 2
# #
if __name__ == "__main__":
n,x= map(int, input().split())
Nums = list(map(int, input().split()))
step=x
for i in Nums:
if i<x:
step-=1
if Nums.count(x)>0:
step+=1
... | -1 | |
818 | B | Permutation Game | PROGRAMMING | 1,600 | [
"implementation"
] | null | null | *n* children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation *a*1,<=*a*2,<=...,<=*a**n* of length *n*. It is an integer sequence such that each integer from 1 to *n* appears exactly once in it.
The game consists of *m* steps. On each step the current leader with in... | The first line contains two integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains *m* integer numbers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*) — indices of leaders in the beginning of each step. | Print such permutation of *n* numbers *a*1,<=*a*2,<=...,<=*a**n* that leaders in the game will be exactly *l*1,<=*l*2,<=...,<=*l**m* if all the rules are followed. If there are multiple solutions print any of them.
If there is no permutation which satisfies all described conditions print -1. | [
"4 5\n2 3 1 4 4\n",
"3 3\n3 1 2\n"
] | [
"3 1 2 4 \n",
"-1\n"
] | Let's follow leadership in the first example:
- Child 2 starts. - Leadership goes from 2 to 2 + *a*<sub class="lower-index">2</sub> = 3. - Leadership goes from 3 to 3 + *a*<sub class="lower-index">3</sub> = 5. As it's greater than 4, it's going in a circle to 1. - Leadership goes from 1 to 1 + *a*<sub class="lowe... | 0 | [
{
"input": "4 5\n2 3 1 4 4",
"output": "3 1 2 4 "
},
{
"input": "3 3\n3 1 2",
"output": "-1"
},
{
"input": "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | 1,622,604,885 | 1,485 | PyPy 3 | RUNTIME_ERROR | TESTS | 1 | 249 | 3,891,200 | import sys
#import random
from bisect import bisect_left as lb
from collections import deque
#sys.setrecursionlimit(10**8)
from queue import PriorityQueue as pq
from math import *
input_ = lambda: sys.stdin.readline().strip("\r\n")
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf... | Title: Permutation Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation *a*1,<=*a*2,<=...,<=*a**n* of length *n*. It is an integer sequence such that each integer from 1 to *n... | ```python
import sys
#import random
from bisect import bisect_left as lb
from collections import deque
#sys.setrecursionlimit(10**8)
from queue import PriorityQueue as pq
from math import *
input_ = lambda: sys.stdin.readline().strip("\r\n")
ii = lambda : int(input_())
il = lambda : list(map(int, input_().spli... | -1 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite if it contains finite number of numerals after the decimal point. It is also possible that... | The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of queries.
Next $n$ lines contain queries, one per line. Each line contains three integers $p$, $q$, and $b$ ($0 \le p \le 10^{18}$, $1 \le q \le 10^{18}$, $2 \le b \le 10^{18}$). All numbers are given in notation with base $10$. | For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. | [
"2\n6 12 10\n4 3 10\n",
"4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n"
] | [
"Finite\nInfinite\n",
"Finite\nFinite\nFinite\nInfinite\n"
] | $\frac{6}{12} = \frac{1}{2} = 0,5_{10}$
$\frac{4}{3} = 1,(3)_{10}$
$\frac{9}{36} = \frac{1}{4} = 0,01_2$
$\frac{4}{12} = \frac{1}{3} = 0,1_3$ | 0 | [
{
"input": "2\n6 12 10\n4 3 10",
"output": "Finite\nInfinite"
},
{
"input": "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4",
"output": "Finite\nFinite\nFinite\nInfinite"
},
{
"input": "10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8 2",
"output": "Finite\nInfinite\nInfini... | 1,560,125,589 | 5,889 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | tc = int(input())
while tc>0:
p,q,b = [int(i) for i in input().split()]
dec = abs(int(p/q)-(p/q))
finite = True
k = 1
curr = 1
dop = 0
while(dec!=0):
curr *= 1/b
kt = b-1
while(kt>0):
ta = curr
ta *= kt
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite ... | ```python
tc = int(input())
while tc>0:
p,q,b = [int(i) for i in input().split()]
dec = abs(int(p/q)-(p/q))
finite = True
k = 1
curr = 1
dop = 0
while(dec!=0):
curr *= 1/b
kt = b-1
while(kt>0):
ta = curr
ta *= kt
... | 0 | |
525 | C | Ilya and Sticks | PROGRAMMING | 1,600 | [
"greedy",
"math",
"sortings"
] | null | null | In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of *n* sticks and an instrument. Each stick is characterized by its length *l**i*.
Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way tha... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of the available sticks.
The second line of the input contains *n* positive integers *l**i* (2<=≤<=*l**i*<=≤<=106) — the lengths of the sticks. | The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks. | [
"4\n2 4 4 2\n",
"4\n2 2 3 5\n",
"4\n100003 100004 100005 100006\n"
] | [
"8\n",
"0\n",
"10000800015\n"
] | none | 1,000 | [
{
"input": "4\n2 4 4 2",
"output": "8"
},
{
"input": "4\n2 2 3 5",
"output": "0"
},
{
"input": "4\n100003 100004 100005 100006",
"output": "10000800015"
},
{
"input": "8\n5 3 3 3 3 4 4 4",
"output": "25"
},
{
"input": "10\n123 124 123 124 2 2 2 2 9 9",
"output... | 1,427,407,220 | 2,147,483,647 | PyPy 3 | OK | TESTS | 96 | 389 | 53,657,600 | n = int(input())
l = list(map(int, input().split()))
m = {}
m2 = set()
for i in range(1, 10**6 + 1):
m[i] = 0
for i in range(n):
m[l[i]] += 1
m2.add(l[i])
if l[i] >= 2:
m2.add(l[i] - 1)
m1 = []
for i in range(10**6, 1, -1):
if m[i] % 2 == 1 and m[i - 1] > 0:
m[i] -= 1... | Title: Ilya and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of *n* sticks and an instrument. Each stick is characterized by its length *l**i*.
Ilya decided to m... | ```python
n = int(input())
l = list(map(int, input().split()))
m = {}
m2 = set()
for i in range(1, 10**6 + 1):
m[i] = 0
for i in range(n):
m[l[i]] += 1
m2.add(l[i])
if l[i] >= 2:
m2.add(l[i] - 1)
m1 = []
for i in range(10**6, 1, -1):
if m[i] % 2 == 1 and m[i - 1] > 0:
... | 3 | |
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains... | The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
... | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "... | 1,588,246,700 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 310 | 0 | n,m = input().split()
m = int(m)
s=''
ans = 0
for i in range(int(n)):
temp = str(input())
if 'S' not in temp:
ans = ans+m
temp=''
s = s + temp
for j in range(int(m)):
temp = ''
while j<len(s):
temp = temp + s[j]
j = j+int(m)
if 'S' not in temp:
... | Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each ti... | ```python
n,m = input().split()
m = int(m)
s=''
ans = 0
for i in range(int(n)):
temp = str(input())
if 'S' not in temp:
ans = ans+m
temp=''
s = s + temp
for j in range(int(m)):
temp = ''
while j<len(s):
temp = temp + s[j]
j = j+int(m)
if 'S' not in ... | 3 | |
544 | A | Set of Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | You are given a string *q*. A sequence of *k* strings *s*1,<=*s*2,<=...,<=*s**k* is called beautiful, if the concatenation of these strings is string *q* (formally, *s*1<=+<=*s*2<=+<=...<=+<=*s**k*<==<=*q*) and the first characters of these strings are distinct.
Find any beautiful sequence of strings or determine that... | The first line contains a positive integer *k* (1<=≤<=*k*<=≤<=26) — the number of strings that should be in a beautiful sequence.
The second line contains string *q*, consisting of lowercase Latin letters. The length of the string is within range from 1 to 100, inclusive. | If such sequence doesn't exist, then print in a single line "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes) and in the next *k* lines print the beautiful sequence of strings *s*1,<=*s*2,<=...,<=*s**k*.
If there are multiple possible answers, print any of them. | [
"1\nabca\n",
"2\naaacas\n",
"4\nabc\n"
] | [
"YES\nabca\n",
"YES\naaa\ncas\n",
"NO\n"
] | In the second sample there are two possible answers: {"*aaaca*", "*s*"} and {"*aaa*", "*cas*"}. | 500 | [
{
"input": "1\nabca",
"output": "YES\nabca"
},
{
"input": "2\naaacas",
"output": "YES\naaa\ncas"
},
{
"input": "4\nabc",
"output": "NO"
},
{
"input": "3\nnddkhkhkdndknndkhrnhddkrdhrnrrnkkdnnndndrdhnknknhnrnnkrrdhrkhkrkhnkhkhhrhdnrndnknrrhdrdrkhdrkkhkrnkk",
"output": "YES\... | 1,439,565,492 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | n = int(input())
s = input()
point = 1
ans = str()
used = set(s[0])
last_point = 0
for i in range(n - 1):
while point <= len(s) and s[point - 1] in used:
point += 1
if point <= len(s):
used.add(s[point - 1])
ans += s[last_point:point - 1] + '\n'
last_point = point - 1... | Title: Set of Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *q*. A sequence of *k* strings *s*1,<=*s*2,<=...,<=*s**k* is called beautiful, if the concatenation of these strings is string *q* (formally, *s*1<=+<=*s*2<=+<=...<=+<=*s**k*<==<=*q*) and the first... | ```python
n = int(input())
s = input()
point = 1
ans = str()
used = set(s[0])
last_point = 0
for i in range(n - 1):
while point <= len(s) and s[point - 1] in used:
point += 1
if point <= len(s):
used.add(s[point - 1])
ans += s[last_point:point - 1] + '\n'
last_point =... | 3 | |
3 | A | Shortest path of the king | PROGRAMMING | 1,000 | [
"greedy",
"shortest paths"
] | A. Shortest path of the king | 1 | 64 | The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the le... | The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. | In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diago... | [
"a8\nh1\n"
] | [
"7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n"
] | none | 0 | [
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "b2\nb4",
"output": "2\nU\nU"
},
{
"input": "a5\na5",
"output": "0"
},
{
"input": "h1\nb2",
"output": "6\nLU\nL\nL\nL\nL\nL"
},
{
"input": "c5\nh2",
"output": "5\nRD\nRD\nRD\nR\nR"
... | 1,664,265,585 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | print("YES") if int(input()) % 2 ==0 else "NO" | Title: Shortest path of the king
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king ... | ```python
print("YES") if int(input()) % 2 ==0 else "NO"
``` | -1 |
454 | B | Little Pony and Sort by Shift | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | [
"2\n2 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"1\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 3 2",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "6\n3 4 5 6 3 2",
"output": "-1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n1 1 2 1 1",
"output": "2"
}... | 1,607,411,705 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 155 | 7,065,600 | n = int(input())
z = list(map(int,input().split()))
z.insert(0,z[-1])
cnt = 0
pos = 0
for i in range(0,n):
if z[i] > z[i+1] :
cnt += 1
pos = i
if cnt > 1 :
print(-1)
else :
print((n-pos)%n) | Title: Little Pony and Sort by Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. ... | ```python
n = int(input())
z = list(map(int,input().split()))
z.insert(0,z[-1])
cnt = 0
pos = 0
for i in range(0,n):
if z[i] > z[i+1] :
cnt += 1
pos = i
if cnt > 1 :
print(-1)
else :
print((n-pos)%n)
``` | 3 | |
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million... | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "N... | 1,692,928,928 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 19 | 92 | 0 | import math
def petriciumus_cifera(k, l):
n = math.log(l, k)
return n == int(n), int(n - 1)
cifera, importance = petriciumus_cifera(k=int(input()), l=int(input()))
if cifera:
print('YES')
print(importance)
else:
print('NO') | Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa... | ```python
import math
def petriciumus_cifera(k, l):
n = math.log(l, k)
return n == int(n), int(n - 1)
cifera, importance = petriciumus_cifera(k=int(input()), l=int(input()))
if cifera:
print('YES')
print(importance)
else:
print('NO')
``` | 0 | |
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (withou... | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa... | 1,674,490,272 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 1,403 | 9,625,600 | s=0
for i in range(int(input())):
x=input()
if x=="Tetrahedron":
s=s+4
elif x=="Cube":
s=s+6
elif x=="Octahedron":
s=s+8
elif x=="Dodecahedron":
s=s+12
else:
s=s+20
print(s) | Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe... | ```python
s=0
for i in range(int(input())):
x=input()
if x=="Tetrahedron":
s=s+4
elif x=="Cube":
s=s+6
elif x=="Octahedron":
s=s+8
elif x=="Dodecahedron":
s=s+12
else:
s=s+20
print(s)
``` | 3 | |
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats num... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on,... | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The ligh... | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 ... | 1,501,256,195 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 77 | 4,710,400 | n, m = [int(i) for i in input().split()]
ans = 0
for _ in range(n):
a = [int(i) for i in input().split()]
b = [0]*m
for i in range(m):
if a[2*i] + a[2*i+1] > 0:
ans += 1
print (ans) | Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vital... | ```python
n, m = [int(i) for i in input().split()]
ans = 0
for _ in range(n):
a = [int(i) for i in input().split()]
b = [0]*m
for i in range(m):
if a[2*i] + a[2*i+1] > 0:
ans += 1
print (ans)
``` | 3 | |
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,117,889 | 789 | Python 3 | CHALLENGED | CHALLENGES | 7 | 77 | 7,065,600 | s = input()
a = [0, 0, 0]
if s[0] == "a" and (s.count("a") == s.count("c") or s.count("b") == s.count("c")) and not "ba" in s and not "cb" in s:
print("YES")
else:
print("NO")
| 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()
a = [0, 0, 0]
if s[0] == "a" and (s.count("a") == s.count("c") or s.count("b") == s.count("c")) and not "ba" in s and not "cb" in s:
print("YES")
else:
print("NO")
``` | -1 | |
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,673,724,095 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | arr = list(map(int, input().split()))
area_square=arr[0]*arr[1]
flagStone=(area_square//(arr[2])**2)+2
print(flagStone)
# print(arr)
# print(area_square) | 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
arr = list(map(int, input().split()))
area_square=arr[0]*arr[1]
flagStone=(area_square//(arr[2])**2)+2
print(flagStone)
# print(arr)
# print(area_square)
``` | 0 |
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* woode... | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal... | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ... | 1,643,182,803 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 57 | 374 | 5,427,200 | n = int(input())
lefto=0
righto=0
s=0
for i in range(0,n):
inputs = [(num) for num in input().split()]
if(inputs[0]=="1"):
lefto+=1
if(inputs[1]=="1"):
righto+=1
if(lefto>int(n/2)):
s+=n-lefto
else:
s+=lefto
if(righto>int(n/2)):
s+=n-righto
else:
s+=righto
p... | 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())
lefto=0
righto=0
s=0
for i in range(0,n):
inputs = [(num) for num in input().split()]
if(inputs[0]=="1"):
lefto+=1
if(inputs[1]=="1"):
righto+=1
if(lefto>int(n/2)):
s+=n-lefto
else:
s+=lefto
if(righto>int(n/2)):
s+=n-righto
else:
s+... | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,649,044,551 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 154 | 0 | m,n=list(map(int,input().split()))
ans=(m*n)//2
print(ans) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m,n=list(map(int,input().split()))
ans=(m*n)//2
print(ans)
``` | 3.9615 |
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"ou... | 1,650,903,935 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 1,000 | 102,400 | n,m=map(int,input().split())
fact1=1
fact2=1
for i in range(1,n+1):
fact1=fact1*i
for j in range(1,m+1):
fact2=fact2*j
def computeGCD(fact1,fact2):
if fact1 > fact2:
small = fact2
else:
small = fact1
for i in range(1, small+1):
if((fact1 % i == 0) and (fact2 % i == 0)):
... | Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi... | ```python
n,m=map(int,input().split())
fact1=1
fact2=1
for i in range(1,n+1):
fact1=fact1*i
for j in range(1,m+1):
fact2=fact2*j
def computeGCD(fact1,fact2):
if fact1 > fact2:
small = fact2
else:
small = fact1
for i in range(1, small+1):
if((fact1 % i == 0) and (fact2 % i ... | 0 | |
20 | B | Equation | PROGRAMMING | 2,000 | [
"math"
] | B. Equation | 1 | 256 | You are given an equation:
Your task is to find the number of distinct roots of the equation and print all of them in ascending order. | The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=105<=≤<=*A*,<=*B*,<=*C*<=≤<=105). Any coefficient may be equal to 0. | In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point. | [
"1 -5 6\n"
] | [
"2\n2.0000000000\n3.0000000000"
] | none | 1,000 | [
{
"input": "1 -5 6",
"output": "2\n2.0000000000\n3.0000000000"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 2 1",
"output": "1\n-1.0000000000"
},
{
"input": "0 0 0",
"output": "-1"
},
{
"input": "0 -2 1",
"output": "1\n0.5000000000"
},
{
"inpu... | 1,655,747,274 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 15 | 0 | import math
a,b,c = map(int,input().split())
d=b*b-4*a*c
if d==0:
print(1)
print(-b/(2*a))
elif d<0:
print(-1)
else:
dd= math.sqrt(d)
print(2)
print((-b-dd)/(2*a))
print((-b+dd)/(2*a)) | Title: Equation
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given an equation:
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input Specification:
The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=1... | ```python
import math
a,b,c = map(int,input().split())
d=b*b-4*a*c
if d==0:
print(1)
print(-b/(2*a))
elif d<0:
print(-1)
else:
dd= math.sqrt(d)
print(2)
print((-b-dd)/(2*a))
print((-b+dd)/(2*a))
``` | 0 |
223 | A | Bracket Sequence | PROGRAMMING | 1,700 | [
"data structures",
"expression parsing",
"implementation"
] | null | null | A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()[]", "([... | The first and the only line contains the bracket sequence as a string, consisting only of characters "(", ")", "[" and "]". It is guaranteed that the string is non-empty and its length doesn't exceed 105 characters. | In the first line print a single integer — the number of brackets «[» in the required bracket sequence. In the second line print the optimal sequence. If there are more than one optimal solutions print any of them. | [
"([])\n",
"(((\n"
] | [
"1\n([])\n",
"0\n\n"
] | none | 500 | [
{
"input": "([])",
"output": "1\n([])"
},
{
"input": "(((",
"output": "0"
},
{
"input": "(][)",
"output": "0"
},
{
"input": "(()[))()[]",
"output": "1\n()[]"
},
{
"input": "(][](](][[(][",
"output": "1\n[]"
},
{
"input": "((])(]]))(](((()[[()[[[)([]()]... | 1,530,004,756 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 156 | 0 | x=input()
ans=[]
s=['a']
tmp=''
count1=0
count2=0
co=0
for i in x:
if i==')':
if s[-1]=='(':
del s[-1]
else:
if len(s)==2:
ans.append(tmp[:-1])
tmp=''
else:
s=['a']
tmp=''
elif i... | Title: Bracket Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "... | ```python
x=input()
ans=[]
s=['a']
tmp=''
count1=0
count2=0
co=0
for i in x:
if i==')':
if s[-1]=='(':
del s[-1]
else:
if len(s)==2:
ans.append(tmp[:-1])
tmp=''
else:
s=['a']
tmp=''
... | 0 | |
74 | A | Room Leader | PROGRAMMING | 1,000 | [
"implementation"
] | A. Room Leader | 2 | 256 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants are divided into rooms. Each room contains exactly *n* participants. During the contest the participants are suggested to solve five prob... | The first line contains an integer *n*, which is the number of contestants in the room (1<=≤<=*n*<=≤<=50). The next *n* lines contain the participants of a given room. The *i*-th line has the format of "*handle**i* *plus**i* *minus**i* *a**i* *b**i* *c**i* *d**i* *e**i*" — it is the handle of a contestant, the number o... | Print on the single line the handle of the room leader. | [
"5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0\n"
] | [
"tourist"
] | The number of points that each participant from the example earns, are as follows:
- Petr — 3860 - tourist — 4140 - Egor — 4030 - c00lH4x0R — - 350 - some_participant — 2220
Thus, the leader of the room is tourist. | 500 | [
{
"input": "5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0",
"output": "tourist"
},
{
"input": "1\nA 0 0 200 0 0 0 0",
"output": "A"
},
{
"input": "2\n12345678901234567890 1 0... | 1,667,960,663 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 124 | 0 | users = dict()
n = int(input())
for i in range(n):
l = input().split()
scores = list(map(int,l[1:]))
a = scores[0]*100-scores[1]*500 +sum(scores[2:])
users[a] = l[0]
b = max(users.keys())
print(users[b]) | Title: Room Leader
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants are divided into rooms. Each room contains e... | ```python
users = dict()
n = int(input())
for i in range(n):
l = input().split()
scores = list(map(int,l[1:]))
a = scores[0]*100-scores[1]*500 +sum(scores[2:])
users[a] = l[0]
b = max(users.keys())
print(users[b])
``` | 0 |
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is... | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so ... | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "... | 1,613,928,977 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | n = int(input())
a=[]
for i in range(n):
a.append(input())
b =set(a)
print(len(a)-len(b)+1) | Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l... | ```python
n = int(input())
a=[]
for i in range(n):
a.append(input())
b =set(a)
print(len(a)-len(b)+1)
``` | 0 | |
3 | A | Shortest path of the king | PROGRAMMING | 1,000 | [
"greedy",
"shortest paths"
] | A. Shortest path of the king | 1 | 64 | The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the le... | The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. | In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diago... | [
"a8\nh1\n"
] | [
"7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n"
] | none | 0 | [
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "b2\nb4",
"output": "2\nU\nU"
},
{
"input": "a5\na5",
"output": "0"
},
{
"input": "h1\nb2",
"output": "6\nLU\nL\nL\nL\nL\nL"
},
{
"input": "c5\nh2",
"output": "5\nRD\nRD\nRD\nR\nR"
... | 1,696,578,719 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 124 | 2,764,800 | n = int(input())
lst = list(map(int, input().split()))
lst_1 = []
lst_2 = []
lst_3 = []
def in_kq(lst):
result = ' '.join(map(str, lst))
print(len(lst), result)
for i in range(n):
if lst[i] < 0 and (not lst_1):
lst_1.append(lst[i])
elif lst[i] > 0 and (not lst_2):
lst_2.append(lst[i... | Title: Shortest path of the king
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king ... | ```python
n = int(input())
lst = list(map(int, input().split()))
lst_1 = []
lst_2 = []
lst_3 = []
def in_kq(lst):
result = ' '.join(map(str, lst))
print(len(lst), result)
for i in range(n):
if lst[i] < 0 and (not lst_1):
lst_1.append(lst[i])
elif lst[i] > 0 and (not lst_2):
lst_2.ap... | -1 |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,696,699,723 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 124 | 0 | n = int(input())
s = ""
st = {""}
for i in range(n+1,9000+1):
s = str(i)
st = {""}
st.add(s[0])
st.add(s[1])
st.add(s[2])
st.add(s[3])
if (len(st)==5):
print(i)
break | Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
n = int(input())
s = ""
st = {""}
for i in range(n+1,9000+1):
s = str(i)
st = {""}
st.add(s[0])
st.add(s[1])
st.add(s[2])
st.add(s[3])
if (len(st)==5):
print(i)
break
``` | 0 | |
121 | B | Lucky Transformation | PROGRAMMING | 1,500 | [
"strings"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has a number consisting of *n* digits without leading zeroes. He represented it as an array of... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=≤<=109) — the number of digits in the number and the number of completed operations. The second line contains *n* digits without spaces representing the array of digits *d*, starting with *d*1. It is guaranteed that the first digit of the ... | In the single line print the result without spaces — the number after the *k* operations are fulfilled. | [
"7 4\n4727447\n",
"4 2\n4478\n"
] | [
"4427477\n",
"4478\n"
] | In the first sample the number changes in the following sequence: 4727447 → 4427447 → 4427477 → 4427447 → 4427477.
In the second sample: 4478 → 4778 → 4478. | 1,000 | [
{
"input": "7 4\n4727447",
"output": "4427477"
},
{
"input": "4 2\n4478",
"output": "4478"
},
{
"input": "7 7\n4211147",
"output": "4211177"
},
{
"input": "7 6\n4747477",
"output": "4444477"
},
{
"input": "10 2\n9474444474",
"output": "9774444774"
},
{
... | 1,685,978,858 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | import sys
# Get Input
#sys.stdin = open("input.txt","r")
input = sys.stdin.readline
# Input Functions #
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def insr():
return(input().strip())
def invr():
return map(int, input().split())
def convert... | Title: Lucky Transformation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are ... | ```python
import sys
# Get Input
#sys.stdin = open("input.txt","r")
input = sys.stdin.readline
# Input Functions #
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def insr():
return(input().strip())
def invr():
return map(int, input().split())
d... | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.