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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,539,675,789 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | line=['a','b','c','d','e','f','g','h']
a=str(input())
b=str(input())
x=line.index(list(a)[0])-line.index(list(b)[0])
y=int(a[1])-int(b[1])
i=0
j=0
k=0
if abs(x)<abs(y):
k=1
print(max(abs(x),abs(y)))
while i<min(abs(x),abs(y)):
if x<0 and y<0:
print('LD')
if x>0 and y<0:
print(... | 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
line=['a','b','c','d','e','f','g','h']
a=str(input())
b=str(input())
x=line.index(list(a)[0])-line.index(list(b)[0])
y=int(a[1])-int(b[1])
i=0
j=0
k=0
if abs(x)<abs(y):
k=1
print(max(abs(x),abs(y)))
while i<min(abs(x),abs(y)):
if x<0 and y<0:
print('LD')
if x>0 and y<0:
... | 0 |
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th... | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"inp... | 1,692,090,369 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 31 | 0 | n,k=map(int,input().split())
a=map(int,input().split())
a=list(a)
f=[]
for i in range(n-k):
f.append(sum(a[i:i+k]))
print(f.index(min(f))+1) | Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ... | ```python
n,k=map(int,input().split())
a=map(int,input().split())
a=list(a)
f=[]
for i in range(n-k):
f.append(sum(a[i:i+k]))
print(f.index(min(f))+1)
``` | -1 | |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,613,338,232 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 204,800 | n = int(input())
a = list(map(int, input().split()))
# print(a)
prev = -1
rest = 0
for k in range(len(a)):
v = a[k]
if v == 3:
if prev == 1:
v = 2
elif prev == 2:
v = 1
else:
if k == len(a) - 1:
v = 1
else:
... | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int... | ```python
n = int(input())
a = list(map(int, input().split()))
# print(a)
prev = -1
rest = 0
for k in range(len(a)):
v = a[k]
if v == 3:
if prev == 1:
v = 2
elif prev == 2:
v = 1
else:
if k == len(a) - 1:
v = 1
else:
... | 0 | |
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, an... | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"inpu... | 1,678,124,925 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 62 | 0 | a, b = int(input()), int(input())
c = abs(a-b)
d = c // 2
print(d * (d+1) if c % 2 == 0 else (d+1) ** 2) | Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in... | ```python
a, b = int(input()), int(input())
c = abs(a-b)
d = c // 2
print(d * (d+1) if c % 2 == 0 else (d+1) ** 2)
``` | 3 | |
864 | B | Polycarp and Letters | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"strings"
] | null | null | Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters.
Let *A* be a set of positions in the string. Let's call it pretty if following conditions are met:
- letters on positions from *A* in the string are all distinct and lowerc... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200) — length of string *s*.
The second line contains a string *s* consisting of lowercase and uppercase Latin letters. | Print maximum number of elements in pretty set of positions for string *s*. | [
"11\naaaaBaabAbA\n",
"12\nzACaAbbaazzC\n",
"3\nABC\n"
] | [
"2\n",
"3\n",
"0\n"
] | In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There... | 1,000 | [
{
"input": "11\naaaaBaabAbA",
"output": "2"
},
{
"input": "12\nzACaAbbaazzC",
"output": "3"
},
{
"input": "3\nABC",
"output": "0"
},
{
"input": "1\na",
"output": "1"
},
{
"input": "2\naz",
"output": "2"
},
{
"input": "200\nXbTJZqcbpYuZQEoUrbxlPXAPCtVLr... | 1,545,497,192 | 1,352 | Python 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | n = int(input())
a = list(input())
ans = []
ans.append(a[0])
for i in range(1, n):
if a[i] != a[i - 1]:
ans.append(a[i])
an = 0
ch = 0
for i in range(len(ans)):
if ans[i] == ans[i].lower():
ch += 1
continue
an = max(an, ch)
ch = 0
print(an) | Title: Polycarp and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters.
Let *A* be a set of positions in the string. Let's call it pretty if... | ```python
n = int(input())
a = list(input())
ans = []
ans.append(a[0])
for i in range(1, n):
if a[i] != a[i - 1]:
ans.append(a[i])
an = 0
ch = 0
for i in range(len(ans)):
if ans[i] == ans[i].lower():
ch += 1
continue
an = max(an, ch)
ch = 0
print(an)
``` | 0 | |
1,004 | A | Sonya and Hotels | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin... | The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coord... | Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. | [
"4 3\n-3 2 9 16\n",
"5 2\n4 8 11 18 19\n"
] | [
"6\n",
"5\n"
] | In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | 500 | [
{
"input": "4 3\n-3 2 9 16",
"output": "6"
},
{
"input": "5 2\n4 8 11 18 19",
"output": "5"
},
{
"input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83",
"output": "8"
},
{
"input": "10 10\n0 20 48 58 81 95 111 137 147 159",
"output": "9"
},
{
"input": "100 1\n0 1 2 3... | 1,531,218,843 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | n = int(input ())
d = int(input ())
c = []
cities = 2
x=0
for i in range(n):
c.append(int(input()))
while x<int(len(c))-1:
if (int(c[x+1])-int(c[x]))>2*d:
cities+=2
x+=1
elif (int(c[x+1])-int(c[x]))==2*d:
cities+=1
x+=1
else:
x+=1
print (cities) | Title: Sonya and Hotels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer c... | ```python
n = int(input ())
d = int(input ())
c = []
cities = 2
x=0
for i in range(n):
c.append(int(input()))
while x<int(len(c))-1:
if (int(c[x+1])-int(c[x]))>2*d:
cities+=2
x+=1
elif (int(c[x+1])-int(c[x]))==2*d:
cities+=1
x+=1
else:
x+=1
print (cities)
``` | -1 | |
630 | I | Parking Lot | PROGRAMMING | 1,700 | [
"combinatorics",
"math"
] | null | null | To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.
The parking lot before the office consists of one line of (2*n*<=-<=2) parking spaces. Unfortunately the total number of ... | The only line of the input contains one integer *n* (3<=≤<=*n*<=≤<=30) — the amount of successive cars of the same make. | Output one integer — the number of ways to fill the parking lot by cars of four makes using the described way. | [
"3\n"
] | [
"24"
] | Let's denote car makes in the following way: A — Aston Martin, B — Bentley, M — Mercedes-Maybach, Z — Zaporozhets. For *n* = 3 there are the following appropriate ways to fill the parking lot: AAAB AAAM AAAZ ABBB AMMM AZZZ BBBA BBBM BBBZ BAAA BMMM BZZZ MMMA MMMB MMMZ MAAA MBBB MZZZ ZZZA ZZZB ZZZM ZAAA ZBBB ZMMM
Orig... | 0 | [
{
"input": "3",
"output": "24"
},
{
"input": "4",
"output": "132"
},
{
"input": "5",
"output": "672"
},
{
"input": "6",
"output": "3264"
},
{
"input": "7",
"output": "15360"
},
{
"input": "12",
"output": "27525120"
},
{
"input": "15",
"... | 1,687,680,151 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n = int(input())
def f(n):
return 4*(n-1)*3**(n-2)
print(f(n)) | Title: Parking Lot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.
The parking lot before t... | ```python
n = int(input())
def f(n):
return 4*(n-1)*3**(n-2)
print(f(n))
``` | 0 | |
14 | C | Four Segments | PROGRAMMING | 1,700 | [
"brute force",
"constructive algorithms",
"geometry",
"implementation",
"math"
] | C. Four Segments | 2 | 64 | Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the progr... | The input data contain four lines. Each of these lines contains four integers *x*1, *y*1, *x*2, *y*2 (<=-<=109<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. | Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». | [
"1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0\n",
"0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0",
"output": "YES"
},
{
"input": "0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2",
"output": "NO"
},
{
"input": "0 0 0 2\n2 0 0 0\n2 2 2 0\n0 2 2 2",
"output": "YES"
},
{
"input": "0 0 10 0\n0 0 10 0\n0 0 0 5\n0 0 0 -5",
"output": "NO"
... | 1,576,742,119 | 2,147,483,647 | Python 3 | OK | TESTS | 110 | 248 | 0 | s = {0:0,1:0}
for i in range(4):
a,b,c,d = input().split()
if a==c and b!=d:
s[0]+=1
if b==d and a!=c:
s[1]+=1
for q in [(a,b),(c,d)]:
s[q] = s.get(q,0) + 1
print("YES" if all(i==2 for i in s.values())else "NO") | Title: Four Segments
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creati... | ```python
s = {0:0,1:0}
for i in range(4):
a,b,c,d = input().split()
if a==c and b!=d:
s[0]+=1
if b==d and a!=c:
s[1]+=1
for q in [(a,b),(c,d)]:
s[q] = s.get(q,0) + 1
print("YES" if all(i==2 for i in s.values())else "NO")
``` | 3.938 |
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,648,832 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 343 | 7,987,200 | import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in s... | 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
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) ... | 3 | |
7 | B | Memory Manager | PROGRAMMING | 1,600 | [
"implementation"
] | B. Memory Manager | 1 | 64 | There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:
... | The first line of the input data contains two positive integers *t* and *m* (1<=≤<=*t*<=≤<=100;1<=≤<=*m*<=≤<=100), where *t* — the amount of operations given to the memory manager for processing, and *m* — the available memory size in bytes. Then there follow *t* lines where the operations themselves are given. The fir... | Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return inte... | [
"6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n"
] | [
"1\n2\nNULL\n3\n"
] | none | 0 | [
{
"input": "6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6",
"output": "1\n2\nNULL\n3"
},
{
"input": "6 1\ndefragment\nalloc 10\nalloc 1\nerase -1\nerase 1\nerase 1",
"output": "NULL\n1\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT"
},
{
"input": "14 100\nalloc 99\nalloc... | 1,632,012,555 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 122 | 20,172,800 | def alloc(controle, mem, maxi, tam):
tem_espaco = False
onde = -1
pos = -1
if not mem:
if tam < maxi:
mem.append([controle, 1, tam])
return [controle, mem]
else:
return ["NULL"]
elif len(mem) == 1:
value = mem[0]
if val... | Title: Memory Manager
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first relea... | ```python
def alloc(controle, mem, maxi, tam):
tem_espaco = False
onde = -1
pos = -1
if not mem:
if tam < maxi:
mem.append([controle, 1, tam])
return [controle, mem]
else:
return ["NULL"]
elif len(mem) == 1:
value = mem[0]
... | 0 |
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor... | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input"... | 1,492,803,837 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
import sys, io
import re, math
#start = time.clock()
n=int(raw_input())
ans=set()
for _ in range(n):
tree=raw_input()
ans.add(tree)
print len(ans)
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the specie... | ```python
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
import sys, io
import re, math
#start = time.clock()
n=int(raw_input())
ans=set()
for _ in range(n):
tree=raw_input()
ans.add(tree)
print len(ans)
``` | -1 |
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,693,160,027 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | n, k = map(int, input().split())
participations = list(map(int, input().split()))
eligible_count = sum(1 for p in participations if p <= 5 - k)
max_teams = eligible_count // 3
print(max_teams)
| 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())
participations = list(map(int, input().split()))
eligible_count = sum(1 for p in participations if p <= 5 - k)
max_teams = eligible_count // 3
print(max_teams)
``` | 3 | |
817 | C | Really Big Numbers | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"dp",
"math"
] | null | null | Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different... | The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018). | Print one integer — the quantity of really big numbers that are not greater than *n*. | [
"12 1\n",
"25 20\n",
"10 9\n"
] | [
"3\n",
"0\n",
"1\n"
] | In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).
In the third example 10 is the only really big number (10 - 1 ≥ 9). | 0 | [
{
"input": "12 1",
"output": "3"
},
{
"input": "25 20",
"output": "0"
},
{
"input": "10 9",
"output": "1"
},
{
"input": "300 1000",
"output": "0"
},
{
"input": "500 1000",
"output": "0"
},
{
"input": "1000 2000",
"output": "0"
},
{
"input":... | 1,498,327,055 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 5,529,600 | def main():
n, s = map(int,input().split())
y = [i for i in range(s, s+180) if i - sum([int(j) for j in str(i)])]
a = y[0]
print(max(n-a+1,0))
# print(max(n - [i for i in range(s, s + 180) if i - sum([int(j) for j in str(i)]) >= s][0] + 1, 0))
if __name__ == "__main__":
main()
| Title: Really Big Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its... | ```python
def main():
n, s = map(int,input().split())
y = [i for i in range(s, s+180) if i - sum([int(j) for j in str(i)])]
a = y[0]
print(max(n-a+1,0))
# print(max(n - [i for i in range(s, s + 180) if i - sum([int(j) for j in str(i)]) >= s][0] + 1, 0))
if __name__ == "__main__":
main()
``` | 0 | |
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,611,309,835 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 154 | 0 | import math as m
n,x,y = list(map(int, input().split()))
a = m.ceil((y/100)*n) - x
print(a) | 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
import math as m
n,x,y = list(map(int, input().split()))
a = m.ceil((y/100)*n) - x
print(a)
``` | 0 | |
349 | B | Color the Fence | PROGRAMMING | 1,700 | [
"data structures",
"dp",
"greedy",
"implementation"
] | null | null | Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.
Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d... | The first line contains a positive integer *v* (0<=≤<=*v*<=≤<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=≤<=*a**i*<=≤<=105). | Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1. | [
"5\n5 4 3 2 1 2 3 4 5\n",
"2\n9 11 1 12 5 8 9 10 6\n",
"0\n1 1 1 1 1 1 1 1 1\n"
] | [
"55555\n",
"33\n",
"-1\n"
] | none | 1,000 | [
{
"input": "5\n5 4 3 2 1 2 3 4 5",
"output": "55555"
},
{
"input": "2\n9 11 1 12 5 8 9 10 6",
"output": "33"
},
{
"input": "0\n1 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "50\n5 3 10 2 2 4 3 6 5",
"output": "5555555555555555555555555"
},
{
"input": "22\n405 3... | 1,611,468,159 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 2,355,200 | from copy import deepcopy
class Digit(object):
def __init__(self, _cost, _value):
self.cost = _cost
self.value = _value
def main():
v = int(input())
a = list(map(int, input().split()))
a = tuple(Digit(cost, digit+1) for digit, cost in enumerate(a))
low_digit = deepco... | Title: Color the Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. ... | ```python
from copy import deepcopy
class Digit(object):
def __init__(self, _cost, _value):
self.cost = _cost
self.value = _value
def main():
v = int(input())
a = list(map(int, input().split()))
a = tuple(Digit(cost, digit+1) for digit, cost in enumerate(a))
low_digi... | 3 | |
75 | B | Facetook Priority Wall | PROGRAMMING | 1,500 | [
"expression parsing",
"implementation",
"strings"
] | B. Facetook Priority Wall | 2 | 256 | Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described).
This priority factor will be affected by three types of actions:
- 1. "*X* posted on *Y*'s wall... | The first line contains your name. The second line contains an integer *n*, which is the number of actions (1<=≤<=*n*<=≤<=100). Then *n* lines follow, it is guaranteed that each one contains exactly 1 action in the format given above. There is exactly one space between each two words in a line, and there are no extra s... | Print *m* lines, where *m* is the number of distinct names in the input (excluding yourself). Each line should contain just 1 name. The names should be sorted according to the priority factor with you in the descending order (the highest priority factor should come first). If two or more names have the same priority fa... | [
"ahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post\n",
"aba\n1\nlikes likes posted's post\n"
] | [
"fatma\nmona\n",
"likes\nposted\n"
] | none | 1,000 | [
{
"input": "ahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post",
"output": "fatma\nmona"
},
{
"input": "aba\n1\nlikes likes posted's post",
"output": "likes\nposted"
},
{
"input": "nu\n5\ng commented on pwyndmh's post\nqv posted on g's wall\n... | 1,657,770,541 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 409,600 | import re
self = input()
d = {}
for _ in range(int(input())):
event = input()
x = None
y = None
if re.match(r".+ posted on .+\'s wall",event):
x = event[event.find("posted on ")+len("posted on "): event.find("'")]
y = event[:event.find(' ')]
try:
d[x] += 15... | Title: Facetook Priority Wall
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be describ... | ```python
import re
self = input()
d = {}
for _ in range(int(input())):
event = input()
x = None
y = None
if re.match(r".+ posted on .+\'s wall",event):
x = event[event.find("posted on ")+len("posted on "): event.find("'")]
y = event[:event.find(' ')]
try:
... | 0 |
250 | A | Paper Work | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know that the main information in a day report is value *a**i*, the company's profit on the *i*-th day. ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), *n* is the number of days. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=100), where *a**i* means the company profit on the *i*-th day. It is possible that the company has no days with the negative *a**i*. | Print an integer *k* — the required minimum number of folders. In the second line print a sequence of integers *b*1, *b*2, ..., *b**k*, where *b**j* is the number of day reports in the *j*-th folder.
If there are multiple ways to sort the reports into *k* days, print any of them. | [
"11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\n",
"5\n0 -1 100 -1 0\n"
] | [
"3\n5 3 3 ",
"1\n5 "
] | Here goes a way to sort the reports from the first sample into three folders:
In the second sample you can put all five reports in one folder. | 500 | [
{
"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6",
"output": "3\n5 3 3 "
},
{
"input": "5\n0 -1 100 -1 0",
"output": "1\n5 "
},
{
"input": "1\n0",
"output": "1\n1 "
},
{
"input": "1\n-1",
"output": "1\n1 "
},
{
"input": "2\n0 0",
"output": "1\n2 "
},
{
"inp... | 1,661,596,025 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 92 | 0 | n=int(input())
L=input().split()
countneg=0
num=0
T=''
sum = 1
for i in range(n) :
num=num+1
if int(L[i])<0 :
countneg=countneg+1
if countneg==3 :
sum=sum+1
countneg=1
T=T+str(num-1)+' '
num=1
T=T+str(num)
print(sum)
print(T) | Title: Paper Work
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know tha... | ```python
n=int(input())
L=input().split()
countneg=0
num=0
T=''
sum = 1
for i in range(n) :
num=num+1
if int(L[i])<0 :
countneg=countneg+1
if countneg==3 :
sum=sum+1
countneg=1
T=T+str(num-1)+' '
num=1
T=T+str(num)
print(sum)
print(T)
``` | 3 | |
796 | B | Find The Bone | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Zane the wizard is going to perform a magic show shuffling the cups.
There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at the position *x*<==<=*i*.
The problematic bone is initially at the position *x*<==<=1. Zane will co... | The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=106, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively.
The second line contains *m* distinct integers *h*1,<=*h*2,<=...,<=*h**m* (1<=≤<=*h**i*<=≤<=*... | Print one integer — the final position along the *x*-axis of the bone. | [
"7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1\n",
"5 1 2\n2\n1 2\n2 4\n"
] | [
"1",
"2"
] | In the first sample, after the operations, the bone becomes at *x* = 2, *x* = 5, *x* = 7, and *x* = 1, respectively.
In the second sample, after the first operation, the bone becomes at *x* = 2, and falls into the hole onto the ground. | 750 | [
{
"input": "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1",
"output": "1"
},
{
"input": "5 1 2\n2\n1 2\n2 4",
"output": "2"
},
{
"input": "10000 1 9\n55\n44 1\n2929 9292\n9999 9998\n44 55\n49 94\n55 53\n100 199\n55 50\n53 11",
"output": "55"
},
{
"input": "100000 3 7\n2 3 4\n1 5\n5 1\n1 5... | 1,553,279,041 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 0 | n, m, k = input().split(' ')
# n = int(n)
# m = int(m)
k = int(k)
holes = {}
lista = input().split(' ')
for i in lista:
holes[i] = 1
where = '1'
resp = '1'
found = False
for i in range(k):
pos = input().split(' ')
if found == False:
if where == pos[0]:
where = pos[1]
elif where == pos[1]:
... | Title: Find The Bone
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard is going to perform a magic show shuffling the cups.
There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at t... | ```python
n, m, k = input().split(' ')
# n = int(n)
# m = int(m)
k = int(k)
holes = {}
lista = input().split(' ')
for i in lista:
holes[i] = 1
where = '1'
resp = '1'
found = False
for i in range(k):
pos = input().split(' ')
if found == False:
if where == pos[0]:
where = pos[1]
elif where == po... | 0 | |
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,683,508,513 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | # Hydro submission #64584d1e8b6b0f8909f4a6cc@1683508511629
l = input().split()
a,b,c,d = int(l[0]),int(l[1]),int(l[2]),int(l[3])
l2 = [(a,b,c),(a,b,d),(a,c,d),(b,c,d)]
for l1 in l2:
if (l1[0]+l1[1] > l1[2]) or (l1[1]+l1[2] > l1[0]) or (l1[0]+l1[1] > l1[2]):
print('TRIANGLE')
return
for l1 in l2:
... | 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
# Hydro submission #64584d1e8b6b0f8909f4a6cc@1683508511629
l = input().split()
a,b,c,d = int(l[0]),int(l[1]),int(l[2]),int(l[3])
l2 = [(a,b,c),(a,b,d),(a,c,d),(b,c,d)]
for l1 in l2:
if (l1[0]+l1[1] > l1[2]) or (l1[1]+l1[2] > l1[0]) or (l1[0]+l1[1] > l1[2]):
print('TRIANGLE')
return
for l1 ... | -1 |
811 | A | Vladik and Courtesy | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving eac... | Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. | Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. | [
"1 1\n",
"7 6\n"
] | [
"Valera\n",
"Vladik\n"
] | Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e... | 500 | [
{
"input": "1 1",
"output": "Valera"
},
{
"input": "7 6",
"output": "Vladik"
},
{
"input": "25 38",
"output": "Vladik"
},
{
"input": "8311 2468",
"output": "Valera"
},
{
"input": "250708 857756",
"output": "Vladik"
},
{
"input": "957985574 24997558",
... | 1,556,817,472 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 109 | 0 | def main():
from math import floor, sqrt
[vladik, valera] = [int(_) for _ in input().split()]
times_vladik = floor(sqrt(vladik))
times_valera = next(i for i in range(floor(sqrt(valera)) + 2) if i * (i + 1) > valera)
times_valera -= 1
print('Valera' if times_vladik > times_valera else 'Vladik')... | Title: Vladik and Courtesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vla... | ```python
def main():
from math import floor, sqrt
[vladik, valera] = [int(_) for _ in input().split()]
times_vladik = floor(sqrt(vladik))
times_valera = next(i for i in range(floor(sqrt(valera)) + 2) if i * (i + 1) > valera)
times_valera -= 1
print('Valera' if times_vladik > times_valera else... | 3 | |
1,004 | D | Sonya and Matrix | PROGRAMMING | 2,300 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Since Sonya has just learned the basics of matrices, she decided to play with them a little bit.
Sonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one zero, while all other cells have the Manhattan distance to the cell containing the zero. The cells with equal numbers ... | The first line contains a single integer $t$ ($1\leq t\leq 10^6$) — the number of cells in the matrix.
The second line contains $t$ integers $a_1, a_2, \ldots, a_t$ ($0\leq a_i< t$) — the values in the cells in arbitrary order. | In the first line, print two positive integers $n$ and $m$ ($n \times m = t$) — the size of the matrix.
In the second line, print two integers $x$ and $y$ ($1\leq x\leq n$, $1\leq y\leq m$) — the row number and the column number where the cell with $0$ is located.
If there are multiple possible answers, print any of ... | [
"20\n1 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4\n",
"18\n2 2 3 2 4 3 3 3 0 2 4 2 1 3 2 1 1 1\n",
"6\n2 1 0 2 1 2\n"
] | [
"4 5\n2 2\n",
"3 6\n2 3\n",
"-1\n"
] | You can see the solution to the first example in the legend. You also can choose the cell $(2, 2)$ for the cell where $0$ is located. You also can choose a $5\times 4$ matrix with zero at $(4, 2)$.
In the second example, there is a $3\times 6$ matrix, where the zero is located at $(2, 3)$ there.
In the third example,... | 2,000 | [
{
"input": "20\n1 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4",
"output": "4 5\n2 2"
},
{
"input": "18\n2 2 3 2 4 3 3 3 0 2 4 2 1 3 2 1 1 1",
"output": "3 6\n2 3"
},
{
"input": "6\n2 1 0 2 1 2",
"output": "-1"
},
{
"input": "1\n0",
"output": "1 1\n1 1"
},
{
"input": "7\... | 1,530,901,427 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 155 | 8,396,800 | n=int(input())
a=map(int, input().split())
"""
n=10000
a=[i for i in range(10000)]
"""
if n==1:
if a[0]==0:
print(1,1)
print(1,1)
exit()
else:
print(-1)
exit()
ct=[0 for i in range(1000000)]
for x in a:
ct[x]+=1
i=0
while ct[i]>0:
i+=1
ct=ct[... | Title: Sonya and Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Sonya has just learned the basics of matrices, she decided to play with them a little bit.
Sonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one zero, while all ... | ```python
n=int(input())
a=map(int, input().split())
"""
n=10000
a=[i for i in range(10000)]
"""
if n==1:
if a[0]==0:
print(1,1)
print(1,1)
exit()
else:
print(-1)
exit()
ct=[0 for i in range(1000000)]
for x in a:
ct[x]+=1
i=0
while ct[i]>0:
i+... | -1 | |
609 | C | Load Balancing | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server.
In order to balance the load for each server, you want to reassign some tasks to make the differe... | The first line contains positive number *n* (1<=≤<=*n*<=≤<=105) — the number of the servers.
The second line contains the sequence of non-negative integers *m*1,<=*m*2,<=...,<=*m**n* (0<=≤<=*m**i*<=≤<=2·104), where *m**i* is the number of tasks assigned to the *i*-th server. | Print the minimum number of seconds required to balance the load. | [
"2\n1 6\n",
"7\n10 11 10 11 10 11 11\n",
"5\n1 2 3 4 5\n"
] | [
"2\n",
"0\n",
"3\n"
] | In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2.
In the second example the load is already balanced.
A possible sequence of task movements for the third example is:
... | 0 | [
{
"input": "2\n1 6",
"output": "2"
},
{
"input": "7\n10 11 10 11 10 11 11",
"output": "0"
},
{
"input": "5\n1 2 3 4 5",
"output": "3"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n20000",
... | 1,576,265,814 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 108 | 0 | def min_secs(A):
avg = int( sum(A) / len(A) )
secs = 0
for a in A:
v = avg - a
if v > 0:
secs += v
return secs
if __name__ == "__main__":
n = int(input())
C = input().split(" ")
C = [int(c) for c in C]
print(min_secs(C))
| Title: Load Balancing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server... | ```python
def min_secs(A):
avg = int( sum(A) / len(A) )
secs = 0
for a in A:
v = avg - a
if v > 0:
secs += v
return secs
if __name__ == "__main__":
n = int(input())
C = input().split(" ")
C = [int(c) for c in C]
print(min_secs(C))
``` | 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,619,516,831 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 62 | 102,400 | n=int(input())
li=list(map(int,input().split()))
for i in range(n):
li[i]=(li[i],i)
ans=[0]*(n)
li.sort(reverse=True)
y=1
for i in range(n-1):
ans[li[i][1]]=y
if(li[i][0]!=li[i+1][0]):
y=2+i
ans[li[n-1][1]]=y
print(*ans)
| 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())
li=list(map(int,input().split()))
for i in range(n):
li[i]=(li[i],i)
ans=[0]*(n)
li.sort(reverse=True)
y=1
for i in range(n-1):
ans[li[i][1]]=y
if(li[i][0]!=li[i+1][0]):
y=2+i
ans[li[n-1][1]]=y
print(*ans)
``` | 3 | |
798 | A | Mike and palindrome | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"strings"
] | null | null | Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codefo... | The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15). | Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. | [
"abccaa\n",
"abbcca\n",
"abcda\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "abccaa",
"output": "YES"
},
{
"input": "abbcca",
"output": "NO"
},
{
"input": "abcda",
"output": "YES"
},
{
"input": "kyw",
"output": "YES"
},
{
"input": "fccf",
"output": "NO"
},
{
"input": "mnlm",
"output": "YES"
},
{
"input":... | 1,694,582,075 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | s = input()
if s == s[::-1]:
print("YES")
else:
# Count the number of characters that need to be changed
diff_count = sum([s[i] != s[-i - 1] for i in range(len(s) // 2)])
# If there's only one character that needs to be changed or the string has an odd length and the middle character is differen... | Title: Mike and palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same ... | ```python
s = input()
if s == s[::-1]:
print("YES")
else:
# Count the number of characters that need to be changed
diff_count = sum([s[i] != s[-i - 1] for i in range(len(s) // 2)])
# If there's only one character that needs to be changed or the string has an odd length and the middle character i... | 0 | |
578 | B | "Or" Game | PROGRAMMING | 1,700 | [
"brute force",
"greedy"
] | null | null | You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR.
Find the maximum possible value of after performing at most *k* operations optimally. | The first line contains three integers *n*, *k* and *x* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=10, 2<=≤<=*x*<=≤<=8).
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | Output the maximum value of a bitwise OR of sequence elements after performing operations. | [
"3 1 2\n1 1 1\n",
"4 2 3\n1 2 4 8\n"
] | [
"3\n",
"79\n"
] | For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1ee73b671ed4bc53f2f96ed1a85fd98388e1712b.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
For the second sample... | 500 | [
{
"input": "3 1 2\n1 1 1",
"output": "3"
},
{
"input": "4 2 3\n1 2 4 8",
"output": "79"
},
{
"input": "2 1 2\n12 9",
"output": "30"
},
{
"input": "2 1 2\n12 7",
"output": "31"
},
{
"input": "3 1 3\n3 2 0",
"output": "11"
},
{
"input": "5 10 8\n10000000... | 1,526,716,318 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 |
n,k,x = map( int,input().split() )
*Arr, = map( int,input().split() )
Prfx = [0]*(n+2)
Sffx = [0]*(n+2)
for i in range(1,n):
Prfx[i] = Prfx[i-1]|Arr[i-1]
Sffx[n-i+1] = Sffx[n-i+2]|Arr[n-i]
now = x**k
Res = 0
for i in range(1,n):
Res = max( Prfx[i]|(Arr[i]*now)|Sffx[i+1],Res );
print(Res) | Title: "Or" Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR... | ```python
n,k,x = map( int,input().split() )
*Arr, = map( int,input().split() )
Prfx = [0]*(n+2)
Sffx = [0]*(n+2)
for i in range(1,n):
Prfx[i] = Prfx[i-1]|Arr[i-1]
Sffx[n-i+1] = Sffx[n-i+2]|Arr[n-i]
now = x**k
Res = 0
for i in range(1,n):
Res = max( Prfx[i]|(Arr[i]*now)|Sffx[i+1],Res );
pri... | 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,692,360,558 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 92 | 0 | n = int(input())
left_doors_opened = right_doors_opened = 0
for _ in range(n):
l, r = input().split()
if l == '1':
left_doors_opened += 1
if r == '1':
right_doors_opened += 1
print(min(left_doors_opened, n - left_doors_opened) + min(right_doors_opened, n - right_doors_opened))
| 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())
left_doors_opened = right_doors_opened = 0
for _ in range(n):
l, r = input().split()
if l == '1':
left_doors_opened += 1
if r == '1':
right_doors_opened += 1
print(min(left_doors_opened, n - left_doors_opened) + min(right_doors_opened, n - right_doors_o... | 3 | |
5 | C | Longest Regular Bracket Sequence | PROGRAMMING | 1,900 | [
"constructive algorithms",
"data structures",
"dp",
"greedy",
"sortings",
"strings"
] | C. Longest Regular Bracket Sequence | 2 | 256 | This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.... | The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106. | Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1". | [
")((())))(()())\n",
"))(\n"
] | [
"6 2\n",
"0 1\n"
] | none | 0 | [
{
"input": ")((())))(()())",
"output": "6 2"
},
{
"input": "))(",
"output": "0 1"
},
{
"input": "()(())()",
"output": "8 1"
},
{
"input": "((((()(((",
"output": "2 1"
},
{
"input": "))))()())))",
"output": "4 1"
},
{
"input": "(()())()(())()()())())()(... | 1,612,606,456 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 1,808 | 14,131,200 | import sys
input=lambda:sys.stdin.readline().strip()
s=input()
stack=[]
m = 0
ans = 1
xx = -1
for i in range(len(s)):
if s[i] == '(':stack.append(i)
else:
if len(stack) > 0:
stack.pop()
optimal = i - stack[-1] if len(stack) > 0 else i - xx
if optimal >= m:
if optimal > m: m, ans = optim... | Title: Longest Regular Bracket Sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical exp... | ```python
import sys
input=lambda:sys.stdin.readline().strip()
s=input()
stack=[]
m = 0
ans = 1
xx = -1
for i in range(len(s)):
if s[i] == '(':stack.append(i)
else:
if len(stack) > 0:
stack.pop()
optimal = i - stack[-1] if len(stack) > 0 else i - xx
if optimal >= m:
if optimal > m: m, a... | 3.521679 |
928 | A | Login Verification | PROGRAMMING | 1,200 | [
"*special",
"strings"
] | null | null | When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds ... | The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins.
The next *n* lines describe the exi... | Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes). | [
"1_wat\n2\n2_wat\nwat_1\n",
"000\n3\n00\nooA\noOo\n",
"_i_\n3\n__i_\n_1_\nI\n",
"La0\n3\n2a0\nLa1\n1a0\n",
"abc\n1\naBc\n",
"0Lil\n2\nLIL0\n0Ril\n"
] | [
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"Yes\n"
] | In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one. | 500 | [
{
"input": "1_wat\n2\n2_wat\nwat_1",
"output": "Yes"
},
{
"input": "000\n3\n00\nooA\noOo",
"output": "No"
},
{
"input": "_i_\n3\n__i_\n_1_\nI",
"output": "No"
},
{
"input": "La0\n3\n2a0\nLa1\n1a0",
"output": "No"
},
{
"input": "abc\n1\naBc",
"output": "No"
}... | 1,519,556,585 | 70,085 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 46 | 5,632,000 | a=[]
shet=0
i=0
log = str(input("Ваш логин:"))
kol = int(input("Кол-во зареганных:"))
len_log = len(log)
log=log.lower()
log = log.replace('0','o')
log = log.replace('1','i')
log = log.replace('l','i')
while i < kol:
a=str(input())
a=a.lower()
a = a.replace('0','o')
a = a.replace('l','i')
... | Title: Login Verification
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercas... | ```python
a=[]
shet=0
i=0
log = str(input("Ваш логин:"))
kol = int(input("Кол-во зареганных:"))
len_log = len(log)
log=log.lower()
log = log.replace('0','o')
log = log.replace('1','i')
log = log.replace('l','i')
while i < kol:
a=str(input())
a=a.lower()
a = a.replace('0','o')
a = a.replace... | 0 | |
988 | A | Diverse Team | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES"... | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student. | If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If t... | [
"5 3\n15 13 15 15 12\n",
"5 4\n15 13 15 15 12\n",
"4 4\n20 10 40 30\n"
] | [
"YES\n1 2 5 \n",
"NO\n",
"YES\n1 2 3 4 \n"
] | All possible answers for the first example:
- {1 2 5} - {2 3 5} - {2 4 5}
Note that the order does not matter. | 0 | [
{
"input": "5 3\n15 13 15 15 12",
"output": "YES\n1 2 5 "
},
{
"input": "5 4\n15 13 15 15 12",
"output": "NO"
},
{
"input": "4 4\n20 10 40 30",
"output": "YES\n1 2 3 4 "
},
{
"input": "1 1\n1",
"output": "YES\n1 "
},
{
"input": "100 53\n16 17 1 2 27 5 9 9 53 24 17... | 1,627,981,340 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 6,963,200 | def main():
n,k = map(int,input().split())
arr = list(map(int,input().split()))
have = []
ind = []
for i in range(len(arr)):
if arr[i] in have:
continue
else:
have.append(arr[i])
ind.append(i)
if(len(ind)<k):
pri... | Title: Diverse Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct... | ```python
def main():
n,k = map(int,input().split())
arr = list(map(int,input().split()))
have = []
ind = []
for i in range(len(arr)):
if arr[i] in have:
continue
else:
have.append(arr[i])
ind.append(i)
if(len(ind)<k):
... | 0 | |
248 | B | Chilly Willy | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them.
Chilly Willy wants to find the minimum number of length *n*, such that it is simultaneous... | A single input line contains a single integer *n* (1<=≤<=*n*<=≤<=105). | Print a single integer — the answer to the problem without leading zeroes, or "-1" (without the quotes), if the number that meet the problem condition does not exist. | [
"1\n",
"5\n"
] | [
"-1\n",
"10080"
] | none | 1,000 | [
{
"input": "1",
"output": "-1"
},
{
"input": "5",
"output": "10080"
},
{
"input": "6",
"output": "100170"
},
{
"input": "4",
"output": "1050"
},
{
"input": "15",
"output": "100000000000110"
},
{
"input": "16",
"output": "1000000000000050"
},
{
... | 1,610,966,157 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 19 | 2,000 | 8,499,200 | n = int(input())
if n in [1,2]:
print(-1)
else:
for i in range(210):
if (i+(10**(n-1))) % 210 == 0:
print(i+(10**(n-1)))
break | Title: Chilly Willy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected wit... | ```python
n = int(input())
if n in [1,2]:
print(-1)
else:
for i in range(210):
if (i+(10**(n-1))) % 210 == 0:
print(i+(10**(n-1)))
break
``` | 0 | |
886 | B | Vlad and Cafes | PROGRAMMING | 1,000 | [] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes... | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ... | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in... | 1,000 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000... | 1,613,798,687 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | in1 = int(input())
in2 = list(dict.fromkeys(re.split("\\s", input())))
print(in2[0])
| Title: Vlad and Cafes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research... | ```python
in1 = int(input())
in2 = list(dict.fromkeys(re.split("\\s", input())))
print(in2[0])
``` | -1 | |
397 | A | On Segment's Own Points | PROGRAMMING | 0 | [
"implementation"
] | null | null | Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm.
The dorm has exactly one straight dryer — a 100 ce... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). The (*i*<=+<=1)-th line contains integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=100) — the endpoints of the corresponding segment for the *i*-th student. | On a single line print a single number *k*, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments. | [
"3\n0 5\n2 8\n1 6\n",
"3\n0 10\n1 5\n7 15\n"
] | [
"1\n",
"3\n"
] | Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments.
In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and... | 500 | [
{
"input": "3\n0 5\n2 8\n1 6",
"output": "1"
},
{
"input": "3\n0 10\n1 5\n7 15",
"output": "3"
},
{
"input": "1\n0 100",
"output": "100"
},
{
"input": "2\n1 9\n1 9",
"output": "0"
},
{
"input": "2\n1 9\n5 10",
"output": "4"
},
{
"input": "2\n1 9\n3 5",... | 1,567,945,921 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 109 | 0 | n = int(input())
seta = set()
ax,ay = map(int, input().split(" "))
for i in range(ax,ay):
seta.add(i+0.5)
for i in range(0,n-1):
nx,ny = map(int, input().split(" "))
for j in range(nx,ny):
seta.discard(j+0.5)
print(len(seta)) | Title: On Segment's Own Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some... | ```python
n = int(input())
seta = set()
ax,ay = map(int, input().split(" "))
for i in range(ax,ay):
seta.add(i+0.5)
for i in range(0,n-1):
nx,ny = map(int, input().split(" "))
for j in range(nx,ny):
seta.discard(j+0.5)
print(len(seta))
``` | 3 | |
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,675,234,970 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | a,b=map(int,input().split())
l=list(map(int,input().split()))
c=0
for i in l:
if((5-i)>=b):
c+=1
if(c>=2):
print(c//3)
else:
print(0) | 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
a,b=map(int,input().split())
l=list(map(int,input().split()))
c=0
for i in l:
if((5-i)>=b):
c+=1
if(c>=2):
print(c//3)
else:
print(0)
``` | 3 | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,690,829,521 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 0 | 78 | 268,390,400 | import sys, threading
input = lambda: sys.stdin.readline().strip()
def main():
def dp(i):
if i==0:
return 0
if i==1:
return hm[1]
if i in memo:
return memo[i]
memo[i]=max(dp(i-1),dp(i-2)+hm[i])
return memo[i]
memo={}
... | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
import sys, threading
input = lambda: sys.stdin.readline().strip()
def main():
def dp(i):
if i==0:
return 0
if i==1:
return hm[1]
if i in memo:
return memo[i]
memo[i]=max(dp(i-1),dp(i-2)+hm[i])
return memo[i]
m... | 0 | |
979 | A | Pizza, Pizza, Pizza!!! | PROGRAMMING | 1,000 | [
"math"
] | null | null | Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to cele... | A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces. | A single integer — the number of straight cuts Shiro needs. | [
"3\n",
"4\n"
] | [
"2",
"5"
] | To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts. | 500 | [
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "5"
},
{
"input": "10",
"output": "11"
},
{
"input": "10000000000",
"output": "10000000001"
},
{
"input": "1234567891",
"output": "617283946"
},
{
"input": "7509213957",
"output": "37546069... | 1,558,260,692 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | //Author: Kudo_kun
//979A
#include<bits/stdc++.h>
using namespace std;
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ll long long int
#define ld long double
ll n;
int main()
{
FastIO;
cin >> n;
if(n == 0)
return (cout << "0\n"), 0;
cout << (((n+1) & 1) ? (n+1) : ((n+... | Title: Pizza, Pizza, Pizza!!!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthd... | ```python
//Author: Kudo_kun
//979A
#include<bits/stdc++.h>
using namespace std;
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ll long long int
#define ld long double
ll n;
int main()
{
FastIO;
cin >> n;
if(n == 0)
return (cout << "0\n"), 0;
cout << (((n+1) & 1) ? (n... | -1 | |
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 ... | 1,505,502,975 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | def main():
a1, a2, b1, b2, x = [int(i) for i in input().split()]
for a in range(a1, a2+1):
if(b1/a < x and b2/a > x):
print("YES")
return
print("NO")
main()
# 1505502972699
| Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the... | ```python
def main():
a1, a2, b1, b2, x = [int(i) for i in input().split()]
for a in range(a1, a2+1):
if(b1/a < x and b2/a > x):
print("YES")
return
print("NO")
main()
# 1505502972699
``` | 0 | |
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,612,722,017 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | m, n = input().split()
m = int(m)
n = int(n)
result = int((m*n)/2)
print(result) | 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 = input().split()
m = int(m)
n = int(n)
result = int((m*n)/2)
print(result)
``` | 3.969 |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,588,694,206 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 218 | 0 | n , m = map(int,input().split())
l = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
indexn = l.index(n)
if m in l:
indexm = l.index(m)
if indexn+1==indexm:
print("YES")
else:print("NO")
else:print("NO") | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
n , m = map(int,input().split())
l = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
indexn = l.index(n)
if m in l:
indexm = l.index(m)
if indexn+1==indexm:
print("YES")
else:print("NO")
else:print("NO")
``` | 3.9455 |
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,628,957,292 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 5 | 78 | 7,065,600 | from random import randint
ip = list(map(int, input().strip().split()))[:]
dis = ip[1]
sz = ip[0]
chars = []
for i in range(dis):
char = randint(97, 122)
if chr(char) in chars:
i -= 1
else:
chars.append(chr(char))
op = ""
for i in range(dis):
op += chars[i]
while dis < sz... | 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
from random import randint
ip = list(map(int, input().strip().split()))[:]
dis = ip[1]
sz = ip[0]
chars = []
for i in range(dis):
char = randint(97, 122)
if chr(char) in chars:
i -= 1
else:
chars.append(chr(char))
op = ""
for i in range(dis):
op += chars[i]
whil... | -1 | |
411 | A | Password Check | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che... | The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_". | If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes). | [
"abacaba\n",
"X12345\n",
"CONTEST_is_STARTED!!11\n"
] | [
"Too weak\n",
"Too weak\n",
"Correct\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "Too weak"
},
{
"input": "X12345",
"output": "Too weak"
},
{
"input": "CONTEST_is_STARTED!!11",
"output": "Correct"
},
{
"input": "1zA__",
"output": "Correct"
},
{
"input": "1zA_",
"output": "Too weak"
},
{
"input": "zA_... | 1,687,163,725 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 46 | 0 | w = 0
x = 0
z = 0
a = input()
if len(a) >= 5:
for i in a:
if i.islower():
w = 1
if i.isupper():
x = 1
if i.isnumeric():
z = 1
if w == 1 and x == 1 and z == 1:
print('Correct')
else:
print('Too weak')
| Title: Password Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password... | ```python
w = 0
x = 0
z = 0
a = input()
if len(a) >= 5:
for i in a:
if i.islower():
w = 1
if i.isupper():
x = 1
if i.isnumeric():
z = 1
if w == 1 and x == 1 and z == 1:
print('Correct')
else:
print('Too weak')
``` | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,632,857,962 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 154 | 6,758,400 | n=int(input())
su=sum([int(i) for i in input().split()])
final=0
for j in range(1,6):
if (su+j)%(n+1)==0:
final+=1
print(final) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n=int(input())
su=sum([int(i) for i in input().split()])
final=0
for j in range(1,6):
if (su+j)%(n+1)==0:
final+=1
print(final)
``` | 0 | |
799 | A | Carrot Cakes | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady... | The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. | If it is reasonable to build the second oven, print "YES". Otherwise print "NO". | [
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] | In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whe... | 500 | [
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"... | 1,594,976,447 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 171 | 7,475,200 | import re
nn = input()
e = re.findall("\d",nn)
n = int(e[0])
t = int(e[1])
k = int(e[2])
d = int(e[3])
time_of_one_oven = 0
time_of_two_oven = d
if k >= n:
print("NO")
else:
for i in range(0, n, k):
time_of_one_oven += t
for i in range(d, n, k):
time_of_two_oven += t
... | 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 re
nn = input()
e = re.findall("\d",nn)
n = int(e[0])
t = int(e[1])
k = int(e[2])
d = int(e[3])
time_of_one_oven = 0
time_of_two_oven = d
if k >= n:
print("NO")
else:
for i in range(0, n, k):
time_of_one_oven += t
for i in range(d, n, k):
time_of_two_oven +=... | 0 | |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,694,851,450 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | str_0 = input().lower()
vow = 'aoyeui'
str_1 = ''
for w in str_0:
if w not in vow:
str_1 += '.'+w
print(str_1) | Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
str_0 = input().lower()
vow = 'aoyeui'
str_1 = ''
for w in str_0:
if w not in vow:
str_1 += '.'+w
print(str_1)
``` | 3 | |
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**... | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},... | 1,591,744,630 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 139 | 0 | n, m = map(int, input().split())
c = []
for i in range(n):
lst = [int(i) for i in input().split()]
for i in range(1, len(lst)):
if lst[i] not in c: c.append(lst[i])
t = []
f = True
for i in range(1, n+2):
if i not in c:
f = False
if f: print("YES")
else: print("NO") | Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is... | ```python
n, m = map(int, input().split())
c = []
for i in range(n):
lst = [int(i) for i in input().split()]
for i in range(1, len(lst)):
if lst[i] not in c: c.append(lst[i])
t = []
f = True
for i in range(1, n+2):
if i not in c:
f = False
if f: print("YES")
else: print("NO... | 0 | |
893 | A | Chess For Three | PROGRAMMING | 900 | [
"implementation"
] | null | null | Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three.
So they play with each other according to following rules:
- ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of games Alex, Bob and Carl played.
Then *n* lines follow, describing the game log. *i*-th line contains one integer *a**i* (1<=≤<=*a**i*<=≤<=3) which is equal to 1 if Alex won *i*-th game, to 2 if Bob won *i*-th game and 3 if Carl won *i*-th gam... | Print YES if the situation described in the log was possible. Otherwise print NO. | [
"3\n1\n1\n2\n",
"2\n1\n2\n"
] | [
"YES\n",
"NO\n"
] | In the first example the possible situation is:
1. Alex wins, Carl starts playing instead of Bob; 1. Alex wins, Bob replaces Carl; 1. Bob wins.
The situation in the second example is impossible because Bob loses the first game, so he cannot win the second one. | 0 | [
{
"input": "3\n1\n1\n2",
"output": "YES"
},
{
"input": "2\n1\n2",
"output": "NO"
},
{
"input": "100\n2\n3\n1\n2\n3\n3\n3\n1\n1\n1\n1\n3\n3\n3\n3\n1\n2\n3\n3\n3\n3\n3\n3\n3\n1\n2\n2\n2\n3\n1\n1\n3\n3\n3\n3\n3\n3\n3\n3\n1\n2\n3\n3\n3\n1\n1\n1\n1\n3\n3\n3\n3\n1\n2\n3\n1\n2\n2\n2\n3\n3\n2\n1... | 1,622,282,074 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 93 | 0 | from sys import stdin
input = stdin.readline
n = int(input())
a = [int(input()) for _ in range(n)]
f = 3
for x in a:
if x == f:
print("NO")
break
for i in range(1, 4):
if i != x and i != f:
f = i
break
else:
print("YES")
| Title: Chess For Three
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess ... | ```python
from sys import stdin
input = stdin.readline
n = int(input())
a = [int(input()) for _ in range(n)]
f = 3
for x in a:
if x == f:
print("NO")
break
for i in range(1, 4):
if i != x and i != f:
f = i
break
else:
print("YES")
``` | 3 | |
349 | B | Color the Fence | PROGRAMMING | 1,700 | [
"data structures",
"dp",
"greedy",
"implementation"
] | null | null | Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.
Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d... | The first line contains a positive integer *v* (0<=≤<=*v*<=≤<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=≤<=*a**i*<=≤<=105). | Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1. | [
"5\n5 4 3 2 1 2 3 4 5\n",
"2\n9 11 1 12 5 8 9 10 6\n",
"0\n1 1 1 1 1 1 1 1 1\n"
] | [
"55555\n",
"33\n",
"-1\n"
] | none | 1,000 | [
{
"input": "5\n5 4 3 2 1 2 3 4 5",
"output": "55555"
},
{
"input": "2\n9 11 1 12 5 8 9 10 6",
"output": "33"
},
{
"input": "0\n1 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "50\n5 3 10 2 2 4 3 6 5",
"output": "5555555555555555555555555"
},
{
"input": "22\n405 3... | 1,693,980,136 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 92 | 0 | ink = int(input())
nums = list(map(int, input().split()))
if ink < min(nums): print(-1)
else:
leastink = 1e5 + 5
cheapestnum = 0
for i in range(len(nums)):
if nums[i] <= leastink:
cheapestnum = i + 1
leastink = nums[i]
numberlength = ink // leastink
if ink... | Title: Color the Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. ... | ```python
ink = int(input())
nums = list(map(int, input().split()))
if ink < min(nums): print(-1)
else:
leastink = 1e5 + 5
cheapestnum = 0
for i in range(len(nums)):
if nums[i] <= leastink:
cheapestnum = i + 1
leastink = nums[i]
numberlength = ink // leastink
... | 0 | |
11 | A | Increasing Sequence | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least... | The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | 0 | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
... | 1,564,085,028 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 0 | n,d=map(int,input().split())
b=list(map(int,input().split()))
count=0
for i in range(n):
if b[i]<b[i-1]:
x=b[i-1]-b[i]
y=x//(d+1)
if x%d==0:
count=count+y
b[i]=b[i]+(y*d)
else:
count=count+1+y
b[i]=b[i]+(y*d+d)
... | Title: Increasing Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*... | ```python
n,d=map(int,input().split())
b=list(map(int,input().split()))
count=0
for i in range(n):
if b[i]<b[i-1]:
x=b[i-1]-b[i]
y=x//(d+1)
if x%d==0:
count=count+y
b[i]=b[i]+(y*d)
else:
count=count+1+y
b[i]=b[i]+(y*d+d)
... | 0 |
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,615,767,367 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 307,200 | r,c=[int(x) for x in input().split()]
l=[]
for i in range(r):
s=[c for c in input()]
#print(s)
l.append(s)
cnt=0
#print(l)
for i in range(r):
if(l[i].count('S')>0):
cnt+=1
for i in range(c):
for j in range(r):
if(l[j][i]=='S'):
cnt+=1
break
#pr... | 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
r,c=[int(x) for x in input().split()]
l=[]
for i in range(r):
s=[c for c in input()]
#print(s)
l.append(s)
cnt=0
#print(l)
for i in range(r):
if(l[i].count('S')>0):
cnt+=1
for i in range(c):
for j in range(r):
if(l[j][i]=='S'):
cnt+=1
... | 0 | |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,687,220,813 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 92 | 0 | n = int(input())
lst = []
lst = list(map(int, input().split()))
c = 0
b = 0
ba = 0
for i in range(0,n):
if i % 3 == 0:
c += lst[i]
elif i % 3 == 1:
b += lst[i]
else:
ba += lst[i]
if c == max(c,b,ba):
print('chest')
elif b == max(c,b,ba):
print('biceps')
... | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
n = int(input())
lst = []
lst = list(map(int, input().split()))
c = 0
b = 0
ba = 0
for i in range(0,n):
if i % 3 == 0:
c += lst[i]
elif i % 3 == 1:
b += lst[i]
else:
ba += lst[i]
if c == max(c,b,ba):
print('chest')
elif b == max(c,b,ba):
print(... | 3 | |
574 | B | Bear and Three Musketeers | PROGRAMMING | 1,500 | [
"brute force",
"dfs and similar",
"graphs",
"hashing"
] | null | null | Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.
There are *n* warriors. Richelimakieu wants to choose thre... | The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other.
*i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**... | If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes). | [
"5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n",
"7 4\n2 1\n3 6\n5 1\n1 7\n"
] | [
"2\n",
"-1\n"
] | In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recogniti... | 1,000 | [
{
"input": "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5",
"output": "2"
},
{
"input": "7 4\n2 1\n3 6\n5 1\n1 7",
"output": "-1"
},
{
"input": "5 0",
"output": "-1"
},
{
"input": "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4",
"output": "5"
},
{
... | 1,604,676,978 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 19 | 2,000 | 17,408,000 | inpt = input().split()
n = int(inpt[0])
m = int(inpt[1])
dfs = [[] for i in range(n)]
for i in range(m):
inpt = input().split()
a = int(inpt[0]) - 1
b = int(inpt[1]) - 1
dfs[a].append(b)
dfs[b].append(a)
for i in dfs:
i.sort()
sets = []
for index, conn in enumerate(dfs):
... | Title: Bear and Three Musketeers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three br... | ```python
inpt = input().split()
n = int(inpt[0])
m = int(inpt[1])
dfs = [[] for i in range(n)]
for i in range(m):
inpt = input().split()
a = int(inpt[0]) - 1
b = int(inpt[1]) - 1
dfs[a].append(b)
dfs[b].append(a)
for i in dfs:
i.sort()
sets = []
for index, conn in enumera... | 0 | |
128 | C | Games with Rectangle | PROGRAMMING | 2,000 | [
"combinatorics",
"dp"
] | null | null | In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted *n*<=×<=*m* rectangle (only the border, no filling). Anna and Maria move in turns and Anna starts. During each move one should paint inside the last-painted rectangle a new lesser rectangle (along the grid... | The first and only line contains three integers: *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000). | Print the single number — the number of the ways to play the game. As this number can be very big, print the value modulo 1000000007 (109<=+<=7). | [
"3 3 1\n",
"4 4 1\n",
"6 7 2\n"
] | [
"1\n",
"9\n",
"75\n"
] | Two ways to play the game are considered different if the final pictures are different. In other words, if one way contains a rectangle that is not contained in the other way.
In the first sample Anna, who performs her first and only move, has only one possible action plan — insert a 1 × 1 square inside the given 3 × ... | 1,500 | [
{
"input": "3 3 1",
"output": "1"
},
{
"input": "4 4 1",
"output": "9"
},
{
"input": "6 7 2",
"output": "75"
},
{
"input": "5 5 3",
"output": "0"
},
{
"input": "2 2 1",
"output": "0"
},
{
"input": "999 999 499",
"output": "1"
},
{
"input": ... | 1,690,348,451 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 482 | 114,176,000 | n, m, k = map(int, input().split())
li = [[0 for _ in range(1001)] for _ in range(1001)]
for i in range(1001):
li[i][0] = 1
li[i][i] = 1
for i in range(1, 1001):
for j in range(1, i):
li[i][j] = li[i-1][j-1] + li[i-1][j]
if 2 * k <= n-1 and 2 * k <= m:
print(li[n-1][2 * k] * li[m-1][2 *... | Title: Games with Rectangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted *n*<=×<=*m* rectangle (only the border, no filling). Anna and Maria move in turns and Anna starts. ... | ```python
n, m, k = map(int, input().split())
li = [[0 for _ in range(1001)] for _ in range(1001)]
for i in range(1001):
li[i][0] = 1
li[i][i] = 1
for i in range(1, 1001):
for j in range(1, i):
li[i][j] = li[i-1][j-1] + li[i-1][j]
if 2 * k <= n-1 and 2 * k <= m:
print(li[n-1][2 * k] * l... | 3 | |
625 | C | K-special Tables | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | null | null | People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects.
Alis is among these collectors. Right now she wants to get one of *k*-special tables. In case you f... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=500,<=1<=≤<=*k*<=≤<=*n*) — the size of the table Alice is looking for and the column that should have maximum possible sum. | First print the sum of the integers in the *k*-th column of the required table.
Next *n* lines should contain the description of the table itself: first line should contains *n* elements of the first row, second line should contain *n* elements of the second row and so on.
If there are multiple suitable table, you ar... | [
"4 1\n",
"5 3\n"
] | [
"28\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16\n",
"85\n5 6 17 18 19\n9 10 23 24 25\n7 8 20 21 22\n3 4 14 15 16\n1 2 11 12 13\n\n"
] | none | 1,000 | [
{
"input": "4 1",
"output": "28\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16"
},
{
"input": "5 3",
"output": "85\n1 2 11 12 13\n3 4 14 15 16\n5 6 17 18 19\n7 8 20 21 22\n9 10 23 24 25"
},
{
"input": "1 1",
"output": "1\n1"
},
{
"input": "2 1",
"output": "4\n1 2\n3 4"
},
... | 1,456,219,219 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 733 | 7,475,200 | N, K = map(int, input().split())
mat = [[0] * N for _ in range(N)]
for i in range(N):
for j in range(K-1):
mat[i][j] = i * (K-1) + j + 1
for i in range(N):
for j in range(N-K+1):
mat[i][j+K-1] = N * (K-1) + i * (N - K + 1) + j + 1
print(sum(mat[i][K-1] for i in range(N)))
[print(*row) for row in... | Title: K-special Tables
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects... | ```python
N, K = map(int, input().split())
mat = [[0] * N for _ in range(N)]
for i in range(N):
for j in range(K-1):
mat[i][j] = i * (K-1) + j + 1
for i in range(N):
for j in range(N-K+1):
mat[i][j+K-1] = N * (K-1) + i * (N - K + 1) + j + 1
print(sum(mat[i][K-1] for i in range(N)))
[print(*row) ... | 3 | |
714 | A | Meeting of Old Friends | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya.
Filya works a lot and he plans to ... | The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. | Print one integer — the number of minutes Sonya and Filya will be able to spend together. | [
"1 10 9 20 1\n",
"1 100 50 200 75\n"
] | [
"2\n",
"50\n"
] | In the first sample, they will be together during minutes 9 and 10.
In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. | 500 | [
{
"input": "1 10 9 20 1",
"output": "2"
},
{
"input": "1 100 50 200 75",
"output": "50"
},
{
"input": "6 6 5 8 9",
"output": "1"
},
{
"input": "1 1000000000 1 1000000000 1",
"output": "999999999"
},
{
"input": "5 100 8 8 8",
"output": "0"
},
{
"input":... | 1,589,787,166 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 23 | 140 | 20,172,800 | a,b,c,d,e=map(int,input().split())
if a<c:
if b<d:
if e>=c:
if(b-c)<0:
print("0")
else:
print(b-c)
else:
if(b-c+1)<0:
print("0")
else:
print(b-c+1)
else:
if e>=c ... | Title: Meeting of Old Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusi... | ```python
a,b,c,d,e=map(int,input().split())
if a<c:
if b<d:
if e>=c:
if(b-c)<0:
print("0")
else:
print(b-c)
else:
if(b-c+1)<0:
print("0")
else:
print(b-c+1)
else:
... | 0 | |
825 | C | Multi-judge Solving | PROGRAMMING | 1,600 | [
"greedy",
"implementation"
] | null | null | Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty *d* on Decoforces is as hard as the problem with difficulty *d* on any other judge).... | The first line contains two integer numbers *n*, *k* (1<=≤<=*n*<=≤<=103, 1<=≤<=*k*<=≤<=109).
The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces. | [
"3 3\n2 1 9\n",
"4 20\n10 3 6 3\n"
] | [
"1\n",
"0\n"
] | In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.
In the second ... | 0 | [
{
"input": "3 3\n2 1 9",
"output": "1"
},
{
"input": "4 20\n10 3 6 3",
"output": "0"
},
{
"input": "1 1000000000\n1",
"output": "0"
},
{
"input": "1 1\n3",
"output": "1"
},
{
"input": "50 100\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34... | 1,500,224,627 | 7,127 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 4,812,800 | n,k=input ().split (" ");
inp=input ().split (" ");
numlist=[];
for no in inp:
numlist+=[int (no)];
numlist.sort ();
max=int (k);
other=0;
for a in numlist:
if (a < max):
continue;
elif (a <= max*2):
max=a;
else :
max*=2;
other+=1;
print (other); | Title: Multi-judge Solving
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the pro... | ```python
n,k=input ().split (" ");
inp=input ().split (" ");
numlist=[];
for no in inp:
numlist+=[int (no)];
numlist.sort ();
max=int (k);
other=0;
for a in numlist:
if (a < max):
continue;
elif (a <= max*2):
max=a;
else :
max*=2;
other+=1;
print (other);
``` | 0 | |
545 | D | Queue | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces. | Print a single number — the maximum number of not disappointed people in the queue. | [
"5\n15 2 1 5 3\n"
] | [
"4\n"
] | Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | 1,750 | [
{
"input": "5\n15 2 1 5 3",
"output": "4"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10\n13 2 5 55 21 34 1 8 1 3",
"output": "6"
},
{
"input": "10\n8 256 16 1 2 1 64 4 128 32",
"output": "10"
},
{
"input": "10\n10000 40000 1000... | 1,698,762,111 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 93 | 13,619,200 | # -*- coding: utf-8 -*-
"""
Created on Tue Oct 31 22:20:45 2023
@author: 袁兆瑞
"""
# 读取输入
n = int(input())
times = list(map(int, input().split()))
# 对时间列表进行排序
times.sort()
# 初始化变量
count = 0
sum_time = 0
# 计算最大不失望人数
for i in range(n):
if sum_time <= times[i]:
count += 1
sum_t... | Title: Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time... | ```python
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 31 22:20:45 2023
@author: 袁兆瑞
"""
# 读取输入
n = int(input())
times = list(map(int, input().split()))
# 对时间列表进行排序
times.sort()
# 初始化变量
count = 0
sum_time = 0
# 计算最大不失望人数
for i in range(n):
if sum_time <= times[i]:
count += 1
... | 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,687,101,793 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n=int(input())
lst=list(map(int,input().split()))
s=0
for i in lst:
s+=i/100
print((s/n)*100)
| 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())
lst=list(map(int,input().split()))
s=0
for i in lst:
s+=i/100
print((s/n)*100)
``` | 3 | |
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat... | The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one ... | Print one integer number — the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5... | 1,639,419,544 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 46 | 0 | n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
for i in arr:
if k % i == 0:
print(k // i)
exit(0)
| Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each ... | ```python
n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
for i in arr:
if k % i == 0:
print(k // i)
exit(0)
``` | 3 | |
792 | B | Counting-out Rhyme | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | *n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In the *i*-th step the leader counts out *a**i* people in clockwise order, starting from the next person. T... | The first line contains two integer numbers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1).
The next line contains *k* integer numbers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=109). | Print *k* numbers, the *i*-th one corresponds to the number of child to be eliminated at the *i*-th step. | [
"7 5\n10 4 11 4 1\n",
"3 2\n2 5\n"
] | [
"4 2 5 6 1 \n",
"3 2 \n"
] | Let's consider first example:
- In the first step child 4 is eliminated, child 5 becomes the leader. - In the second step child 2 is eliminated, child 3 becomes the leader. - In the third step child 5 is eliminated, child 6 becomes the leader. - In the fourth step child 6 is eliminated, child 7 becomes the leader... | 0 | [
{
"input": "7 5\n10 4 11 4 1",
"output": "4 2 5 6 1 "
},
{
"input": "3 2\n2 5",
"output": "3 2 "
},
{
"input": "2 1\n1",
"output": "2 "
},
{
"input": "2 1\n2",
"output": "1 "
},
{
"input": "2 1\n3",
"output": "2 "
},
{
"input": "10 7\n5 10 4 3 8 10 6",... | 1,589,673,919 | 1,519 | PyPy 3 | OK | TESTS | 22 | 140 | 20,172,800 | n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
c = 1
ans = []
b = [i for i in range(1, n+1)]
for i in range(k):
c = (c + a[i]-1)%n
ans.append(b[c])
b.pop(c)
n = n - 1
if n == 0:
break
c = (c + 1)%n
for i in ans:
print(i, end = " ")
... | Title: Counting-out Rhyme
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In ... | ```python
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
c = 1
ans = []
b = [i for i in range(1, n+1)]
for i in range(k):
c = (c + a[i]-1)%n
ans.append(b[c])
b.pop(c)
n = n - 1
if n == 0:
break
c = (c + 1)%n
for i in ans:
print(i, e... | 3 | |
821 | A | Okabe and Future Gadget Laboratory | PROGRAMMING | 800 | [
"implementation"
] | null | null | Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. ... | The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=50) — the size of the lab.
The next *n* lines contain *n* space-separated integers denoting a row of the grid. The *j*-th integer in the *i*-th row is *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=105). | Print "Yes" if the given lab is good and "No" otherwise.
You can output each letter in upper or lower case. | [
"3\n1 1 2\n2 3 1\n6 4 1\n",
"3\n1 5 2\n1 1 1\n1 2 3\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes".
In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an inte... | 500 | [
{
"input": "3\n1 1 2\n2 3 1\n6 4 1",
"output": "Yes"
},
{
"input": "3\n1 5 2\n1 1 1\n1 2 3",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 11 1 2\n2 5 1 4\n3 9 4 1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 7 1 1\n1 3 1 2\n2... | 1,628,943,324 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 93 | 7,782,400 | from typing import Counter
n = int(input())
a = []
rc = []
cc = [Counter() for _ in range(n)]
rg = range(n)
for _ in rg:
l = [int(x) for x in input().split()]
c = Counter(l)
rc.append(c)
for i in rg:
cc[i][l[i]] += 1
a.append(l)
bn = n - 1
good = True
for r in rg:
... | Title: Okabe and Future Gadget Laboratory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in whi... | ```python
from typing import Counter
n = int(input())
a = []
rc = []
cc = [Counter() for _ in range(n)]
rg = range(n)
for _ in rg:
l = [int(x) for x in input().split()]
c = Counter(l)
rc.append(c)
for i in rg:
cc[i][l[i]] += 1
a.append(l)
bn = n - 1
good = True
for... | 3 | |
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,686,554,193 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 154 | 0 | n = int(input())
a = list(map(int, input().split()))
cnt = 0
p = -1
for i in range(len(a)):
if a[i]%2 != a[0]%2:
cnt += 1
p = i + 1
if cnt != 1:
print(1)
else:
print(p) | 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())
a = list(map(int, input().split()))
cnt = 0
p = -1
for i in range(len(a)):
if a[i]%2 != a[0]%2:
cnt += 1
p = i + 1
if cnt != 1:
print(1)
else:
print(p)
``` | 3.9615 |
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"ou... | 1,687,520,317 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | import math
def divisor(n, k):
divisors = []
for i in range(1, int(math.sqrt(n)) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort()
if len(divisors) >= k:
return divisors[k - 1]
return -... | Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specificatio... | ```python
import math
def divisor(n, k):
divisors = []
for i in range(1, int(math.sqrt(n)) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort()
if len(divisors) >= k:
return divisors[k - 1]
... | 0 | |
937 | B | Vile Grasshoppers | PROGRAMMING | 1,400 | [
"brute force",
"math",
"number theory"
] | null | null | The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (more precise, from 2 to *p*) are occupied by tiny vile grasshoppers which you're at war with. These grassh... | The only line contains two integers *p* and *y* (2<=≤<=*p*<=≤<=*y*<=≤<=109). | Output the number of the highest suitable branch. If there are none, print -1 instead. | [
"3 6\n",
"3 4\n"
] | [
"5\n",
"-1\n"
] | In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.
It immediately follows that there are no valid branches in second sample case. | 1,000 | [
{
"input": "3 6",
"output": "5"
},
{
"input": "3 4",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "5 50",
"output": "49"
},
{
"input": "944192806 944193066",
"output": "944192807"
},
{
"input": "1000000000 1000000000",
"output":... | 1,540,933,099 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 109 | 0 | import math
p, y = input().split()
p = int(p)
y = int(y)
for i in range(y, p, -1):
for d in range(2, min(int(math.sqrt(i))+1, p)):
if i % d == 0:
break
else:
print(i)
break
else:
print(-1) | Title: Vile Grasshoppers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (mor... | ```python
import math
p, y = input().split()
p = int(p)
y = int(y)
for i in range(y, p, -1):
for d in range(2, min(int(math.sqrt(i))+1, p)):
if i % d == 0:
break
else:
print(i)
break
else:
print(-1)
``` | 0 | |
955 | B | Not simply beatiful strings | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of *a*-s and others — a ... | The only line contains *s* (1<=≤<=|*s*|<=≤<=105) consisting of lowercase latin letters. | Print «Yes» if the string can be split according to the criteria above or «No» otherwise.
Each letter can be printed in arbitrary case. | [
"ababa\n",
"zzcxx\n",
"yeee\n"
] | [
"Yes\n",
"Yes\n",
"No\n"
] | In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable.
There's no suitable partition in sample case three. | 1,000 | [
{
"input": "ababa",
"output": "Yes"
},
{
"input": "zzcxx",
"output": "Yes"
},
{
"input": "yeee",
"output": "No"
},
{
"input": "a",
"output": "No"
},
{
"input": "bbab",
"output": "No"
},
{
"input": "abcd",
"output": "Yes"
},
{
"input": "abc"... | 1,526,016,556 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 140 | 8,704,000 | """Problem B - Not simply beatiful strings.
http://codeforces.com/contest/955/problem/B
Let's call a string adorable if its letters can be realigned in such a way
that they form two consequent groups of equal symbols (note that different
groups must contain different symbols). For example, ababa is adorable (you can
... | Title: Not simply beatiful strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, abab... | ```python
"""Problem B - Not simply beatiful strings.
http://codeforces.com/contest/955/problem/B
Let's call a string adorable if its letters can be realigned in such a way
that they form two consequent groups of equal symbols (note that different
groups must contain different symbols). For example, ababa is adorable... | 3 | |
616 | A | Comparing Two Long Integers | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal.
The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.
As input/output can r... | The first line contains a non-negative integer *a*.
The second line contains a non-negative integer *b*.
The numbers *a*,<=*b* may contain leading zeroes. Each of them contains no more than 106 digits. | Print the symbol "<" if *a*<=<<=*b* and the symbol ">" if *a*<=><=*b*. If the numbers are equal print the symbol "=". | [
"9\n10\n",
"11\n10\n",
"00012345\n12345\n",
"0123\n9\n",
"0123\n111\n"
] | [
"<\n",
">\n",
"=\n",
">\n",
">\n"
] | none | 0 | [
{
"input": "9\n10",
"output": "<"
},
{
"input": "11\n10",
"output": ">"
},
{
"input": "00012345\n12345",
"output": "="
},
{
"input": "0123\n9",
"output": ">"
},
{
"input": "0123\n111",
"output": ">"
},
{
"input": "9\n9",
"output": "="
},
{
... | 1,588,595,170 | 2,147,483,647 | Python 3 | OK | TESTS | 120 | 124 | 3,993,600 | #ROUNIAAUDI
answerOne=input().lstrip('0')
answerTwo=input().lstrip('0')
#print(a)
if(len(answerOne)!=len(answerTwo)) :
print(">" if len(answerOne)>len(answerTwo) else "<")
else :
print(">" if answerOne>answerTwo else "<" if answerTwo > answerOne else "=")
| Title: Comparing Two Long Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal.
The input size is very large so don't use th... | ```python
#ROUNIAAUDI
answerOne=input().lstrip('0')
answerTwo=input().lstrip('0')
#print(a)
if(len(answerOne)!=len(answerTwo)) :
print(">" if len(answerOne)>len(answerTwo) else "<")
else :
print(">" if answerOne>answerTwo else "<" if answerTwo > answerOne else "=")
``` | 3 | |
609 | C | Load Balancing | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server.
In order to balance the load for each server, you want to reassign some tasks to make the differe... | The first line contains positive number *n* (1<=≤<=*n*<=≤<=105) — the number of the servers.
The second line contains the sequence of non-negative integers *m*1,<=*m*2,<=...,<=*m**n* (0<=≤<=*m**i*<=≤<=2·104), where *m**i* is the number of tasks assigned to the *i*-th server. | Print the minimum number of seconds required to balance the load. | [
"2\n1 6\n",
"7\n10 11 10 11 10 11 11\n",
"5\n1 2 3 4 5\n"
] | [
"2\n",
"0\n",
"3\n"
] | In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2.
In the second example the load is already balanced.
A possible sequence of task movements for the third example is:
... | 0 | [
{
"input": "2\n1 6",
"output": "2"
},
{
"input": "7\n10 11 10 11 10 11 11",
"output": "0"
},
{
"input": "5\n1 2 3 4 5",
"output": "3"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n20000",
... | 1,646,550,402 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 31 | 0 | n=int(input())
a=list(map(int,input().split()))
q=(sum(a)+n-1)//n
w,e=0,0
for i in a:
if i>q:
w+=i-q
else:
e+=q-i
print(min(w,e))
| Title: Load Balancing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server... | ```python
n=int(input())
a=list(map(int,input().split()))
q=(sum(a)+n-1)//n
w,e=0,0
for i in a:
if i>q:
w+=i-q
else:
e+=q-i
print(min(w,e))
``` | 0 | |
171 | D | Broken checker | PROGRAMMING | 1,300 | [
"*special",
"brute force"
] | null | null | "This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" — people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem was alright, that's a mercy. | The only line of the input contains an integer between 1 and 5, inclusive. All tests for this problem are different. The contents of the test case doesn't need to be equal to its index. | The only line of the output contains an integer between 1 and 3, inclusive. | [] | [] | This problem has no samples, since there so few test cases. | 0 | [
{
"input": "3",
"output": "1"
},
{
"input": "1",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "2",
"output": "3"
},
{
"input": "5",
"output": "1"
}
] | 1,554,141,993 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 0 | n = int(input())
print([2, 3,1,1,1][n - 1]) | Title: Broken checker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" — people complained in the comments to one round on Codeforces. And even more... No,... | ```python
n = int(input())
print([2, 3,1,1,1][n - 1])
``` | 0 | |
682 | D | Alyona and Strings | PROGRAMMING | 1,900 | [
"dp",
"strings"
] | null | null | After returned from forest, Alyona started reading a book. She noticed strings *s* and *t*, lengths of which are *n* and *m* respectively. As usual, reading bored Alyona and she decided to pay her attention to strings *s* and *t*, which she considered very similar.
Alyona has her favourite positive integer *k* and bec... | In the first line of the input three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=10) are given — the length of the string *s*, the length of the string *t* and Alyona's favourite number respectively.
The second line of the input contains string *s*, consisting of lowercase English letters.
The thi... | In the only line print the only non-negative integer — the sum of the lengths of the strings in a desired sequence.
It is guaranteed, that at least one desired sequence exists. | [
"3 2 2\nabc\nab\n",
"9 12 4\nbbaaababb\nabbbabbaaaba\n"
] | [
"2\n",
"7\n"
] | The following image describes the answer for the second sample case: | 2,000 | [
{
"input": "3 2 2\nabc\nab",
"output": "2"
},
{
"input": "9 12 4\nbbaaababb\nabbbabbaaaba",
"output": "7"
},
{
"input": "11 11 4\naaababbabbb\nbbbaaaabaab",
"output": "7"
},
{
"input": "15 9 4\nababaaabbaaaabb\nbbaababbb",
"output": "8"
},
{
"input": "2 7 1\nbb\nb... | 1,508,765,104 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 16 | 2,000 | 33,280,000 | n, m, k = map(int, input().split())
s, t = input(), input()
n += 1
m += 1
d = [0] * n * m
p = [i for i in range(n * m - n) if (i + 1) % n]
for i in p:
if s[i % n] == t[i // n]: d[i] = d[i - n - 1] + 1
f = d.copy()
for y in range(k - 1):
for i in p: f[i] = max(f[i], f[i - 1], f[i - n])
for... | Title: Alyona and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After returned from forest, Alyona started reading a book. She noticed strings *s* and *t*, lengths of which are *n* and *m* respectively. As usual, reading bored Alyona and she decided to pay her attention to string... | ```python
n, m, k = map(int, input().split())
s, t = input(), input()
n += 1
m += 1
d = [0] * n * m
p = [i for i in range(n * m - n) if (i + 1) % n]
for i in p:
if s[i % n] == t[i // n]: d[i] = d[i - n - 1] + 1
f = d.copy()
for y in range(k - 1):
for i in p: f[i] = max(f[i], f[i - 1], f[i - n]... | 0 | |
909 | A | Generate Login | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"sortings"
] | null | null | The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and ... | The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. | Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. | [
"harry potter\n",
"tom riddle\n"
] | [
"hap\n",
"tomr\n"
] | none | 500 | [
{
"input": "harry potter",
"output": "hap"
},
{
"input": "tom riddle",
"output": "tomr"
},
{
"input": "a qdpinbmcrf",
"output": "aq"
},
{
"input": "wixjzniiub ssdfodfgap",
"output": "wis"
},
{
"input": "z z",
"output": "zz"
},
{
"input": "ertuyivhfg v"... | 1,514,466,965 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 77 | 5,529,600 | N = list(map(str, input().split()))
fn, ln = str(N[0]), str(N[1])
un = ""
flag = 0
i = 1
un = un + fn[0]
while i < len(fn):
if fn[i] < ln[0]:
un = un + fn[i]
i = i + 1
else:
un = un + ln[0]
flag = 1
break
if flag == 0:
un = un + ln[0]
print(un)
el... | Title: Generate Login
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the fu... | ```python
N = list(map(str, input().split()))
fn, ln = str(N[0]), str(N[1])
un = ""
flag = 0
i = 1
un = un + fn[0]
while i < len(fn):
if fn[i] < ln[0]:
un = un + fn[i]
i = i + 1
else:
un = un + ln[0]
flag = 1
break
if flag == 0:
un = un + ln[0]
pri... | 3 | |
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and c... | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",... | 1,698,165,168 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 124 | 4,198,400 | n = int(input())
needed = set()
i = 1
t = 1
failed = True
while t <= n :
t = (i * (i + 1)) / 2
if (t in needed) or t + t == n:
print("YES")
failed = False
break
else:
needed.add(n - t)
i += 1
if (failed) : print("NO")
| Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent... | ```python
n = int(input())
needed = set()
i = 1
t = 1
failed = True
while t <= n :
t = (i * (i + 1)) / 2
if (t in needed) or t + t == n:
print("YES")
failed = False
break
else:
needed.add(n - t)
i += 1
if (failed) : print("NO")
``` | 3 | |
172 | A | Phone Code | PROGRAMMING | 800 | [
"*special",
"brute force",
"implementation"
] | null | null | Polycarpus has *n* friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings *s*1,<=*s*2,<=...,<=*s**n*. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the... | The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=3·104) — the number of Polycarpus's friends. The following *n* lines contain strings *s*1,<=*s*2,<=...,<=*s**n* — the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, ... | Print the number of digits in the city phone code. | [
"4\n00209\n00219\n00999\n00909\n",
"2\n1\n2\n",
"3\n77012345678999999999\n77012345678901234567\n77012345678998765432\n"
] | [
"2\n",
"0\n",
"12\n"
] | A prefix of string *t* is a string that is obtained by deleting zero or more digits from the end of string *t*. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an em... | 1,000 | [
{
"input": "4\n00209\n00219\n00999\n00909",
"output": "2"
},
{
"input": "2\n1\n2",
"output": "0"
},
{
"input": "3\n77012345678999999999\n77012345678901234567\n77012345678998765432",
"output": "12"
},
{
"input": "5\n4491183345\n4491184811\n4491162340\n4491233399\n4491449214",
... | 1,599,992,797 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 684 | 1,945,600 | nums = []
for _ in range(int(input())):
nums.append(str(input()))
pointer, length = 1, 0
while pointer < len(nums[0]) + 1:
count = 0
for j in range(1, len(nums)):
if nums[j][pointer - 1] != nums[0][pointer - 1]:
break
count += 1
if count != len(nums) - 1:
b... | Title: Phone Code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has *n* friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings *s*1,<=*s*2,<=...,<=*s**n*. All these strings consist only of digits and have the same length.
Once Polycarpus... | ```python
nums = []
for _ in range(int(input())):
nums.append(str(input()))
pointer, length = 1, 0
while pointer < len(nums[0]) + 1:
count = 0
for j in range(1, len(nums)):
if nums[j][pointer - 1] != nums[0][pointer - 1]:
break
count += 1
if count != len(nums) - 1:
... | 3 | |
287 | A | IQ Test | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the... | Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black. | Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise. | [
"####\n.#..\n####\n....\n",
"####\n....\n####\n....\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | 500 | [
{
"input": "###.\n...#\n###.\n...#",
"output": "NO"
},
{
"input": ".##.\n#..#\n.##.\n#..#",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n.#.#\n#.#.",
"output": "NO"
},
{
"input": "##..\n..##\n##..\n..##",
"output": "NO"
},
{
"input": "#.#.\n#.#.\n.#.#\n.#.#",
"ou... | 1,580,293,683 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 307,200 | c=[['1', '2', '3', '4'], ['1', '2', '3', '4'], ['4', '3', '2', '1'], ['2', '3', '4', '5']]
lst=[]
f=0
for i in range(4):
a=list(input().split())
lst.append(a)
#print(lst)
cl=[]
for i in range(3):
for j in range(3):
a,b,c,d=lst[i][j],lst[i][j+1],lst[i+1][j],lst[i+1][j+1]
cl=[... | Title: IQ Test
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and o... | ```python
c=[['1', '2', '3', '4'], ['1', '2', '3', '4'], ['4', '3', '2', '1'], ['2', '3', '4', '5']]
lst=[]
f=0
for i in range(4):
a=list(input().split())
lst.append(a)
#print(lst)
cl=[]
for i in range(3):
for j in range(3):
a,b,c,d=lst[i][j],lst[i][j+1],lst[i+1][j],lst[i+1][j+1]
... | -1 | |
979 | A | Pizza, Pizza, Pizza!!! | PROGRAMMING | 1,000 | [
"math"
] | null | null | Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to cele... | A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces. | A single integer — the number of straight cuts Shiro needs. | [
"3\n",
"4\n"
] | [
"2",
"5"
] | To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts. | 500 | [
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "5"
},
{
"input": "10",
"output": "11"
},
{
"input": "10000000000",
"output": "10000000001"
},
{
"input": "1234567891",
"output": "617283946"
},
{
"input": "7509213957",
"output": "37546069... | 1,526,987,543 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 77 | 0 | n = int(input())
n = n + 1
if n % 2 == 1:
print(n)
else:
print(int(n/2)) | Title: Pizza, Pizza, Pizza!!!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthd... | ```python
n = int(input())
n = n + 1
if n % 2 == 1:
print(n)
else:
print(int(n/2))
``` | 0 | |
981 | A | Antipalindrome | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}... | The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. | If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique. | [
"mew\n",
"wuffuw\n",
"qqqqqqqq\n"
] | [
"3\n",
"5\n",
"0\n"
] | "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All sub... | 500 | [
{
"input": "mew",
"output": "3"
},
{
"input": "wuffuw",
"output": "5"
},
{
"input": "qqqqqqqq",
"output": "0"
},
{
"input": "ijvji",
"output": "4"
},
{
"input": "iiiiiii",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow"... | 1,531,401,539 | 2,147,483,647 | Python 3 | OK | TESTS | 133 | 124 | 0 | s=input()
n=len(s)
k=0
for i in range(n):
for j in range(i+1,n+1):
t=s[i:j]
if t!=t[::-1]:
k=max(k,j-i)
print(k) | Title: Antipalindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" ar... | ```python
s=input()
n=len(s)
k=0
for i in range(n):
for j in range(i+1,n+1):
t=s[i:j]
if t!=t[::-1]:
k=max(k,j-i)
print(k)
``` | 3 | |
559 | B | Equivalent Strings | PROGRAMMING | 1,700 | [
"divide and conquer",
"hashing",
"sortings",
"strings"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 1,000 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,585,549,952 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 18 | 156 | 2,150,400 | a=input()
b=input()
if(a==b):
print("YES")
else:
n=len(a)//2
a1=a[:n]
a1="".join(sorted(a1))
a2=a[n:]
a2="".join(sorted(a2))
b1=b[:n]
b1="".join(sorted(b1))
b2=b[n:]
b2="".join(sorted(b2))
#print(n,a1,a2,b1,b2)
if((a1==b1 and a2==b2) or (a1==b2 and a2==b1))... | Title: Equivalent Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split str... | ```python
a=input()
b=input()
if(a==b):
print("YES")
else:
n=len(a)//2
a1=a[:n]
a1="".join(sorted(a1))
a2=a[n:]
a2="".join(sorted(a2))
b1=b[:n]
b1="".join(sorted(b1))
b2=b[n:]
b2="".join(sorted(b2))
#print(n,a1,a2,b1,b2)
if((a1==b1 and a2==b2) or (a1==b2 an... | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,587,150,474 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 248 | 0 | n = int(input())
l = []
a= 0
b = 0
c = 0
for y in range(n):
i ,j,k = map(int, input().split())
a += i
b += j
c += k
if (a == 0 and b == 0 and c == 0) :
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
l = []
a= 0
b = 0
c = 0
for y in range(n):
i ,j,k = map(int, input().split())
a += i
b += j
c += k
if (a == 0 and b == 0 and c == 0) :
print("YES")
else:
print("NO")
``` | 3.938 |
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,670,009,391 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | s=list(input())
s=list(set(s))
i=0
a=0
while i<len(s):
if s[i]=='h' and s[i+1]=='e' and s[i+2]=='l' and s[i+3]=='o':
print('YES')
a+=1
break
i+=1
if a==0:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=list(input())
s=list(set(s))
i=0
a=0
while i<len(s):
if s[i]=='h' and s[i+1]=='e' and s[i+2]=='l' and s[i+3]=='o':
print('YES')
a+=1
break
i+=1
if a==0:
print("NO")
``` | 0 |
835 | C | Star sky | PROGRAMMING | 1,600 | [
"dp",
"implementation"
] | null | null | The Cartesian coordinate system is set in the sky. There you can see *n* stars, the *i*-th has coordinates (*x**i*, *y**i*), a maximum brightness *c*, equal for all stars, and an initial brightness *s**i* (0<=≤<=*s**i*<=≤<=*c*).
Over time the stars twinkle. At moment 0 the *i*-th star has brightness *s**i*. Let at mom... | The first line contains three integers *n*, *q*, *c* (1<=≤<=*n*,<=*q*<=≤<=105, 1<=≤<=*c*<=≤<=10) — the number of the stars, the number of the views and the maximum brightness of the stars.
The next *n* lines contain the stars description. The *i*-th from these lines contains three integers *x**i*, *y**i*, *s**i* (1<=≤... | For each view print the total brightness of the viewed stars. | [
"2 3 3\n1 1 1\n3 2 0\n2 1 1 2 2\n0 2 1 4 5\n5 1 1 5 5\n",
"3 4 5\n1 1 2\n2 3 0\n3 3 1\n0 1 1 100 100\n1 2 2 4 4\n2 2 1 4 7\n1 50 50 51 51\n"
] | [
"3\n0\n3\n",
"3\n3\n5\n0\n"
] | Let's consider the first example.
At the first view, you can see only the first star. At moment 2 its brightness is 3, so the answer is 3.
At the second view, you can see only the second star. At moment 0 its brightness is 0, so the answer is 0.
At the third view, you can see both stars. At moment 5 brightness of th... | 1,250 | [
{
"input": "2 3 3\n1 1 1\n3 2 0\n2 1 1 2 2\n0 2 1 4 5\n5 1 1 5 5",
"output": "3\n0\n3"
},
{
"input": "3 4 5\n1 1 2\n2 3 0\n3 3 1\n0 1 1 100 100\n1 2 2 4 4\n2 2 1 4 7\n1 50 50 51 51",
"output": "3\n3\n5\n0"
}
] | 1,699,114,366 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 155 | 12,288,000 | from os import path
from sys import stdin, stdout
from typing import List
filename = "../templates/input.txt"
if path.exists(filename):
stdin = open(filename, 'r')
def input():
return stdin.readline().rstrip()
def print(*args, sep=' ', end='\n'):
stdout.write(sep.join(map(str, args)))
... | Title: Star sky
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Cartesian coordinate system is set in the sky. There you can see *n* stars, the *i*-th has coordinates (*x**i*, *y**i*), a maximum brightness *c*, equal for all stars, and an initial brightness *s**i* (0<=≤<=*s**i*<=≤<=*c*... | ```python
from os import path
from sys import stdin, stdout
from typing import List
filename = "../templates/input.txt"
if path.exists(filename):
stdin = open(filename, 'r')
def input():
return stdin.readline().rstrip()
def print(*args, sep=' ', end='\n'):
stdout.write(sep.join(map(str, a... | 0 | |
875 | A | Classroom Watch | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109). | In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order. | [
"21\n",
"20\n"
] | [
"1\n15\n",
"0\n"
] | In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | 500 | [
{
"input": "21",
"output": "1\n15"
},
{
"input": "20",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "3",
"output": "0"
},
{
"input": "100000001",
"output": "2\n99999937\n100000000"
},
{
"i... | 1,556,726,180 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 108 | 0 | x=int(input())
n=x
l=1
while 1:
m=n+sum([int(k) for k in str(n)])
# print(m)
if m==x:
break
if n==(x//2):
l=0
break
else:
# print(n)
n-=1
continue
print(l)
if l==1:
print(n) | Title: Classroom Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answe... | ```python
x=int(input())
n=x
l=1
while 1:
m=n+sum([int(k) for k in str(n)])
# print(m)
if m==x:
break
if n==(x//2):
l=0
break
else:
# print(n)
n-=1
continue
print(l)
if l==1:
print(n)
``` | 0 | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,567,347,881 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 218 | 0 | n=int(input())
x=str(n)
for i in range(0,len(x)):
if(x[i]=='0'):
y=x[0:i]+x[i+1:len(x)]
break
print(int(y)) | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
n=int(input())
x=str(n)
for i in range(0,len(x)):
if(x[i]=='0'):
y=x[0:i]+x[i+1:len(x)]
break
print(int(y))
``` | -1 | |
248 | B | Chilly Willy | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them.
Chilly Willy wants to find the minimum number of length *n*, such that it is simultaneous... | A single input line contains a single integer *n* (1<=≤<=*n*<=≤<=105). | Print a single integer — the answer to the problem without leading zeroes, or "-1" (without the quotes), if the number that meet the problem condition does not exist. | [
"1\n",
"5\n"
] | [
"-1\n",
"10080"
] | none | 1,000 | [
{
"input": "1",
"output": "-1"
},
{
"input": "5",
"output": "10080"
},
{
"input": "6",
"output": "100170"
},
{
"input": "4",
"output": "1050"
},
{
"input": "15",
"output": "100000000000110"
},
{
"input": "16",
"output": "1000000000000050"
},
{
... | 1,698,946,063 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 66 | 186 | 5,632,000 | n=210
k=int(input())
if (k<=2): print(-1)
else: print(n*((10**(k-1))//n+1)) | Title: Chilly Willy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected wit... | ```python
n=210
k=int(input())
if (k<=2): print(-1)
else: print(n*((10**(k-1))//n+1))
``` | 3 | |
11 | B | Jumping Jack | PROGRAMMING | 1,600 | [
"math"
] | B. Jumping Jack | 1 | 64 | Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or ri... | The input data consists of only one integer *x* (<=-<=109<=≤<=*x*<=≤<=109). | Output the minimal number of jumps that Jack requires to reach *x*. | [
"2\n",
"6\n",
"0\n"
] | [
"3\n",
"3\n",
"0\n"
] | none | 0 | [
{
"input": "2",
"output": "3"
},
{
"input": "6",
"output": "3"
},
{
"input": "0",
"output": "0"
},
{
"input": "-1000000000",
"output": "44723"
},
{
"input": "999961560",
"output": "44720"
},
{
"input": "999961561",
"output": "44721"
},
{
"i... | 1,623,777,807 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 122 | 0 | def main():
x = int(input())
num = ans = 0
while num != x:
if num+ans+1 <= x:
ans += 1
num += ans
elif num+ans+1 > x:
ans += 1
num -= ans
print(ans)
if __name__ == "__main__":
main() | Title: Jumping Jack
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each ... | ```python
def main():
x = int(input())
num = ans = 0
while num != x:
if num+ans+1 <= x:
ans += 1
num += ans
elif num+ans+1 > x:
ans += 1
num -= ans
print(ans)
if __name__ == "__main__":
ma... | 0 |
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "Y... | 1,635,422,207 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 30 | 124 | 5,734,400 | n=input()
m=input()
x=sorted(n)
j=sorted(m)
if(x==j):
print("YES")
else:
print("NO") | Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ... | ```python
n=input()
m=input()
x=sorted(n)
j=sorted(m)
if(x==j):
print("YES")
else:
print("NO")
``` | 0 | |
960 | B | Minimize the error | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1.
Output the min... | The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively.
Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-... | Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. | [
"2 0 0\n1 2\n2 3\n",
"2 1 0\n1 2\n2 2\n",
"2 5 7\n3 4\n14 4\n"
] | [
"2",
"0",
"1"
] | In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2.
In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we... | 1,000 | [
{
"input": "2 0 0\n1 2\n2 3",
"output": "2"
},
{
"input": "2 1 0\n1 2\n2 2",
"output": "0"
},
{
"input": "2 5 7\n3 4\n14 4",
"output": "1"
},
{
"input": "2 0 1\n1 2\n2 2",
"output": "0"
},
{
"input": "2 1 1\n0 0\n1 1",
"output": "0"
},
{
"input": "5 5 ... | 1,537,895,398 | 2,147,483,647 | Python 3 | OK | TESTS | 80 | 280 | 0 | n, k1, k2 = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
a = []
k = 0
for i in range(n):
a.append(abs(arr1[i]-arr2[i]))
k += a[i]
if k<=(k1+k2):
print((k-k1-k2)%2)
else:
for j in range(k1+k2):
m = 0
for x in range(n):
if a[x]>m:
i = x
m = a[x... | Title: Minimize the error
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one ... | ```python
n, k1, k2 = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
a = []
k = 0
for i in range(n):
a.append(abs(arr1[i]-arr2[i]))
k += a[i]
if k<=(k1+k2):
print((k-k1-k2)%2)
else:
for j in range(k1+k2):
m = 0
for x in range(n):
if a[x]>m:
i = x
... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery.
Soon the expenses started to overcome the income, so Slastyona decided to study the sweets market. She learned it's profitable to pack ca... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=35000, 1<=≤<=*k*<=≤<=*min*(*n*,<=50)) – the number of cakes and the number of boxes, respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) – the types of cakes in the order the oven bakes them. | Print the only integer – the maximum total value of all boxes with cakes. | [
"4 1\n1 2 2 1\n",
"7 2\n1 3 3 1 4 4 4\n",
"8 3\n7 7 8 7 7 8 1 7\n"
] | [
"2\n",
"5\n",
"6\n"
] | In the first example Slastyona has only one box. She has to put all cakes in it, so that there are two types of cakes in the box, so the value is equal to 2.
In the second example it is profitable to put the first two cakes in the first box, and all the rest in the second. There are two distinct types in the first box... | 0 | [] | 1,691,859,362 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1691859361.7138336")# 1691859361.7138517 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery.
Soon the expenses started to overcome the incom... | ```python
print("_RANDOM_GUESS_1691859361.7138336")# 1691859361.7138517
``` | 0 | |
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,692,037,413 | 2,147,483,647 | PyPy 3 | OK | TESTS | 81 | 93 | 0 | n=int(input())
arr1=list(map(int,input().split()))
m=int(input())
arr2=list(map(int,input().split()))
arr1.sort()
arr2.sort()
i=0
j=0
ans=0
while i <n and j < m:
if abs(arr1[i]-arr2[j])<=1:
ans+=1
i+=1
j+=1
elif arr1[i]>arr2[j]:
j+=1
else:
i+=1
print... | 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
n=int(input())
arr1=list(map(int,input().split()))
m=int(input())
arr2=list(map(int,input().split()))
arr1.sort()
arr2.sort()
i=0
j=0
ans=0
while i <n and j < m:
if abs(arr1[i]-arr2[j])<=1:
ans+=1
i+=1
j+=1
elif arr1[i]>arr2[j]:
j+=1
else:
i... | 3 | |
508 | A | Pasha and Pixels | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choos... | The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i*... | If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0. | [
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n",
"5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n"
] | [
"4\n",
"5\n",
"0\n"
] | none | 500 | [
{
"input": "2 2 4\n1 1\n1 2\n2 1\n2 2",
"output": "4"
},
{
"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1",
"output": "5"
},
{
"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2",
"output": "0"
},
{
"input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3",
... | 1,697,638,759 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 280 | 10,547,200 | def check(x, y, rec):
if rec[x][y] and rec[x+1][y] and rec[x][y+1] and rec[x+1][y+1]:
return True
if rec[x][y] and rec[x-1][y] and rec[x][y-1] and rec[x-1][y-1]:
return True
if rec[x][y] and rec[x-1][y] and rec[x][y+1] and rec[x-1][y+1]:
return True
if rec[x][y] and rec[x+... | Title: Pasha and Pixels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row ... | ```python
def check(x, y, rec):
if rec[x][y] and rec[x+1][y] and rec[x][y+1] and rec[x+1][y+1]:
return True
if rec[x][y] and rec[x-1][y] and rec[x][y-1] and rec[x-1][y-1]:
return True
if rec[x][y] and rec[x-1][y] and rec[x][y+1] and rec[x-1][y+1]:
return True
if rec[x][y] ... | 3 | |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,699,020,466 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n=int(input())
s=0
for i in range(1,n+1,2):
s=s-i
s=s+(i+1)
print(s*-1)
| Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
n=int(input())
s=0
for i in range(1,n+1,2):
s=s-i
s=s+(i+1)
print(s*-1)
``` | 0 | |
691 | A | Fashion in Berland | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fast... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | [
"3\n1 0 1\n",
"3\n1 0 0\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 0 1",
"output": "YES"
},
{
"input": "3\n1 0 0",
"output": "NO"
},
{
"input": "3\n1 1 0",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n0 0 1",
"output": "NO"
},
{
"input": "3\n0 0 0",
"output": "NO"
}... | 1,495,629,383 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 77 | 0 | number_of_buttons = int(input())
buttons = [int(x) for x in input().split()]
count = 0
if len(buttons) == 1:
if buttons[0] == 0:
print("NO")
else:
print("YES")
for button in buttons:
if button == 0:
count = count + 1
if count == 1:
print("YES")
else:
print... | Title: Fashion in Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened,... | ```python
number_of_buttons = int(input())
buttons = [int(x) for x in input().split()]
count = 0
if len(buttons) == 1:
if buttons[0] == 0:
print("NO")
else:
print("YES")
for button in buttons:
if button == 0:
count = count + 1
if count == 1:
print("YES")
else:
... | 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,694,863,069 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 62 | 0 | s = input("")
for l in 'hello':
#print('letra=',l,'s=',s)
achou = 0
while len(s)>0:
if l==s[0]:
achou=1
s = s[1:]
break;
else:
s=s[1:]
#print(s,'l=',l,'s[i]=','achou=',achou)
if achou==0:
print('NO')
ex... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s = input("")
for l in 'hello':
#print('letra=',l,'s=',s)
achou = 0
while len(s)>0:
if l==s[0]:
achou=1
s = s[1:]
break;
else:
s=s[1:]
#print(s,'l=',l,'s[i]=','achou=',achou)
if achou==0:
print('NO')
... | 3.969 |
452 | A | Eevee | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"strings"
] | null | null | You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Syl... | First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string.
Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword). | Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter). | [
"7\nj......\n",
"7\n...feon\n",
"7\n.l.r.o.\n"
] | [
"jolteon\n",
"leafeon\n",
"flareon\n"
] | Here's a set of names in a form you can paste into your solution:
["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
{"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"} | 500 | [
{
"input": "7\n...feon",
"output": "leafeon"
},
{
"input": "7\n.l.r.o.",
"output": "flareon"
},
{
"input": "6\n.s..o.",
"output": "espeon"
},
{
"input": "7\nglaceon",
"output": "glaceon"
},
{
"input": "8\n.a.o.e.n",
"output": "vaporeon"
},
{
"input": "... | 1,612,103,892 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 93 | 0 | ref = ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
n = int(input())
s = str(input())
output = ''
for j in range(len(ref)):
if len(ref[j]) != n:
continue
alpha, count = 0, 0
for k in range(n):
if s[k] >= 'a' and s[k] <= 'z':
al... | Title: Eevee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight... | ```python
ref = ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
n = int(input())
s = str(input())
output = ''
for j in range(len(ref)):
if len(ref[j]) != n:
continue
alpha, count = 0, 0
for k in range(n):
if s[k] >= 'a' and s[k] <= 'z':
... | 3 | |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,638,813,408 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 614,400 | x = int(input())
ans = list(range(1, x//2+1))
ans = [i for i in ans if (x-i) % i == 0]
print(len(ans))
| Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
x = int(input())
ans = list(range(1, x//2+1))
ans = [i for i in ans if (x-i) % i == 0]
print(len(ans))
``` | 3 | |
887 | C | Solution for Cube | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation... | In first line given a sequence of 24 integers *a**i* (1<=≤<=*a**i*<=≤<=6), where *a**i* denotes color of *i*-th square. There are exactly 4 occurrences of all colors in this sequence. | Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise. | [
"2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4\n",
"5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3\n"
] | [
"NO",
"YES"
] | In first test case cube looks like this:
In second test case cube looks like this:
It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16. | 1,500 | [
{
"input": "2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4",
"output": "NO"
},
{
"input": "5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3",
"output": "YES"
},
{
"input": "2 6 3 3 5 5 2 6 1 1 6 4 4 4 2 4 6 5 3 1 2 5 3 1",
"output": "NO"
},
{
"input": "3 4 2 3 5 5 6 6 4 5 4 6... | 1,509,738,853 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | C = str(input())
A = C.split()
L = []
for k in range(len(A)): L.append(int(A[k]))
if(L[0]==L[1]==L[2]==L[3]):
print("YES")
elif(L[16]==L[17]==L[18]==L[19]):
print("YES")
elif(L[12]==L[13]==L[14]==L[15]):
print("YES")
elif(L[8]==L[9]==L[10]==L[11]):
print("YES")
else:
print("NO")
| Title: Solution for Cube
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly,... | ```python
C = str(input())
A = C.split()
L = []
for k in range(len(A)): L.append(int(A[k]))
if(L[0]==L[1]==L[2]==L[3]):
print("YES")
elif(L[16]==L[17]==L[18]==L[19]):
print("YES")
elif(L[12]==L[13]==L[14]==L[15]):
print("YES")
elif(L[8]==L[9]==L[10]==L[11]):
print("YES")
else:
print... | 0 | |
685 | A | Robbers' watch | PROGRAMMING | 1,700 | [
"brute force",
"combinatorics",
"dp",
"math"
] | null | null | Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in *n* ho... | The first line of the input contains two integers, given in the decimal notation, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=109) — the number of hours in one day and the number of minutes in one hour, respectively. | Print one integer in decimal notation — the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct. | [
"2 3\n",
"8 2\n"
] | [
"4\n",
"5\n"
] | In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1). | 500 | [
{
"input": "2 3",
"output": "4"
},
{
"input": "8 2",
"output": "5"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "8 8",
"output": "0"
},
{
"input": "50 50",
"output": "0"
},
{
"input": "344 344",
"o... | 1,466,703,058 | 3,358 | Python 3 | OK | TESTS | 39 | 62 | 0 | def D(n):
x,r=n-1,1
while x>=7:
x//=7
r+=1
return r
def H(n,l):
x,r=n,""
if x==0:r+='0'
while x:
r+=chr(ord('0')+x%7)
x//=7
r+='0'*(l-len(r))
return r
a,b=map(int,input().split())
la=D(a)
lb=D(b)
V=[0]*99
r=0
def F(deep,wa,wb):
global r
if wa>=a or wb>=b:return
if deep==la+lb:
... | Title: Robbers' watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad a... | ```python
def D(n):
x,r=n-1,1
while x>=7:
x//=7
r+=1
return r
def H(n,l):
x,r=n,""
if x==0:r+='0'
while x:
r+=chr(ord('0')+x%7)
x//=7
r+='0'*(l-len(r))
return r
a,b=map(int,input().split())
la=D(a)
lb=D(b)
V=[0]*99
r=0
def F(deep,wa,wb):
global r
if wa>=a or wb>=b:return
if deep... | 3 | |
534 | C | Polycarpus' Dice | PROGRAMMING | 1,600 | [
"math"
] | null | null | Polycarp has *n* dice *d*1,<=*d*2,<=...,<=*d**n*. The *i*-th dice shows numbers from 1 to *d**i*. Polycarp rolled all the dice and the sum of numbers they showed is *A*. Agrippina didn't see which dice showed what number, she knows only the sum *A* and the values *d*1,<=*d*2,<=...,<=*d**n*. However, she finds it enough... | The first line contains two integers *n*,<=*A* (1<=≤<=*n*<=≤<=2·105,<=*n*<=≤<=*A*<=≤<=*s*) — the number of dice and the sum of shown values where *s*<==<=*d*1<=+<=*d*2<=+<=...<=+<=*d**n*.
The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=106), where *d**i* is the maximum value that the... | Print *n* integers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* is the number of values for which it is guaranteed that the *i*-th dice couldn't show them. | [
"2 8\n4 4\n",
"1 3\n5\n",
"2 3\n2 3\n"
] | [
"3 3 ",
"4 ",
"0 1 "
] | In the first sample from the statement *A* equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement *A* equal to 3 could be obtained when the single dice shows 3. Correspondingly, it ... | 1,500 | [
{
"input": "2 8\n4 4",
"output": "3 3 "
},
{
"input": "1 3\n5",
"output": "4 "
},
{
"input": "2 3\n2 3",
"output": "0 1 "
},
{
"input": "1 1\n3",
"output": "2 "
},
{
"input": "1 2\n3",
"output": "2 "
},
{
"input": "2 2\n2 3",
"output": "1 2 "
},
... | 1,428,862,261 | 7,861 | Python 3 | WRONG_ANSWER | PRETESTS | 7 | 61 | 0 | n, a = map(int, input().split())
d = list(map(int, input().split()))
b = [0 for i in d]
s = sum (d)
if n == 1:
print (d[0] - 1)
else:
for i in range(len(d)):
if s - d[i] < a:
b[i] += a - s + d[i] - 1
if d[i] >= a:
b[i] += d[i] - a + 1
print (*b) | Title: Polycarpus' Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has *n* dice *d*1,<=*d*2,<=...,<=*d**n*. The *i*-th dice shows numbers from 1 to *d**i*. Polycarp rolled all the dice and the sum of numbers they showed is *A*. Agrippina didn't see which dice showed what numb... | ```python
n, a = map(int, input().split())
d = list(map(int, input().split()))
b = [0 for i in d]
s = sum (d)
if n == 1:
print (d[0] - 1)
else:
for i in range(len(d)):
if s - d[i] < a:
b[i] += a - s + d[i] - 1
if d[i] >= a:
b[i] += d[i] - a + 1
print (*b)
... | 0 | |
985 | A | Chess Placing | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | You are given a chessboard of size 1<=×<=*n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW".
Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to .
In one step you can move... | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100, *n* is even) — the size of the chessboard.
The second line of the input contains integer numbers (1<=≤<=*p**i*<=≤<=*n*) — initial positions of the pieces. It is guaranteed that all the positions are distinct. | Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color. | [
"6\n1 2 6\n",
"10\n1 2 3 4 5\n"
] | [
"2\n",
"10\n"
] | In the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3.
In the second example the possible strategy is to move... | 0 | [
{
"input": "6\n1 2 6",
"output": "2"
},
{
"input": "10\n1 2 3 4 5",
"output": "10"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "100\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 ... | 1,655,123,351 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | n=int(input())
num=list(map(int,input().split()))
even,odd=0,0
for i in range(n//2):
if(num[i]%2==0):
even+=1
else:
odd+=1
if(even==0 or odd==0):
print(0)
else:
ans1,ans2=0,0
for i in range(n//2):
x=num[i]
ans1+=abs(x-2*(i+1))
ans2+=abs(x-2*(i+1)+1)
print(min(ans1,ans2)) | Title: Chess Placing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a chessboard of size 1<=×<=*n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW".
Some cells of the board are occupied by the chess pieces. Each cell contains no more than... | ```python
n=int(input())
num=list(map(int,input().split()))
even,odd=0,0
for i in range(n//2):
if(num[i]%2==0):
even+=1
else:
odd+=1
if(even==0 or odd==0):
print(0)
else:
ans1,ans2=0,0
for i in range(n//2):
x=num[i]
ans1+=abs(x-2*(i+1))
ans2+=abs(x-2*(i+1)+1)
print(min(ans1,ans2))
``` | 0 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,695,610,462 | 2,147,483,647 | PyPy 3 | OK | TESTS | 15 | 93 | 0 | a, b, c = map(int, input().split())
s = 0
for i in range(1, c + 1):
s += i * a
if s - b < 0:
print(0)
else:
print(s - b) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
a, b, c = map(int, input().split())
s = 0
for i in range(1, c + 1):
s += i * a
if s - b < 0:
print(0)
else:
print(s - b)
``` | 3 | |
129 | B | Students and Shoelaces | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the f... | The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*... | Print the single number — the number of groups of students that will be kicked out from the club. | [
"3 3\n1 2\n2 3\n3 1\n",
"6 3\n1 2\n2 3\n3 4\n",
"6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two ... | 1,000 | [
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "0"
},
{
"input": "6 3\n1 2\n2 3\n3 4",
"output": "2"
},
{
"input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4",
"output": "1"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "0"
},
... | 1,604,234,906 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 49 | 218 | 819,200 | n, m = map(int, input().split(" "))
adj_list = [set() for i in range(n + 1)]
adj_count = [0] * (n + 1)
for i in range(m):
a, b = map(int, input().split(" "))
adj_list[a].add(b)
adj_count[a] += 1
adj_list[b].add(a)
adj_count[b] += 1
count = 0
while True:
r = []
for i in rang... | Title: Students and Shoelaces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifica... | ```python
n, m = map(int, input().split(" "))
adj_list = [set() for i in range(n + 1)]
adj_count = [0] * (n + 1)
for i in range(m):
a, b = map(int, input().split(" "))
adj_list[a].add(b)
adj_count[a] += 1
adj_list[b].add(a)
adj_count[b] += 1
count = 0
while True:
r = []
for... | 0 | |
478 | B | Random Teams | PROGRAMMING | 1,300 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that coul... | The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively. | The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. | [
"5 1\n",
"3 2\n",
"6 3\n"
] | [
"10 10\n",
"1 1\n",
"3 6\n"
] | In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
... | 1,000 | [
{
"input": "5 1",
"output": "10 10"
},
{
"input": "3 2",
"output": "1 1"
},
{
"input": "6 3",
"output": "3 6"
},
{
"input": "5 3",
"output": "2 3"
},
{
"input": "10 2",
"output": "20 36"
},
{
"input": "10 6",
"output": "4 10"
},
{
"input": ... | 1,698,067,083 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 62 | 0 | def c(n):return ((n-1)*n)//2
n,m=map(int, input().split())
h=(n+m-1)//m
print(c(h)*(m+n-h*m)+c(h-1)*(h*m-n),c(n-m+1)) | Title: Random Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is ... | ```python
def c(n):return ((n-1)*n)//2
n,m=map(int, input().split())
h=(n+m-1)//m
print(c(h)*(m+n-h*m)+c(h-1)*(h*m-n),c(n-m+1))
``` | 3 | |
834 | B | The Festive Evening | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom... | Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26).
In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest. | Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"5 1\nAABBB\n",
"5 1\nABABB\n"
] | [
"NO\n",
"YES\n"
] | In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the secon... | 1,000 | [
{
"input": "5 1\nAABBB",
"output": "NO"
},
{
"input": "5 1\nABABB",
"output": "YES"
},
{
"input": "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "NO"
},
{
"input": "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA",
"output": "YES"
},
{
"input": "5 2\nABACA",
"output": "NO"
... | 1,501,727,202 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 46 | 4,608,000 | def main ():
n, k = [int(n) for n in input().split()]
S = input();
doors = {}
for i, s in enumerate(S):
doors[s] = i
activeDoors = set();
for i, s in enumerate(S):
if doors[s] == i:
activeDoors.remove(s);
else:
activeDoors.add(s);
if(len(activeDoors) > k):
return "YES... | Title: The Festive Evening
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here... | ```python
def main ():
n, k = [int(n) for n in input().split()]
S = input();
doors = {}
for i, s in enumerate(S):
doors[s] = i
activeDoors = set();
for i, s in enumerate(S):
if doors[s] == i:
activeDoors.remove(s);
else:
activeDoors.add(s);
if(len(activeDoors) > k):
r... | -1 | |
362 | B | Petya and Staircases | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.
No... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty s... | Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO". | [
"10 5\n2 4 8 3 6\n",
"10 5\n2 4 5 7 9\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "10 5\n2 4 8 3 6",
"output": "NO"
},
{
"input": "10 5\n2 4 5 7 9",
"output": "YES"
},
{
"input": "10 9\n2 3 4 5 6 7 8 9 10",
"output": "NO"
},
{
"input": "5 2\n4 5",
"output": "NO"
},
{
"input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37",
"outp... | 1,642,576,213 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 93 | 2,150,400 | from genericpath import isdir
from traceback import print_tb
n,m=map(int,input().split())
d=sorted([int(x) for x in input().split()])
def isDirty(n: int)->bool:
if (n in d):
return True
else:
return False
def solve(n: int) -> str:
current=0
for i in range(n):
if... | Title: Petya and Staircases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump o... | ```python
from genericpath import isdir
from traceback import print_tb
n,m=map(int,input().split())
d=sorted([int(x) for x in input().split()])
def isDirty(n: int)->bool:
if (n in d):
return True
else:
return False
def solve(n: int) -> str:
current=0
for i in range(n):
... | 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.