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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,599,897,806 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 280 | 0 | from math import gcd
j=0
a,b,c=map(int,input().split())
while c!=0:
c-=gcd(a,c)
j+=1
if c!=0:
c-=gcd(b,c)
j+=1
if j%2==0:
print(1)
else:
print(0) | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
from math import gcd
j=0
a,b,c=map(int,input().split())
while c!=0:
c-=gcd(a,c)
j+=1
if c!=0:
c-=gcd(b,c)
j+=1
if j%2==0:
print(1)
else:
print(0)
``` | 3 | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,651,953,193 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 122 | 0 | s, t = input(), input()
moves = 0
for i in range(len(t)):
c = t[i]
if c == s[moves]:
moves = moves + 1
print(moves + 1) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
s, t = input(), input()
moves = 0
for i in range(len(t)):
c = t[i]
if c == s[moves]:
moves = moves + 1
print(moves + 1)
``` | 3 | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,611,304,855 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n,m=map(int,input().split());
a=list(map(lambda x: -1*int(x),input().split()));
a.sort();
sum=0;
for i in range(m):
if(a[i]>0):
break;
sum=sum+a[i];
print(-1*sum);
# 6 6
# 756 -611 251 -66 572 -818
| Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
n,m=map(int,input().split());
a=list(map(lambda x: -1*int(x),input().split()));
a.sort();
sum=0;
for i in range(m):
if(a[i]>0):
break;
sum=sum+a[i];
print(-1*sum);
# 6 6
# 756 -611 251 -66 572 -818
``` | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible inte... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=<=105) — the size of the array *a* and the number of subsegments you have to split the array to.
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=≤<=<=*a**i*<=≤<=<=109). | Print single integer — the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments. | [
"5 2\n1 2 3 4 5\n",
"5 1\n-4 -5 -3 -2 -1\n"
] | [
"5\n",
"-5\n"
] | A subsegment [*l*, *r*] (*l* ≤ *r*) of array *a* is the sequence *a*<sub class="lower-index">*l*</sub>, *a*<sub class="lower-index">*l* + 1</sub>, ..., *a*<sub class="lower-index">*r*</sub>.
Splitting of array *a* of *n* elements into *k* subsegments [*l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index... | 0 | [
{
"input": "5 2\n1 2 3 4 5",
"output": "5"
},
{
"input": "5 1\n-4 -5 -3 -2 -1",
"output": "-5"
},
{
"input": "10 2\n10 9 1 -9 -7 -9 3 8 -10 5",
"output": "10"
},
{
"input": "10 4\n-8 -1 2 -3 9 -8 4 -3 5 9",
"output": "9"
},
{
"input": "1 1\n504262064",
"output... | 1,508,113,170 | 870 | Python 3 | WRONG_ANSWER | TESTS | 9 | 93 | 8,396,800 | read = lambda: tuple(map(int, input().split()))
n, k = read()
nums = read()
if k == 1:
print(min(nums))
else:
print(max(nums))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and ... | ```python
read = lambda: tuple(map(int, input().split()))
n, k = read()
nums = read()
if k == 1:
print(min(nums))
else:
print(max(nums))
``` | 0 | |
243 | E | Matrix | PROGRAMMING | 3,000 | [
"data structures"
] | null | null | Let's consider an *n*<=×<=*n* square matrix, consisting of digits one and zero.
We'll consider a matrix good, if it meets the following condition: in each row of the matrix all ones go in one group. That is, each row of the matrix looks like that 00...0011...1100...00 (or simply consists of zeroes if it has no ones).
... | The first line contains integer *n* (1<=≤<=*n*<=≤<=500) — the size of matrix *a*.
Each of *n* following lines contains *n* characters "0" and "1" — matrix *a*. Note that the characters are written without separators. | Print "YES" in the first line, if you can rearrange the matrix columns so as to get a good matrix *b*. In the next *n* lines print the good matrix *b*. If there are multiple answers, you are allowed to print any of them.
If it is impossible to get a good matrix, print "NO". | [
"6\n100010\n110110\n011001\n010010\n000100\n011001\n",
"3\n110\n101\n011\n"
] | [
"YES\n011000\n111100\n000111\n001100\n100000\n000111\n",
"NO\n"
] | none | 2,500 | [] | 1,584,958,351 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 218 | 512,000 | from collections import deque
class IsNotC1P(Exception):
"""The given instance does not have the all consecutive ones property"""
pass
P_shape = 0
Q_shape = 1
L_shape = 2
EMPTY = 0
FULL = 1
PARTIAL = 2
# automaton is used for pattern recognition when reducing a Q node
# -1 represents the ... | Title: Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider an *n*<=×<=*n* square matrix, consisting of digits one and zero.
We'll consider a matrix good, if it meets the following condition: in each row of the matrix all ones go in one group. That is, each row of the mat... | ```python
from collections import deque
class IsNotC1P(Exception):
"""The given instance does not have the all consecutive ones property"""
pass
P_shape = 0
Q_shape = 1
L_shape = 2
EMPTY = 0
FULL = 1
PARTIAL = 2
# automaton is used for pattern recognition when reducing a Q node
# -1 repre... | -1 | |
205 | A | Little Elephant and Rozdil | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider t... | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | [
"2\n7 4\n",
"7\n7 4 47 100 4 9 12\n"
] | [
"2\n",
"Still Rozdil\n"
] | In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling t... | 500 | [
{
"input": "2\n7 4",
"output": "2"
},
{
"input": "7\n7 4 47 100 4 9 12",
"output": "Still Rozdil"
},
{
"input": "1\n47",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "Still Rozdil"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "7"
},
{
... | 1,561,724,273 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 216 | 0 | n=int(input())
A=[int(x) for x in input().split()]
B=[x for x in range(n)]
C=sorted(zip(A,B))
if C[0][0]==C[1][0]:
print("Still Rozdil")
else:
print(C[0][1]+1) | Title: Little Elephant and Rozdil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elepha... | ```python
n=int(input())
A=[int(x) for x in input().split()]
B=[x for x in range(n)]
C=sorted(zip(A,B))
if C[0][0]==C[1][0]:
print("Still Rozdil")
else:
print(C[0][1]+1)
``` | -1 | |
873 | D | Merge Sort | PROGRAMMING | 1,800 | [
"constructive algorithms",
"divide and conquer"
] | null | null | Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows:
1. If the segment [*l*,<=*r*) is already sorted in non-descending order (that is, for any *i* such that *l*<=≤<=*i*<=<<=*r*<=-<=1 *a*[*i*]<=≤<=*a*[*i*<=+... | The first line contains two numbers *n* and *k* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=200000) — the size of a desired permutation and the number of *mergesort* calls required to sort it. | If a permutation of size *n* such that there will be exactly *k* calls of *mergesort* while sorting it doesn't exist, output <=-<=1. Otherwise output *n* integer numbers *a*[0],<=*a*[1],<=...,<=*a*[*n*<=-<=1] — the elements of a permutation that would meet the required conditions. If there are multiple answers, print a... | [
"3 3\n",
"4 1\n",
"5 6\n"
] | [
"2 1 3 ",
"1 2 3 4 ",
"-1\n"
] | none | 0 | [
{
"input": "3 3",
"output": "2 1 3 "
},
{
"input": "4 1",
"output": "1 2 3 4 "
},
{
"input": "5 6",
"output": "-1"
},
{
"input": "100 100",
"output": "-1"
},
{
"input": "10000 10001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27... | 1,645,782,962 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 307,200 | n, k = [int(i) for i in input().split(' ')]
test = [None] * 100010;
def unsort(l, r):
global k;
if (k == 1 or l + 1 == r):
return;
k -= 2;
mid = int((l + r) >> 1);
test[mid], test[mid - 1] = test[mid - 1], test[mid];
unsort(l,mid);
unsort(mid,r);
if (k % 2 == 0):
... | Title: Merge Sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows:
1. If the segment [*l*,<=*r*) is already sorted in non-desce... | ```python
n, k = [int(i) for i in input().split(' ')]
test = [None] * 100010;
def unsort(l, r):
global k;
if (k == 1 or l + 1 == r):
return;
k -= 2;
mid = int((l + r) >> 1);
test[mid], test[mid - 1] = test[mid - 1], test[mid];
unsort(l,mid);
unsort(mid,r);
if (k % 2 ==... | 0 | |
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,622,742,129 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 0 | def fun(ls):
prv=None
count3=0
rest=0
count0=0
for i,val in enumerate(ls):
if(val==3):
count3+=1
else:
if((prv==1 and val==2 ) or (prv==2 and val==1 )):
if(count3%2==0):
rest+=0
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
def fun(ls):
prv=None
count3=0
rest=0
count0=0
for i,val in enumerate(ls):
if(val==3):
count3+=1
else:
if((prv==1 and val==2 ) or (prv==2 and val==1 )):
if(count3%2==0):
rest+=0
else:
... | 0 | |
609 | A | USB Flash Drives | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. | The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabyt... | Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. | [
"3\n5\n2\n1\n3\n",
"3\n6\n2\n3\n2\n",
"2\n5\n5\n10\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | 0 | [
{
"input": "3\n5\n2\n1\n3",
"output": "2"
},
{
"input": "3\n6\n2\n3\n2",
"output": "3"
},
{
"input": "2\n5\n5\n10",
"output": "1"
},
{
"input": "5\n16\n8\n1\n3\n4\n9",
"output": "2"
},
{
"input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100",
"output": "2"
... | 1,677,322,590 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | import bisect as bi
from sys import stdin
input = stdin.readline
def main():
n = int(input())
m = int(input())
l = []
for _ in range(n):
q = int(input())
l.append(q)
l.sort(reverse = True)
w = 0
for i in range(n):
m -= l[i]
w += 1
if m <= 0:
print(w)
break
... | Title: USB Flash Drives
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of... | ```python
import bisect as bi
from sys import stdin
input = stdin.readline
def main():
n = int(input())
m = int(input())
l = []
for _ in range(n):
q = int(input())
l.append(q)
l.sort(reverse = True)
w = 0
for i in range(n):
m -= l[i]
w += 1
if m <= 0:
print(w)
bre... | 3 | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,618,426,645 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 33 | 154 | 0 | # def islucky(n):
# if(len(n)%2!=0):
# return False
# n4=0
# n7=0
# for c in n:
# if c=='4':
# n4+=1
# elif c=='7':
# n7+=1
# else:
# return False
# if n4==n7:
# return True
# else:
# return False
... | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
# def islucky(n):
# if(len(n)%2!=0):
# return False
# n4=0
# n7=0
# for c in n:
# if c=='4':
# n4+=1
# elif c=='7':
# n7+=1
# else:
# return False
# if n4==n7:
# return True
# else:
# ret... | 0 | |
246 | A | Buggy Sorting | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a**n* in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. ... | You've got a single integer *n* (1<=≤<=*n*<=≤<=50) — the size of the sorted array. | Print *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the counter-example, for which Valera's algorithm won't work correctly. If the counter-example that meets the described conditions is impossible to give, print -1.
If there are several counter-examples, consisting of *n* numbers, yo... | [
"1\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "3 2 1 "
},
{
"input": "4",
"output": "4 3 2 1 "
},
{
"input": "5",
"output": "5 4 3 2 1 "
},
{
"input": "6",
"output": "6 5 4 3 2 1 "
},
{
"input... | 1,636,453,031 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 4,198,400 | n = int( input())
if n >= 3:
nums = [n]
for i in range (2, n):
nums.append(i)
nums.append(1)
print(nums)
else:
print(-1) | Title: Buggy Sorting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a*... | ```python
n = int( input())
if n >= 3:
nums = [n]
for i in range (2, n):
nums.append(i)
nums.append(1)
print(nums)
else:
print(-1)
``` | 0 | |
789 | B | Masha and geometric depression | PROGRAMMING | 1,700 | [
"brute force",
"implementation",
"math"
] | null | null | Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression *b* defined by two integers *b*1 and *q*. Remind that a geometric progression is a sequence of integers *b*1,<=*b*2,<=*b*3,<=..., where for each *i*<=><=1 the respective term satisfi... | The first line of input contains four integers *b*1, *q*, *l*, *m* (-109<=≤<=*b*1,<=*q*<=≤<=109, 1<=≤<=*l*<=≤<=109, 1<=≤<=*m*<=≤<=105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second lin... | Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. | [
"3 2 30 4\n6 14 25 48\n",
"123 1 2143435 4\n123 11 -5453 141245\n",
"123 1 2143435 4\n54343 -13 6 124\n"
] | [
"3",
"0",
"inf"
] | In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed *l* by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.... | 1,000 | [
{
"input": "3 2 30 4\n6 14 25 48",
"output": "3"
},
{
"input": "123 1 2143435 4\n123 11 -5453 141245",
"output": "0"
},
{
"input": "123 1 2143435 4\n54343 -13 6 124",
"output": "inf"
},
{
"input": "3 2 25 2\n379195692 -69874783",
"output": "4"
},
{
"input": "3 2 3... | 1,490,818,285 | 2,147,483,647 | Python 3 | OK | TESTS | 116 | 93 | 12,902,400 | b, q, l, m = list(map(int, input().split()))
a = set(list(map(int, input().split())))
ans = 0
boo = False
i = 0
while (i < 34) and (abs(b) <= l):
if (b not in a):
ans += 1
if i > 31:
boo = True
b *= q
i += 1
if boo:
print('inf')
else:
print(ans) | Title: Masha and geometric depression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression *b* defined by two integers *b*1 and *q*. Remind that a geometric pro... | ```python
b, q, l, m = list(map(int, input().split()))
a = set(list(map(int, input().split())))
ans = 0
boo = False
i = 0
while (i < 34) and (abs(b) <= l):
if (b not in a):
ans += 1
if i > 31:
boo = True
b *= q
i += 1
if boo:
print('inf')
else:
print(ans)
`... | 3 | |
1,000 | B | Light It Up | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunate... | First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed progra... | Print the only integer — maximum possible total time when the lamp is lit. | [
"3 10\n4 6 7\n",
"2 12\n1 10\n",
"2 7\n3 4\n"
] | [
"8\n",
"9\n",
"6\n"
] | In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal so... | 0 | [
{
"input": "3 10\n4 6 7",
"output": "8"
},
{
"input": "2 12\n1 10",
"output": "9"
},
{
"input": "2 7\n3 4",
"output": "6"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "5 10\n1 3 5 6 8",
"output": "6"
},
{
"input": "7 1000000000\n1 10001 10011 20... | 1,635,300,150 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 4,505,600 | n,M=map(int,input().split())
a=[0]
adjust=[]
s=input().split()
for i in range(n):
a.append(int(s[i]))
a.append(int(M))
#print(a)
lit_time_initial=0
if len(a)%2!=0:
for i in range(0,len(a)-1,2):
lit_time_initial+=int(a[i+1])-int(a[i])
else:
for i in range(0,len(a),2):
lit_time... | Title: Light It Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows y... | ```python
n,M=map(int,input().split())
a=[0]
adjust=[]
s=input().split()
for i in range(n):
a.append(int(s[i]))
a.append(int(M))
#print(a)
lit_time_initial=0
if len(a)%2!=0:
for i in range(0,len(a)-1,2):
lit_time_initial+=int(a[i+1])-int(a[i])
else:
for i in range(0,len(a),2):
... | 0 | |
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,667,042,171 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | a=input()
f=False
h=False
a1=a[:len(a)//2]
a2=a[len(a)//2:][::-1]
for i in range(len(a)//2):
if f==False and a1[i]!=a2[i]:
f=True
elif f==True and a1[i]!=a2[i]:
h=True
break
if h:
print('NO')
elif f and not h:
print('YES') | 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
a=input()
f=False
h=False
a1=a[:len(a)//2]
a2=a[len(a)//2:][::-1]
for i in range(len(a)//2):
if f==False and a1[i]!=a2[i]:
f=True
elif f==True and a1[i]!=a2[i]:
h=True
break
if h:
print('NO')
elif f and not h:
print('YES')
``` | 0 | |
474 | A | Keyboard | PROGRAMMING | 900 | [
"implementation"
] | null | null | Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That mean... | First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right).
Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain ... | Print a line that contains the original message. | [
"R\ns;;upimrrfod;pbr\n"
] | [
"allyouneedislove\n"
] | none | 500 | [
{
"input": "R\ns;;upimrrfod;pbr",
"output": "allyouneedislove"
},
{
"input": "R\nwertyuiop;lkjhgfdsxcvbnm,.",
"output": "qwertyuiolkjhgfdsazxcvbnm,"
},
{
"input": "L\nzxcvbnm,kjhgfdsaqwertyuio",
"output": "xcvbnm,.lkjhgfdswertyuiop"
},
{
"input": "R\nbubbuduppudup",
"outp... | 1,697,117,843 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 62 | 0 | string = "qwertyuiopasdfghjkl;zxcvbnm,./"
char = input()
inputstring = input()
answerstring = ""
addition = 1 if char == 'L' else -1
for x in inputstring :
num = string.index(x)+addition
answerstring += string[num]
print(answerstring) | Title: Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately.... | ```python
string = "qwertyuiopasdfghjkl;zxcvbnm,./"
char = input()
inputstring = input()
answerstring = ""
addition = 1 if char == 'L' else -1
for x in inputstring :
num = string.index(x)+addition
answerstring += string[num]
print(answerstring)
``` | 3 | |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,698,383,100 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n, m = map(int, input().split())
arr = list(map(int, input().split()))
# Step 1: Count unique
# Step 2: Create the dict
# Step 3: Loop through the array only ones
Unique = len(set(arr))
Data = {}
for i in set(arr):
Data[i] = arr.count(i)
Data[arr[0]] -= 1
if Data[arr[0]] == 0:
Unique -= 1
print(Uniq... | Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
n, m = map(int, input().split())
arr = list(map(int, input().split()))
# Step 1: Count unique
# Step 2: Create the dict
# Step 3: Loop through the array only ones
Unique = len(set(arr))
Data = {}
for i in set(arr):
Data[i] = arr.count(i)
Data[arr[0]] -= 1
if Data[arr[0]] == 0:
Unique -= 1
... | 0 | |
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,526,322,736 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 156 | 7,065,600 | x=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
a,b=map(int,input().split())
if b in x and x.index(b)-x.index(a)==1:
print('YES')
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
x=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
a,b=map(int,input().split())
if b in x and x.index(b)-x.index(a)==1:
print('YES')
else:
print('NO')
``` | 3.947839 |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,697,132,204 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 62 | 0 | s=input()
l=[]
for i in s:
if i.isdigit():
l.append(i)
l.sort()
print('+'.join(l)) | Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
s=input()
l=[]
for i in s:
if i.isdigit():
l.append(i)
l.sort()
print('+'.join(l))
``` | 3 | |
754 | A | Lesha and array splitting | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | One spring day on his way to university Lesha found an array *A*. Lesha likes to split arrays into several parts. This time Lesha decided to split the array *A* into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array *A*.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=103<=≤<=*a**i*<=≤<=103) — the elements of the array *A*. | If it is not possible to split the array *A* and satisfy all the constraints, print single line containing "NO" (without quotes).
Otherwise in the first line print "YES" (without quotes). In the next line print single integer *k* — the number of new arrays. In each of the next *k* lines print two integers *l**i* and *... | [
"3\n1 2 -3\n",
"8\n9 -12 3 4 -4 -10 7 3\n",
"1\n0\n",
"4\n1 2 3 -5\n"
] | [
"YES\n2\n1 2\n3 3\n",
"YES\n2\n1 2\n3 8\n",
"NO\n",
"YES\n4\n1 1\n2 2\n3 3\n4 4\n"
] | none | 500 | [
{
"input": "3\n1 2 -3",
"output": "YES\n3\n1 1\n2 2\n3 3"
},
{
"input": "8\n9 -12 3 4 -4 -10 7 3",
"output": "YES\n8\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8"
},
{
"input": "1\n0",
"output": "NO"
},
{
"input": "4\n1 2 3 -5",
"output": "YES\n4\n1 1\n2 2\n3 3\n4 4"
},
{
... | 1,636,363,181 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 4,505,600 | n = int(input())
list1 = list(map(int,input().split()))
count = 0
count = 0
g = g.split(' ')
for i in range(len(g)-1):
if g[i]+g[i+1] !=0:
count+=1
if count == 0:
print('NO')
else:
print('YES')
print(count+1)
for i in range(1,count+2):
print(i,i) | Title: Lesha and array splitting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One spring day on his way to university Lesha found an array *A*. Lesha likes to split arrays into several parts. This time Lesha decided to split the array *A* into several, possibly one, new arrays so that t... | ```python
n = int(input())
list1 = list(map(int,input().split()))
count = 0
count = 0
g = g.split(' ')
for i in range(len(g)-1):
if g[i]+g[i+1] !=0:
count+=1
if count == 0:
print('NO')
else:
print('YES')
print(count+1)
for i in range(1,count+2):
print(i,i)
``` | -1 | |
812 | C | Sagheer and Nubian Market | PROGRAMMING | 1,500 | [
"binary search",
"sortings"
] | null | null | On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. The *i*-th item has base cost *a**i* Egyptian pounds. If Sagheer buys *k* items with indices *x*1,<=*x*2,<=...,<... | The first line contains two integers *n* and *S* (1<=≤<=*n*<=≤<=105 and 1<=≤<=*S*<=≤<=109) — the number of souvenirs in the market and Sagheer's budget.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the base costs of the souvenirs. | On a single line, print two integers *k*, *T* — the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these *k* souvenirs. | [
"3 11\n2 3 5\n",
"4 100\n1 2 5 6\n",
"1 7\n7\n"
] | [
"2 11\n",
"4 54\n",
"0 0\n"
] | In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.
In the second example, he can buy all items as they will cost him [5, 10, 17, 22].
In the... | 1,500 | [
{
"input": "3 11\n2 3 5",
"output": "2 11"
},
{
"input": "4 100\n1 2 5 6",
"output": "4 54"
},
{
"input": "1 7\n7",
"output": "0 0"
},
{
"input": "1 7\n5",
"output": "1 6"
},
{
"input": "1 1\n1",
"output": "0 0"
},
{
"input": "4 33\n4 3 2 1",
"outp... | 1,678,799,520 | 2,147,483,647 | PyPy 3 | OK | TESTS | 57 | 358 | 15,872,000 | n,s = map(int,input().split())
a = list(map(int,input().split()))
def find(k):
# ans = 0
b = [(i+1)*k+a[i] for i in range(n)]
b = sorted(b)
return sum(b[:k])
l,r = 0,n
ans = 0
while l<r:
md = (l+r+1)//2
ans = find(md)
# print(ans)
if ans<=s:
l = md
else:
... | Title: Sagheer and Nubian Market
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. T... | ```python
n,s = map(int,input().split())
a = list(map(int,input().split()))
def find(k):
# ans = 0
b = [(i+1)*k+a[i] for i in range(n)]
b = sorted(b)
return sum(b[:k])
l,r = 0,n
ans = 0
while l<r:
md = (l+r+1)//2
ans = find(md)
# print(ans)
if ans<=s:
l = md
... | 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,668,888,357 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | n, m = [int(i) for i in input().split()]
k = [int(i) for i in input().split()]
a = []
for i in k:
if i +m <= 5:
a.append(i)
if len(a) < 3:
print(0)
else:
print(len(a)//3) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n, m = [int(i) for i in input().split()]
k = [int(i) for i in input().split()]
a = []
for i in k:
if i +m <= 5:
a.append(i)
if len(a) < 3:
print(0)
else:
print(len(a)//3)
``` | 3 | |
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first... | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999... | 1,461,759,462 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 592 | 8,499,200 | '''
Created on Apr 27, 2016
Gmail : [email protected]
@author: Md. Rezwanul Haque
'''
'''
Created on Apr 27, 2016
Gmail : [email protected]
@author: Md. Rezwanul Haque
'''
import sys
f = sys.stdin
# f = open("input.txt", "r")
y, k, n = map(int, f.readline().strip().split())
if y >= n:
first = -1
e... | Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* pota... | ```python
'''
Created on Apr 27, 2016
Gmail : [email protected]
@author: Md. Rezwanul Haque
'''
'''
Created on Apr 27, 2016
Gmail : [email protected]
@author: Md. Rezwanul Haque
'''
import sys
f = sys.stdin
# f = open("input.txt", "r")
y, k, n = map(int, f.readline().strip().split())
if y >= n:
fir... | 3 | |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,627,756,606 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 6,963,200 | resheto = [0] * 999
resheto[0] = 1
resheto[1] = 1
for i in range(2, len(resheto)):
if resheto[i] == 0:
for j in range(i*2, len(resheto), i):
resheto[j] += 1
n = int(input())
prosto = []
for i in range(n):
if resheto[i] == 0:
prosto.append(i)
for i in prosto:
if... | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
... | ```python
resheto = [0] * 999
resheto[0] = 1
resheto[1] = 1
for i in range(2, len(resheto)):
if resheto[i] == 0:
for j in range(i*2, len(resheto), i):
resheto[j] += 1
n = int(input())
prosto = []
for i in range(n):
if resheto[i] == 0:
prosto.append(i)
for i in prost... | 0 | |
965 | D | Single-use Stones | PROGRAMMING | 1,900 | [
"binary search",
"flows",
"greedy",
"two pointers"
] | null | null | A lot of frogs want to cross a river. A river is $w$ units width, but frogs can only jump $l$ units long, where $l < w$. Frogs can also jump on lengths shorter than $l$. but can't jump longer. Hopefully, there are some stones in the river to help them.
The stones are located at integer distances from the banks. The... | The first line contains two integers $w$ and $l$ ($1 \le l < w \le 10^5$) — the width of the river and the maximum length of a frog's jump.
The second line contains $w - 1$ integers $a_1, a_2, \ldots, a_{w-1}$ ($0 \le a_i \le 10^4$), where $a_i$ is the number of stones at the distance $i$ from the bank the frogs ar... | Print a single integer — the maximum number of frogs that can cross the river. | [
"10 5\n0 0 1 0 2 0 0 1 0\n",
"10 3\n1 1 1 1 2 1 1 1 1\n"
] | [
"3\n",
"3\n"
] | In the first sample two frogs can use the different stones at the distance $5$, and one frog can use the stones at the distances $3$ and then $8$.
In the second sample although there are two stones at the distance $5$, that does not help. The three paths are: $0 \to 3 \to 6 \to 9 \to 10$, $0 \to 2 \to 5 \to 8 \to 10$,... | 2,000 | [
{
"input": "10 5\n0 0 1 0 2 0 0 1 0",
"output": "3"
},
{
"input": "10 3\n1 1 1 1 2 1 1 1 1",
"output": "3"
},
{
"input": "2 1\n0",
"output": "0"
},
{
"input": "2 1\n5",
"output": "5"
},
{
"input": "10 4\n0 0 6 2 7 1 6 4 0",
"output": "8"
},
{
"input": ... | 1,524,865,683 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 217 | 16,793,600 | input_string = input().split()
n = int(input_string[0])
l = int(input_string[1])
input_string = input().split()
v = []
for i in range(0, len(input_string)):
v.append(int(input_string[i]))
dp = [0]
for i in range(1, len(v) + 1):
dp.append(dp[i-1] + v[i-1])
ans = 1000000000000000000000000000
for i in range(l, len(dp)):... | Title: Single-use Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A lot of frogs want to cross a river. A river is $w$ units width, but frogs can only jump $l$ units long, where $l < w$. Frogs can also jump on lengths shorter than $l$. but can't jump longer. Hopefully, there are ... | ```python
input_string = input().split()
n = int(input_string[0])
l = int(input_string[1])
input_string = input().split()
v = []
for i in range(0, len(input_string)):
v.append(int(input_string[i]))
dp = [0]
for i in range(1, len(v) + 1):
dp.append(dp[i-1] + v[i-1])
ans = 1000000000000000000000000000
for i in range(l,... | 3 | |
55 | A | Flea travel | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | A. Flea travel | 1 | 256 | A flea is sitting at one of the *n* hassocks, arranged in a circle, at the moment. After minute number *k* the flea jumps through *k*<=-<=1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighboring hassock. You should answer: will the flea visit all the hassocks or not. We assume that ... | The only line contains single integer: 1<=≤<=*n*<=≤<=1000 — number of hassocks. | Output "YES" if all the hassocks will be visited and "NO" otherwise. | [
"1\n",
"3\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "YES"
},
{
"input": "4",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "NO"
},
{
"input": "7",
"output": "NO... | 1,450,134,758 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 93 | 4,403,200 | n, c, k = int(input()), 0, 0
v = [[False] * n for i in range(n)]
while not v[c][k]:
v[c][k] = True
k = (k + 1) % n
c = (c + k) % n
print('YES' if all(any(x) for x in v) else 'NO') | Title: Flea travel
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
A flea is sitting at one of the *n* hassocks, arranged in a circle, at the moment. After minute number *k* the flea jumps through *k*<=-<=1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighbo... | ```python
n, c, k = int(input()), 0, 0
v = [[False] * n for i in range(n)]
while not v[c][k]:
v[c][k] = True
k = (k + 1) % n
c = (c + k) % n
print('YES' if all(any(x) for x in v) else 'NO')
``` | 3.945298 |
903 | G | Yet Another Maxflow Problem | PROGRAMMING | 2,700 | [
"data structures",
"flows",
"graphs"
] | null | null | In this problem you will have to deal with a very special network.
The network consists of two parts: part *A* and part *B*. Each part consists of *n* vertices; *i*-th vertex of part *A* is denoted as *A**i*, and *i*-th vertex of part *B* is denoted as *B**i*.
For each index *i* (1<=≤<=*i*<=<<=*n*) there is a dire... | The first line contains three integer numbers *n*, *m* and *q* (2<=≤<=*n*,<=*m*<=≤<=2·105, 0<=≤<=*q*<=≤<=2·105) — the number of vertices in each part, the number of edges going from *A* to *B* and the number of changes, respectively.
Then *n*<=-<=1 lines follow, *i*-th line contains two integers *x**i* and *y**i* deno... | Firstly, print the maximum flow value in the original network. Then print *q* integers, *i*-th of them must be equal to the maximum flow value after *i*-th change. | [
"4 3 2\n1 2\n3 4\n5 6\n2 2 7\n1 4 8\n4 3 9\n1 100\n2 100\n"
] | [
"9\n14\n14\n"
] | This is the original network in the example: | 0 | [
{
"input": "4 3 2\n1 2\n3 4\n5 6\n2 2 7\n1 4 8\n4 3 9\n1 100\n2 100",
"output": "9\n14\n14"
},
{
"input": "10 10 10\n291546518 199012865\n327731857 137263959\n145140225 631959974\n559674936 815057131\n677050070 949982094\n839693202 160045764\n967872826 489258292\n706535160 594950620\n230389718 27478... | 1,683,662,340 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 62 | 841 | 88,473,600 | import heapq
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def make_graph(n, m):
x, y, s = [0] * (2 * m), [0] * m, [0] * (n + 3)
for i in range(0, 2 * m, 2):
u, v, w = map(int, input().split())
s[u + 2] += 1
x[i], x[i + 1] = u, v
y[i >... | Title: Yet Another Maxflow Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you will have to deal with a very special network.
The network consists of two parts: part *A* and part *B*. Each part consists of *n* vertices; *i*-th vertex of part *A* is denoted as *A**i... | ```python
import heapq
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def make_graph(n, m):
x, y, s = [0] * (2 * m), [0] * m, [0] * (n + 3)
for i in range(0, 2 * m, 2):
u, v, w = map(int, input().split())
s[u + 2] += 1
x[i], x[i + 1] = u, v
... | 3 | |
1,011 | A | Stages | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
There are $n$ stages available. The ro... | The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket.
The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build th... | Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all. | [
"5 3\nxyabd\n",
"7 4\nproblem\n",
"2 2\nab\n",
"12 1\nabaabbaaabbb\n"
] | [
"29",
"34",
"-1",
"1"
] | In the first example, the following rockets satisfy the condition:
- "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$).
Rocket "adx" has the minimal weight, so the answer is $29$.
In the second example, target rocket is "belo". Its weight ... | 500 | [
{
"input": "5 3\nxyabd",
"output": "29"
},
{
"input": "7 4\nproblem",
"output": "34"
},
{
"input": "2 2\nab",
"output": "-1"
},
{
"input": "12 1\nabaabbaaabbb",
"output": "1"
},
{
"input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": ... | 1,533,707,179 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 140 | 0 | n,k = map(int,input().split())
s = input().rstrip()
l = list(s)
sum1 = 0
d = {}
for i in range(26):
d[chr(97 + i)] = i + 1
l.sort()
sum1 += d[l[0]]
count = 1
i,j = 1,0
while (i < len(l)) and (j < i) and count < k:
if d[l[i]] < d[l[j]] + 2:
i += 1
continue
else:
sum1 += d[l[i]]
count +=... | Title: Stages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — conca... | ```python
n,k = map(int,input().split())
s = input().rstrip()
l = list(s)
sum1 = 0
d = {}
for i in range(26):
d[chr(97 + i)] = i + 1
l.sort()
sum1 += d[l[0]]
count = 1
i,j = 1,0
while (i < len(l)) and (j < i) and count < k:
if d[l[i]] < d[l[j]] + 2:
i += 1
continue
else:
sum1 += d[l[i]]
... | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,563,478,354 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 0 | string = input()
up = 0
low = 0
i = 0
while(i<len(string)):
if ord(string[i])>=65 and ord(string[i])<=90:
up+=1
else:
low+=1
i+=1
if up>low:
ok = string.upper()
else:
ok = string.lower()
print(ok) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
string = input()
up = 0
low = 0
i = 0
while(i<len(string)):
if ord(string[i])>=65 and ord(string[i])<=90:
up+=1
else:
low+=1
i+=1
if up>low:
ok = string.upper()
else:
ok = string.lower()
print(ok)
``` | 3.938 |
928 | B | Chat | PROGRAMMING | 1,400 | [
"*special",
"dp"
] | null | null | There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago.
More formal, your message history is a sequence of messages ordered by time sent numbered from 1 to... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=*n*) — the total amount of messages and the number of previous and next messages visible.
The second line features a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=<<=*i*), where *a**i* denotes the *i*-th message link... | Print *n* integers with *i*-th denoting the number of distinct messages you can read starting from message *i* and traversing the links while possible. | [
"6 0\n0 1 1 2 3 2\n",
"10 1\n0 1 0 3 4 5 2 3 7 0\n",
"2 2\n0 1\n"
] | [
"1 2 2 3 3 3 \n",
"2 3 3 4 5 6 6 6 8 2 \n",
"2 2 \n"
] | Consider *i* = 6 in sample case one. You will read message 6, then 2, then 1 and then there will be no link to go.
In the second sample case *i* = 6 gives you messages 5, 6, 7 since *k* = 1, then 4, 5, 6, then 2, 3, 4 and then the link sequence breaks. The number of distinct messages here is equal to 6. | 1,250 | [
{
"input": "6 0\n0 1 1 2 3 2",
"output": "1 2 2 3 3 3 "
},
{
"input": "10 1\n0 1 0 3 4 5 2 3 7 0",
"output": "2 3 3 4 5 6 6 6 8 2 "
},
{
"input": "2 2\n0 1",
"output": "2 2 "
},
{
"input": "1 1\n0",
"output": "1 "
},
{
"input": "5 2\n0 1 2 3 1",
"output": "3 4... | 1,519,502,903 | 16,403 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 8 | 1,000 | 11,673,600 | a,b=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
c=[]
for i in range(a):
s=1
B=[]
k=i
while A[k]!=0:
B.append(k + 1)
if k + 1 - b > 0:
for j in range(k, k - b, -1):
B.append(j)
else:
for j in range(k, 0, -1):... | Title: Chat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago.
More form... | ```python
a,b=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
c=[]
for i in range(a):
s=1
B=[]
k=i
while A[k]!=0:
B.append(k + 1)
if k + 1 - b > 0:
for j in range(k, k - b, -1):
B.append(j)
else:
for j in range(... | 0 | |
978 | A | Remove Duplicates | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. | The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array.
The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array. | In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates.
In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. | [
"6\n1 5 5 1 6 1\n",
"5\n2 4 2 4 4\n",
"5\n6 6 6 6 6\n"
] | [
"3\n5 6 1 \n",
"2\n2 4 \n",
"1\n6 \n"
] | In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$.
In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$.
In the... | 0 | [
{
"input": "6\n1 5 5 1 6 1",
"output": "3\n5 6 1 "
},
{
"input": "5\n2 4 2 4 4",
"output": "2\n2 4 "
},
{
"input": "5\n6 6 6 6 6",
"output": "1\n6 "
},
{
"input": "7\n1 2 3 4 2 2 3",
"output": "4\n1 4 2 3 "
},
{
"input": "9\n100 100 100 99 99 99 100 100 100",
... | 1,697,153,764 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | x = [1, 5, 5, 1, 6, 1]
# get the last insatnce of the number in the list
ans = []
for i in range(len(x) - 1, 0, -1):
if x[i] not in ans:
ans.insert(0, x[i])
else:
continue
print(len(ans))
print(*ans)
| Title: Remove Duplicates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the re... | ```python
x = [1, 5, 5, 1, 6, 1]
# get the last insatnce of the number in the list
ans = []
for i in range(len(x) - 1, 0, -1):
if x[i] not in ans:
ans.insert(0, x[i])
else:
continue
print(len(ans))
print(*ans)
``` | 0 | |
573 | B | Bear and Blocks | PROGRAMMING | 1,600 | [
"binary search",
"data structures",
"dp",
"math"
] | null | null | Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built *n* towers in a row. The *i*-th tower is made of *h**i* identical blocks. For clarification see picture for the first sample.
Limak will repeat the following operation till everything is destroyed.
Block is called inter... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109) — sizes of towers. | Print the number of operations needed to destroy all towers. | [
"6\n2 1 4 6 2 2\n",
"7\n3 3 3 1 3 3 3\n"
] | [
"3\n",
"2\n"
] | The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color. | 1,000 | [
{
"input": "6\n2 1 4 6 2 2",
"output": "3"
},
{
"input": "7\n3 3 3 1 3 3 3",
"output": "2"
},
{
"input": "7\n5128 5672 5805 5452 5882 5567 5032",
"output": "4"
},
{
"input": "10\n1 2 2 3 5 5 5 4 2 1",
"output": "5"
},
{
"input": "14\n20 20 20 20 20 20 3 20 20 20 2... | 1,463,984,004 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 13,824,000 | n = int(input())
heights = [0] + [int(h) for h in input().split(' ')] + [0]
tmp = [0 for i in range(len(heights))]
step = 0
while True:
done = True
for i in range(1, n):
tmp[i] = max(0, min(heights[i - 1], heights[i + 1], heights[i] - 1))
if tmp[i] > 0:
done = False
h... | Title: Bear and Blocks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built *n* towers in a row. The *i*-th tower is made of *h**i* identical blocks. For clarification see picture for the first sa... | ```python
n = int(input())
heights = [0] + [int(h) for h in input().split(' ')] + [0]
tmp = [0 for i in range(len(heights))]
step = 0
while True:
done = True
for i in range(1, n):
tmp[i] = max(0, min(heights[i - 1], heights[i + 1], heights[i] - 1))
if tmp[i] > 0:
done = Fa... | 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,571,157,928 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 108 | 0 | st = input()
strr = st[::-1]
if st.index('h')<st.index('e') and st.index('e')<st.index('l') and strr.index('l')<strr.index('e') and st.index('l')>st.index('o'):
print('YES')
else:
print('NO') | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
st = input()
strr = st[::-1]
if st.index('h')<st.index('e') and st.index('e')<st.index('l') and strr.index('l')<strr.index('e') and st.index('l')>st.index('o'):
print('YES')
else:
print('NO')
``` | 0 |
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* woode... | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal... | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ... | 1,545,310,154 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 20 | 248 | 0 | ro = 0
lc = 0
lo = 0
rc = 0
r = []
l = []
n = int(input())
for i in range(0,n):
l = list(map(int,input().split()))
if l[0] == 1:
lo +=1
else:
lc+=1
if l[1] == 1:
ro+=1
else:
rc+=1
maxl = max(lo,lc)
maxr = max(ro,lc)
print(n-maxl+n-maxr)
| 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
ro = 0
lc = 0
lo = 0
rc = 0
r = []
l = []
n = int(input())
for i in range(0,n):
l = list(map(int,input().split()))
if l[0] == 1:
lo +=1
else:
lc+=1
if l[1] == 1:
ro+=1
else:
rc+=1
maxl = max(lo,lc)
maxr = max(ro,lc)
print(n-maxl+n-maxr)
... | 0 | |
1,006 | E | Military Problem | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | In this problem you will have to help Berland army with organizing their command delivery system.
There are $n$ officers in Berland army. The first officer is the commander of the army, and he does not have any superiors. Every other officer has exactly one direct superior. If officer $a$ is the direct superior of off... | The first line of the input contains two integers $n$ and $q$ ($2 \le n \le 2 \cdot 10^5, 1 \le q \le 2 \cdot 10^5$) — the number of officers in Berland army and the number of queries.
The second line of the input contains $n - 1$ integers $p_2, p_3, \dots, p_n$ ($1 \le p_i < i$), where $p_i$ is the index of the di... | Print $q$ numbers, where the $i$-th number is the officer at the position $k_i$ in the list which describes the order in which officers will receive the command if it starts spreading from officer $u_i$. Print "-1" if the number of officers which receive the command is less than $k_i$.
You should process queries indep... | [
"9 6\n1 1 1 3 5 3 5 7\n3 1\n1 5\n3 4\n7 3\n1 8\n1 9\n"
] | [
"3\n6\n8\n-1\n9\n4\n"
] | none | 0 | [
{
"input": "9 6\n1 1 1 3 5 3 5 7\n3 1\n1 5\n3 4\n7 3\n1 8\n1 9",
"output": "3\n6\n8\n-1\n9\n4"
},
{
"input": "2 1\n1\n1 1",
"output": "1"
},
{
"input": "13 12\n1 1 1 1 1 1 1 1 1 1 1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n... | 1,590,358,131 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
//simple for loop
#define f(n) for(int i=0; i<n; i++)
typedef long long int ll;
typedef vector<ll> vll;
ll inf=numeric_limits<ll>::max();
ll findNumofSUbords(ll v, vector<vll>& adjList, vll& numofSUbords)
{
if (adjList[v].empty())
{
numofSUbord... | Title: Military Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you will have to help Berland army with organizing their command delivery system.
There are $n$ officers in Berland army. The first officer is the commander of the army, and he does not have any superi... | ```python
#include <bits/stdc++.h>
using namespace std;
//simple for loop
#define f(n) for(int i=0; i<n; i++)
typedef long long int ll;
typedef vector<ll> vll;
ll inf=numeric_limits<ll>::max();
ll findNumofSUbords(ll v, vector<vll>& adjList, vll& numofSUbords)
{
if (adjList[v].empty())
{
n... | -1 | |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,688,905,992 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | k, r = map(int, input().split())
shovels = 1
price = k
while price % 10 != 0 and price % 10 != r:
shovels += 1
price = k * shovels
print(shovels) | Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
k, r = map(int, input().split())
shovels = 1
price = k
while price % 10 != 0 and price % 10 != r:
shovels += 1
price = k * shovels
print(shovels)
``` | 3 | |
199 | A | Hexadecimal's theorem | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"implementation",
"number theory"
] | null | null | Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F... | The input contains of a single integer *n* (0<=≤<=*n*<=<<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number. | Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them. | [
"3\n",
"13\n"
] | [
"1 1 1\n",
"2 3 8\n"
] | none | 500 | [
{
"input": "3",
"output": "1 1 1"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input... | 1,637,301,308 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 92 | 0 | n = int(input())
if n == 0:
print("0 0 0")
elif n == 1:
print("1 0 0")
elif n == 2:
print("1 1 0")
elif n == 3:
print("1 1 1")
else:
s = [0, 1];c = 1;i = 2
while (c != n):
s.append(c)
c = s[i - 1] + s[i]
i += 1
print(s[i - 1], s[i - 3], s[i - 4]) | Title: Hexadecimal's theorem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let'... | ```python
n = int(input())
if n == 0:
print("0 0 0")
elif n == 1:
print("1 0 0")
elif n == 2:
print("1 1 0")
elif n == 3:
print("1 1 1")
else:
s = [0, 1];c = 1;i = 2
while (c != n):
s.append(c)
c = s[i - 1] + s[i]
i += 1
print(s[i - 1], s[i - 3], s[i - ... | 3 | |
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul... | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter t... | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input":... | 1,586,485,532 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 218 | 307,200 | x=input()
y=input()
z=input()
if (x=="A>B" or x=="B<A"):
if (y=="B>C" or y=="C<B"):
if (z=="C<A" or z=="A>C"):
print("CBA")
else:
print("Impossible")
else:
if (z=="C<A" or z=="A>C"):
print("BCA")
else:
print("BAC")
els... | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ... | ```python
x=input()
y=input()
z=input()
if (x=="A>B" or x=="B<A"):
if (y=="B>C" or y=="C<B"):
if (z=="C<A" or z=="A>C"):
print("CBA")
else:
print("Impossible")
else:
if (z=="C<A" or z=="A>C"):
print("BCA")
else:
print("... | 0 |
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). | Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only th... | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
... | 1,558,780,890 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 109 | 0 | n, m = map(int, input().split())
a = [0] * 5
b = [0] * 5
for i in range(5):
a[i] = (n-i)//5
b[i] = (m-i)//5
ans = 0
for i in range(5):
for j in range(5):
if i + j==5 or i + j == 0:
ans += a[i] * b[j]
print(ans) | Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers ... | ```python
n, m = map(int, input().split())
a = [0] * 5
b = [0] * 5
for i in range(5):
a[i] = (n-i)//5
b[i] = (m-i)//5
ans = 0
for i in range(5):
for j in range(5):
if i + j==5 or i + j == 0:
ans += a[i] * b[j]
print(ans)
``` | 0 | |
305 | B | Continued Fractions | PROGRAMMING | 1,700 | [
"brute force",
"implementation",
"math"
] | null | null | A continued fraction of height *n* is a fraction of form . You are given two rational numbers, one is represented as and the other one is represented as a finite fraction of height *n*. Check if they are equal. | The first line contains two space-separated integers *p*,<=*q* (1<=≤<=*q*<=≤<=*p*<=≤<=1018) — the numerator and the denominator of the first fraction.
The second line contains integer *n* (1<=≤<=*n*<=≤<=90) — the height of the second fraction. The third line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a... | Print "YES" if these fractions are equal and "NO" otherwise. | [
"9 4\n2\n2 4\n",
"9 4\n3\n2 3 1\n",
"9 4\n3\n1 2 4\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5ff92f27aebea2560d99ad61202d20bab5ee5390.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/221368c79c05fc0ecad4e5f7a64f3... | 1,000 | [
{
"input": "9 4\n2\n2 4",
"output": "YES"
},
{
"input": "9 4\n3\n2 3 1",
"output": "YES"
},
{
"input": "9 4\n3\n1 2 4",
"output": "NO"
},
{
"input": "39088169 24157817\n36\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2",
"output": "YES"
},
{
... | 1,576,728,664 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 46 | 310 | 0 |
p,q=map(int,input().split())
n=int(input())
w=[int(x) for x in input().split()]
if p%q!=0:
r=[0]*n
i=0
while i+1<=n:
if q!=0:
r[i] = int(p / q)
p,q=q,p-int(p/q)*q
i+=1
else:
break
if r==w or (r[n-1]==0 and w[n-1]==1 and w[... | Title: Continued Fractions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A continued fraction of height *n* is a fraction of form . You are given two rational numbers, one is represented as and the other one is represented as a finite fraction of height *n*. Check if they are equal.
In... | ```python
p,q=map(int,input().split())
n=int(input())
w=[int(x) for x in input().split()]
if p%q!=0:
r=[0]*n
i=0
while i+1<=n:
if q!=0:
r[i] = int(p / q)
p,q=q,p-int(p/q)*q
i+=1
else:
break
if r==w or (r[n-1]==0 and w[n-1]... | 0 | |
312 | A | Whose sentence is it? | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of ... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=10), number of sentences in the chat record. Each of the next *n* lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditi... | [
"5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .\n"
] | [
"Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\n"
] | none | 500 | [
{
"input": "5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .",
"output": "Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"
},
{
"input": "10\nLpAEKiHVJrzSZqBVSSyY\nYECGBlala.\nUZeGpeM.UCwiHmmA\nqt_,.b_.LSwJtJ.\nFAnXZtHlala.\nmiao.iape... | 1,562,097,280 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 93 | 0 | class CodeforcesTask312ASolution:
def __init__(self):
self.result = ''
self.mess_count = 0
self.messages = []
def read_input(self):
self.mess_count = int(input())
self.messages = [input() for x in range(self.mess_count)]
def process_task(self):
fo... | Title: Whose sentence is it?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Fr... | ```python
class CodeforcesTask312ASolution:
def __init__(self):
self.result = ''
self.mess_count = 0
self.messages = []
def read_input(self):
self.mess_count = int(input())
self.messages = [input() for x in range(self.mess_count)]
def process_task(self):
... | 0 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,648,227,616 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | from math import floor
n,k=[int(i1) for i1 in input().split()]
students=[int(i2) for i2 in input().split()]
eligible_students=0
max_rounds=5-k
for i3 in students:
if i3<=max_rounds:
eligible_students+=1
print(floor(eligible_students/3)) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
from math import floor
n,k=[int(i1) for i1 in input().split()]
students=[int(i2) for i2 in input().split()]
eligible_students=0
max_rounds=5-k
for i3 in students:
if i3<=max_rounds:
eligible_students+=1
print(floor(eligible_students/3))
``` | 3 | |
27 | A | Next Test | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Next Test | 2 | 256 | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. | Output the required default value for the next test index. | [
"3\n1 7 2\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
... | 1,494,584,443 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 307,200 | '''input
3
1 7 2
'''
n = int(input())
a = sorted(map(int, input().split()))
x = 1
while x in a:
x += 1
print(x) | Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the... | ```python
'''input
3
1 7 2
'''
n = int(input())
a = sorted(map(int, input().split()))
x = 1
while x in a:
x += 1
print(x)
``` | 3.944928 |
981 | B | Businessmen Problems | PROGRAMMING | 1,000 | [
"sortings"
] | null | null | Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the ... | The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of elements discovered by ChemForces.
The $i$-th of the next $n$ lines contains two integers $a_i$ and $x_i$ ($1 \leq a_i \leq 10^9$, $1 \leq x_i \leq 10^9$) — the index of the $i$-th element and the income of its usage on the exhibitio... | Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets. | [
"3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4\n",
"1\n1000000000 239\n3\n14 15\n92 65\n35 89\n"
] | [
"24\n",
"408\n"
] | In the first example ChemForces can choose the set ($3, 7$), while TopChemist can choose ($1, 2, 4$). This way the total income is $(10 + 2) + (4 + 4 + 4) = 24$.
In the second example ChemForces can choose the only element $10^9$, while TopChemist can choose ($14, 92, 35$). This way the total income is $(239) + (15 + ... | 750 | [
{
"input": "3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4",
"output": "24"
},
{
"input": "1\n1000000000 239\n3\n14 15\n92 65\n35 89",
"output": "408"
},
{
"input": "10\n598654597 488228616\n544064902 21923894\n329635457 980089248\n988262691 654502493\n967529230 543358150\n835120075 128123793\... | 1,527,435,178 | 2,578 | Python 3 | OK | TESTS | 33 | 842 | 20,582,400 | n=int(input())
CF={}
for i in range(n):
x=list(map(int,input().split()))
CF[x[0]]=x[1]
m=int(input())
TC={}
for i in range(m):
x=list(map(int,input().split()))
TC[x[0]]=x[1]
keys_Tc=set(TC.keys())
keys_Cf=set(CF.keys())
common=keys_Cf&keys_Tc
s=0
for x in TC:
if x not in common:
s+=TC[x]
for x in CF:
if x not i... | Title: Businessmen Problems
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both... | ```python
n=int(input())
CF={}
for i in range(n):
x=list(map(int,input().split()))
CF[x[0]]=x[1]
m=int(input())
TC={}
for i in range(m):
x=list(map(int,input().split()))
TC[x[0]]=x[1]
keys_Tc=set(TC.keys())
keys_Cf=set(CF.keys())
common=keys_Cf&keys_Tc
s=0
for x in TC:
if x not in common:
s+=TC[x]
for x in CF:
... | 3 | |
936 | B | Sleepy Game | PROGRAMMING | 2,100 | [
"dfs and similar",
"dp",
"games",
"graphs"
] | null | null | Petya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of *n* vertices and *m* edges. One of the vertices contains a chip. Initially the chip is located at vertex *s*. Players take turns moving the chip along some edge of the graph. Petya goes first. Player who c... | The first line of input contain two integers *n* and *m* — the number of vertices and the number of edges in the graph (2<=≤<=*n*<=≤<=105, 0<=≤<=*m*<=≤<=2·105).
The next *n* lines contain the information about edges of the graph. *i*-th line (1<=≤<=*i*<=≤<=*n*) contains nonnegative integer *c**i* — number of vertices ... | If Petya can win print «Win» in the first line. In the next line print numbers *v*1,<=*v*2,<=...,<=*v**k* (1<=≤<=*k*<=≤<=106) — the sequence of vertices Petya should visit for the winning. Vertex *v*1 should coincide with *s*. For *i*<==<=1... *k*<=-<=1 there should be an edge from *v**i* to *v**i*<=+<=1 in the graph. ... | [
"5 6\n2 2 3\n2 4 5\n1 4\n1 5\n0\n1\n",
"3 2\n1 3\n1 1\n0\n2\n",
"2 2\n1 2\n1 1\n1\n"
] | [
"Win\n1 2 4 5 \n",
"Lose\n",
"Draw\n"
] | In the first example the graph is the following:
Initially the chip is located at vertex 1. In the first move Petya moves the chip to vertex 2, after that he moves it to vertex 4 for Vasya. After that he moves to vertex 5. Now it is Vasya's turn and there is no possible move, so Petya wins.
In the second example the ... | 1,000 | [
{
"input": "5 6\n2 2 3\n2 4 5\n1 4\n1 5\n0\n1",
"output": "Win\n1 2 4 5 "
},
{
"input": "3 2\n1 3\n1 1\n0\n2",
"output": "Lose"
},
{
"input": "2 2\n1 2\n1 1\n1",
"output": "Draw"
},
{
"input": "92 69\n1 76\n1 14\n1 9\n0\n1 46\n1 80\n0\n0\n1 77\n0\n1 53\n1 81\n1 61\n1 40\n0\n1... | 1,520,567,156 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 5,632,000 | draw = False
nodes = []
result = []
init = 0
class node:
def __init__(self, nei, num):
self.pe = None
self.po = None
self.visit = False
self.rec = False
self.neigh = nei
self.number = num
def search(self):
self.visit = True
if... | Title: Sleepy Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of *n* vertices and *m* edges. One of the vertices contains a chip. Initially the chip is located at vertex *s*... | ```python
draw = False
nodes = []
result = []
init = 0
class node:
def __init__(self, nei, num):
self.pe = None
self.po = None
self.visit = False
self.rec = False
self.neigh = nei
self.number = num
def search(self):
self.visit = True
... | 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,563,173,241 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 80 | 218 | 0 | import sys
import math
s = int(input())
ans = [0,0,0]
for i in range(s):
a = [int(x) for x in input().split()]
ans[0] += a[0]
ans[1] += a[1]
ans[2] += a[2]
if sum(ans) == 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
import sys
import math
s = int(input())
ans = [0,0,0]
for i in range(s):
a = [int(x) for x in input().split()]
ans[0] += a[0]
ans[1] += a[1]
ans[2] += a[2]
if sum(ans) == 0:
print("YES")
else:
print("NO")
``` | 0 |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,694,932,052 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 92 | 0 | num, *data = map(int, open(0).read().split())
subset = data[:1]
for element in data:
num -= min(subset) <= element <= max(subset)
subset += element,
print(num)
| Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
num, *data = map(int, open(0).read().split())
subset = data[:1]
for element in data:
num -= min(subset) <= element <= max(subset)
subset += element,
print(num)
``` | 3 | |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-sepa... | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6... | 1,659,005,772 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 156 | 25,292,800 | a = int(input())
b = list(map(int,input().split(" ")))
b.sort()
c = list(map(int,input().split(" ")))
c.sort()
d = list(map(int,input().split(" ")))
d.sort()
first,second=0,0
for i in range(len(c)):
if b[i] != c[i]:
first = b[i]
break
if first == 0:
first = b[-1]
print(first)
... | Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler disp... | ```python
a = int(input())
b = list(map(int,input().split(" ")))
b.sort()
c = list(map(int,input().split(" ")))
c.sort()
d = list(map(int,input().split(" ")))
d.sort()
first,second=0,0
for i in range(len(c)):
if b[i] != c[i]:
first = b[i]
break
if first == 0:
first = b[-1]
prin... | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,540,149,624 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | x=input()
z=0
while (z<len(x) and x[n]!='h'):
z+=1
z+=1
while (z<len(x) and x[z]!='e'):
z+=1
z+=1
while (z<len(x) and x[z]!='l'):
z+=1
z+=1
while (z<len(x) and x[z]!='l'):
z+=1
z+=1
while (z<len(x) and x[z]!='o'):
z+=1
if z<len(x):
print("YES")
else :
print ("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
x=input()
z=0
while (z<len(x) and x[n]!='h'):
z+=1
z+=1
while (z<len(x) and x[z]!='e'):
z+=1
z+=1
while (z<len(x) and x[z]!='l'):
z+=1
z+=1
while (z<len(x) and x[z]!='l'):
z+=1
z+=1
while (z<len(x) and x[z]!='o'):
z+=1
if z<len(x):
print("YES")
else :
print ("NO")
``` | -1 |
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1... | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"outpu... | 1,458,238,052 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 3,000 | 8,601,600 | n = int(input())
a = []
for i in range(n) :
a.append(input())
c = []
for i in range(len(a)-1,-1,-1) :
for q in range(len(c)) :
if c[q] == a[i] :
break
else :
c.append(a[i])
for i in range(len(c)):
print(c[i])
| Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The rela... | ```python
n = int(input())
a = []
for i in range(n) :
a.append(input())
c = []
for i in range(len(a)-1,-1,-1) :
for q in range(len(c)) :
if c[q] == a[i] :
break
else :
c.append(a[i])
for i in range(len(c)):
print(c[i])
``` | 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,548,784,151 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 108 | 0 | b=input()
a='hello'
k=0
for j in range(len(b)):
try:
if a[j] not in b:
print('NO')
k=1
break
c=b.find(a[j])
b=b[c+1:]
if a[j+1] in b:
continue
else:
... | 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
b=input()
a='hello'
k=0
for j in range(len(b)):
try:
if a[j] not in b:
print('NO')
k=1
break
c=b.find(a[j])
b=b[c+1:]
if a[j+1] in b:
continue
else:
... | 3.946 |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,645,941,522 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 1,044 | 9,216,000 | n = int(input())
alist = list(map(int, input().split()))
asort = sorted(alist)
for i in range(1, n):
alist[i] += alist[i - 1]
asort[i] += asort[i - 1]
m = int(input())
for _ in range(m):
t, l, r = map(int, input().split())
if t == 2:
print(asort[r-1] - asort[l - 2] if l - 1 !... | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
n = int(input())
alist = list(map(int, input().split()))
asort = sorted(alist)
for i in range(1, n):
alist[i] += alist[i - 1]
asort[i] += asort[i - 1]
m = int(input())
for _ in range(m):
t, l, r = map(int, input().split())
if t == 2:
print(asort[r-1] - asort[l - 2] ... | 3 | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,677,237,718 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 122 | 0 | n = int(input())
scores = list(map(int, input().split()))
min_score = max_score = scores[0]
amazing_count = 0
for score in scores[1:]:
if score > max_score:
max_score = score
amazing_count += 1
elif score < min_score:
min_score = score
amazing_count += 1
print(am... | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n = int(input())
scores = list(map(int, input().split()))
min_score = max_score = scores[0]
amazing_count = 0
for score in scores[1:]:
if score > max_score:
max_score = score
amazing_count += 1
elif score < min_score:
min_score = score
amazing_count += 1
... | 3 | |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,669,650,556 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | n,t=map(int,input().split())
lis=list(map(int,input().split()))
lis.sort()
c=0
i=0
for i in range(len(lis)):
t=t-lis[i]
if(t>0):
c=c+1
print(c)
| Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
n,t=map(int,input().split())
lis=list(map(int,input().split()))
lis.sort()
c=0
i=0
for i in range(len(lis)):
t=t-lis[i]
if(t>0):
c=c+1
print(c)
``` | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,578,856,006 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 280 | 0 | import sys
import io
import os
total = 0
failed = 0
def run(test,res):
x = io.StringIO()
with io.StringIO(test) as sys.stdin:
with x as sys.stdout:
work()
z = x.getvalue().strip()
sys.stdout = sys.__stdout__
print("Passed?", z == res)
print("Expected: "... | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
import sys
import io
import os
total = 0
failed = 0
def run(test,res):
x = io.StringIO()
with io.StringIO(test) as sys.stdin:
with x as sys.stdout:
work()
z = x.getvalue().strip()
sys.stdout = sys.__stdout__
print("Passed?", z == res)
print("E... | 3.93 |
26 | D | Tickets | PROGRAMMING | 2,400 | [
"combinatorics",
"math",
"probabilities"
] | D. Tickets | 2 | 256 | As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for t... | The input consist of a single line with three space separated integers, *n*, *m* and *k* (0<=≤<=*n*,<=*m*<=≤<=105, 0<=≤<=*k*<=≤<=10). | Output on a single line the desired probability with at least 4 digits after the decimal point. | [
"5 3 1\n",
"0 5 5\n",
"0 1 0\n"
] | [
"0.857143\n",
"1\n",
"0\n"
] | none | 2,000 | [
{
"input": "5 3 1",
"output": "0.857143"
},
{
"input": "0 5 5",
"output": "1"
},
{
"input": "0 1 0",
"output": "0"
},
{
"input": "95105 76851 10",
"output": "0.904215"
},
{
"input": "60503 53620 1",
"output": "0.214637"
},
{
"input": "25902 30390 2",
... | 1,499,391,581 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 124 | 5,529,600 | def find(A):
n,m,k=A
if m<k:
return 1
temp1=1
temp2=1
for i in range(k+1):
temp1*=(m-i)
temp2*=(n+i+1)
return 1-temp1/temp2
print(find(list(map(int,input().strip().split(' ')))))
| Title: Tickets
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes l... | ```python
def find(A):
n,m,k=A
if m<k:
return 1
temp1=1
temp2=1
for i in range(k+1):
temp1*=(m-i)
temp2*=(n+i+1)
return 1-temp1/temp2
print(find(list(map(int,input().strip().split(' ')))))
``` | 0 |
111 | A | Petya and Inequiations | PROGRAMMING | 1,400 | [
"greedy"
] | A. Petya and Inequiations | 2 | 256 | Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied:
- *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=≥<=*x*- *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=*y* | The first line contains three space-separated integers *n*, *x* and *y* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=1012,<=1<=≤<=*y*<=≤<=106).
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is recommended to use cin, cout streams or the %I64d specificator. | Print *n* positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them. | [
"5 15 15\n",
"2 3 2\n",
"1 99 11\n"
] | [
"4\n4\n1\n1\n2\n",
"-1\n",
"11\n"
] | none | 500 | [
{
"input": "5 15 15",
"output": "11\n1\n1\n1\n1"
},
{
"input": "2 3 2",
"output": "-1"
},
{
"input": "1 99 11",
"output": "11"
},
{
"input": "100000 810000099998 1000000",
"output": "900001\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n... | 1,591,529,265 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 48 | 436 | 7,884,800 | n, x, y = map(int, input().split())
a = y - n + 1
if a * a + n - 1 < x: exit(print(-1))
print(a)
for _ in range(n - 1):
print(1)
| Title: Petya and Inequiations
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied:
- *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=≥<=*x*- *a*1<=+<=*a*2<=+<... | ```python
n, x, y = map(int, input().split())
a = y - n + 1
if a * a + n - 1 < x: exit(print(-1))
print(a)
for _ in range(n - 1):
print(1)
``` | 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,523,211,399 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 77 | 7,065,600 |
lenght, a, b = map(int, input().split())
masa = list(map(int, input().split()))
masb = list(map(int, input().split()))
masc = list(abs(masa[i] - masb[i]) for i in range(lenght) if abs(masa[i] - masb[i]) != 0)
moves = a + b
if masc:
while moves > 0:
masc.sort()
masc[~0] -= 1
... | 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
lenght, a, b = map(int, input().split())
masa = list(map(int, input().split()))
masb = list(map(int, input().split()))
masc = list(abs(masa[i] - masb[i]) for i in range(lenght) if abs(masa[i] - masb[i]) != 0)
moves = a + b
if masc:
while moves > 0:
masc.sort()
masc[~0] -= 1... | 0 | |
276 | D | Little Girl and Maximum XOR | PROGRAMMING | 1,700 | [
"bitmasks",
"dp",
"greedy",
"implementation",
"math"
] | null | null | A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers *l* and *r*. Let's consider the values of for all pairs of integers *a* and *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*). Your task is to find the maximum value among all considered ones.
Expression means applying bitw... | The single line contains space-separated integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | In a single line print a single integer — the maximum value of for all pairs of integers *a*, *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*). | [
"1 2\n",
"8 16\n",
"1 1\n"
] | [
"3\n",
"31\n",
"0\n"
] | none | 2,000 | [
{
"input": "1 2",
"output": "3"
},
{
"input": "8 16",
"output": "31"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "506 677",
"output": "1023"
},
{
"input": "33 910",
"output": "1023"
},
{
"input": "36 94",
"output": "127"
},
{
"input": ... | 1,680,549,416 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 46 | 0 | l, r = map(int, input().split())
if l == r:
print(0)
exit()
num2 = str(bin(r))[2:]
num1 = str(bin(l))[2:]
temp = ([0] * (len(num2) - len(num1)))
temp.extend(num1)
# print(temp)
# print(num2)
total = 0
counter = 0
diff = 0
for i in range(len(num2)-1, -1, -1):
if temp[i] != num2[i]:
... | Title: Little Girl and Maximum XOR
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers *l* and *r*. Let's consider the values of for all pairs of integers *a* and *b* (*l*<=≤<=*a*<=≤<... | ```python
l, r = map(int, input().split())
if l == r:
print(0)
exit()
num2 = str(bin(r))[2:]
num1 = str(bin(l))[2:]
temp = ([0] * (len(num2) - len(num1)))
temp.extend(num1)
# print(temp)
# print(num2)
total = 0
counter = 0
diff = 0
for i in range(len(num2)-1, -1, -1):
if temp[i] != num... | 0 | |
298 | B | Sail | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will ... | The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the... | If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | [
"5 0 0 1 1\nSESNW\n",
"10 5 3 3 6\nNENSWESNEE\n"
] | [
"4\n",
"-1\n"
] | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | 500 | [
{
"input": "5 0 0 1 1\nSESNW",
"output": "4"
},
{
"input": "10 5 3 3 6\nNENSWESNEE",
"output": "-1"
},
{
"input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS",
"output": "13"
},
{
"input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSS... | 1,571,518,503 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 372 | 1,331,200 | p=input()
t,sx,sy,ex,ey=map(int,p.split())
q=input()
q=q.replace('',' ')
q=q.split()
i=0
while (sx!=ex or sy!=ey) and i<t:
if q[i]=='E':
if sx<ex:
sx+=1
elif q[i]=='W':
if sx>ex:
sx-=1
elif q[i]=='N':
if sy<ey:
sy+=1
else:
... | Title: Sail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assu... | ```python
p=input()
t,sx,sy,ex,ey=map(int,p.split())
q=input()
q=q.replace('',' ')
q=q.split()
i=0
while (sx!=ex or sy!=ey) and i<t:
if q[i]=='E':
if sx<ex:
sx+=1
elif q[i]=='W':
if sx>ex:
sx-=1
elif q[i]=='N':
if sy<ey:
sy+=1
e... | 3 | |
630 | G | Challenge Pennants | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting... | The only line of the input contains one integer *n* (1<=≤<=*n*<=≤<=500) — the number of tables in the IT company. | Output one integer — the amount of ways to place the pennants on *n* tables. | [
"2\n"
] | [
"24"
] | none | 0 | [
{
"input": "2",
"output": "24"
},
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "210"
},
{
"input": "4",
"output": "1120"
},
{
"input": "5",
"output": "4410"
},
{
"input": "6",
"output": "14112"
},
{
"input": "7",
"output":... | 1,687,723,013 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 15 | 62 | 0 | import sys
input = lambda: sys.stdin.readline().rstrip()
import math
N = int(input())
a = math.comb(N+5-1,5)
b = math.comb(N+3-1,3)
print(a*b) | Title: Challenge Pennants
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed ... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
import math
N = int(input())
a = math.comb(N+5-1,5)
b = math.comb(N+3-1,3)
print(a*b)
``` | 3 | |
877 | A | Alex and broken contest | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest ... | The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. | Print "YES", if problem is from this contest, and "NO" otherwise. | [
"Alex_and_broken_contest\n",
"NikitaAndString\n",
"Danil_and_Olya\n"
] | [
"NO",
"YES",
"NO"
] | none | 500 | [
{
"input": "Alex_and_broken_contest",
"output": "NO"
},
{
"input": "NikitaAndString",
"output": "YES"
},
{
"input": "Danil_and_Olya",
"output": "NO"
},
{
"input": "Slava____and_the_game",
"output": "YES"
},
{
"input": "Olya_and_energy_drinks",
"output": "YES"
... | 1,521,712,898 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 93 | 7,065,600 | s=input()
D="Danil"
O="Olya"
S="Slava"
A="Ann"
N="Nikita"
if s.count(D)==1 and s.count(O)==0 and s.count(S)==0 and s.count(A)==0 and s.count(N)==0:
print("YES")
elif s.count(D)==0 and s.count(O)==1 and s.count(S)==0 and s.count(A)==0 and s.count(N)==0:
print("YES")
elif s.count(D)==0 and s.count(O)==0... | Title: Alex and broken contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems,... | ```python
s=input()
D="Danil"
O="Olya"
S="Slava"
A="Ann"
N="Nikita"
if s.count(D)==1 and s.count(O)==0 and s.count(S)==0 and s.count(A)==0 and s.count(N)==0:
print("YES")
elif s.count(D)==0 and s.count(O)==1 and s.count(S)==0 and s.count(A)==0 and s.count(N)==0:
print("YES")
elif s.count(D)==0 and s.c... | 3 | |
27 | E | Number With The Given Amount Of Divisors | PROGRAMMING | 2,000 | [
"brute force",
"dp",
"number theory"
] | E. Number With The Given Amount Of Divisors | 2 | 256 | Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000). | Output the smallest positive integer with exactly *n* divisors. | [
"4\n",
"6\n"
] | [
"6\n",
"12\n"
] | none | 2,500 | [
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "64"
},
{
"input": "8",
"output": "24"
},
{
"input": "9",
"output": "36"
},
{
"input": "10",
"output": "48"
},
{
"input": "15",
"output": "144"
},
{
"input": "20",
"output": "24... | 1,617,574,239 | 2,147,483,647 | PyPy 3 | OK | TESTS | 22 | 248 | 3,891,200 | INF = 20**18
primes = []
a = [1]*100
def crivo():
for i in range(2, 100):
if a[i]:
primes.append(i)
for j in range(i+i, 100, i):
a[j] = 0
def dp(div, idx):
div = int(div)
idx = int(idx)
if div == 1:
return 1
resp = INF
for i in ra... | Title: Number With The Given Amount Of Divisors
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018.
Input Specification:
The first line... | ```python
INF = 20**18
primes = []
a = [1]*100
def crivo():
for i in range(2, 100):
if a[i]:
primes.append(i)
for j in range(i+i, 100, i):
a[j] = 0
def dp(div, idx):
div = int(div)
idx = int(idx)
if div == 1:
return 1
resp = INF
f... | 3.930752 |
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,691,409,517 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 124 | 2,764,800 | n=int(input())
x,y,z=map(int,input().split())
static=False
for v in zip(x,y,z):
if sum(v) == 0:
print("YES")
static=True
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())
x,y,z=map(int,input().split())
static=False
for v in zip(x,y,z):
if sum(v) == 0:
print("YES")
static=True
else:
print("No")
``` | -1 |
16 | B | Burglar and Matches | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | B. Burglar and Matches | 0 | 64 | A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactl... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. | Output the only number — answer to the problem. | [
"7 3\n5 10\n2 5\n3 6\n",
"3 3\n1 3\n2 2\n3 1\n"
] | [
"62\n",
"7\n"
] | none | 0 | [
{
"input": "7 3\n5 10\n2 5\n3 6",
"output": "62"
},
{
"input": "3 3\n1 3\n2 2\n3 1",
"output": "7"
},
{
"input": "1 1\n1 2",
"output": "2"
},
{
"input": "1 2\n1 9\n1 6",
"output": "9"
},
{
"input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1",
"ou... | 1,641,817,941 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 92 | 0 | n,m = map(int,input().split())
matchboxes = {}
for _ in range(m):
a,b = map(int,input().split()) #a refers to number of matchboxes holding b matches
matchboxes[b] = a if b not in matchboxes else matchboxes[b] + a
highest = 0
for key,value in sorted(matchboxes.items(),key = lambda x: x[0],reverse = True):
... | Title: Burglar and Matches
Time Limit: 0 seconds
Memory Limit: 64 megabytes
Problem Description:
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* mat... | ```python
n,m = map(int,input().split())
matchboxes = {}
for _ in range(m):
a,b = map(int,input().split()) #a refers to number of matchboxes holding b matches
matchboxes[b] = a if b not in matchboxes else matchboxes[b] + a
highest = 0
for key,value in sorted(matchboxes.items(),key = lambda x: x[0],reverse... | 3 |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,697,835,375 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | n = int(input())
counter = 0
for i in range(0, n):
k = input()
if k.count("1") >= 2:
counter += 1
print(counter)
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
n = int(input())
counter = 0
for i in range(0, n):
k = input()
if k.count("1") >= 2:
counter += 1
print(counter)
``` | 3 | |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihn... | 1,560,212,128 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 108 | 0 | n = input()
vet = [0,0,0,0];
for i in range(0,len(n)):
if(n[i] == 'n'):
vet[0]+=1
elif(n[i] == 'i'):
vet[1]+=1
elif(n[i] == 'e'):
vet[2]+=1
elif(n[i] == 't'):
vet[3]+=1
vet[0] = (vet[0] - 1) / 2
vet[2] /= 3
vet.sort()
print(int(vet[0])) | Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiinetee... | ```python
n = input()
vet = [0,0,0,0];
for i in range(0,len(n)):
if(n[i] == 'n'):
vet[0]+=1
elif(n[i] == 'i'):
vet[1]+=1
elif(n[i] == 'e'):
vet[2]+=1
elif(n[i] == 't'):
vet[3]+=1
vet[0] = (vet[0] - 1) / 2
vet[2] /= 3
vet.sort()
print(int(vet[0]))
``` | 3 | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,675,540,751 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 404 | 28,467,200 | num, choose = map(int, input().split())
lista = list(map(int, input().split()))
ans = 0
j = 0
for i in range(0,num):
while(lista[i] - lista[j] > choose): j+=1
ans += ((i - j) * (i - j - 1))/2
print(int(ans))
| Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
num, choose = map(int, input().split())
lista = list(map(int, input().split()))
ans = 0
j = 0
for i in range(0,num):
while(lista[i] - lista[j] > choose): j+=1
ans += ((i - j) * (i - j - 1))/2
print(int(ans))
``` | 3 | |
609 | A | USB Flash Drives | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. | The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabyt... | Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. | [
"3\n5\n2\n1\n3\n",
"3\n6\n2\n3\n2\n",
"2\n5\n5\n10\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | 0 | [
{
"input": "3\n5\n2\n1\n3",
"output": "2"
},
{
"input": "3\n6\n2\n3\n2",
"output": "3"
},
{
"input": "2\n5\n5\n10",
"output": "1"
},
{
"input": "5\n16\n8\n1\n3\n4\n9",
"output": "2"
},
{
"input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100",
"output": "2"
... | 1,562,078,765 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | n = int(input())
m = int(input())
a = []
for i in range(n):
x = int(input())
a.append(x)
a.sort()
a = a[::-1]
count = 0
i = 0
res = 0
while i < n and res <= m:
if res + a[i] <= m:
res = res + a[i]
i += 1
if re... | Title: USB Flash Drives
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of... | ```python
n = int(input())
m = int(input())
a = []
for i in range(n):
x = int(input())
a.append(x)
a.sort()
a = a[::-1]
count = 0
i = 0
res = 0
while i < n and res <= m:
if res + a[i] <= m:
res = res + a[i]
i +... | 0 | |
598 | B | Queries on a String | PROGRAMMING | 1,300 | [
"implementation",
"strings"
] | null | null | You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**i*] *k**i* times. The queries should be processed one after another in the order they are given.
One ope... | The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=10<=000) in its initial state, where |*s*| stands for the length of *s*. It contains only lowercase English letters.
Second line contains a single integer *m* (1<=≤<=*m*<=≤<=300) — the number of queries.
The *i*-th of the next *m* lines contains thr... | Print the resulting string *s* after processing all *m* queries. | [
"abacaba\n2\n3 6 1\n1 4 2\n"
] | [
"baabcaa\n"
] | The sample is described in problem statement. | 0 | [
{
"input": "abacaba\n2\n3 6 1\n1 4 2",
"output": "baabcaa"
},
{
"input": "u\n1\n1 1 1",
"output": "u"
},
{
"input": "p\n5\n1 1 5\n1 1 9\n1 1 10\n1 1 10\n1 1 4",
"output": "p"
},
{
"input": "ssssssssss\n5\n5 7 9\n3 9 3\n2 7 1\n7 7 10\n1 9 6",
"output": "ssssssssss"
},
... | 1,636,131,187 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 28,467,200 | s = input()
q = int(input())
for i in range(q):
l, r, k = map(int, input().split())
if l==r:
continue
k%=(r-l)
b = s[l-1:r]
s = s[:l-1] + b[len(b)-k:] + b[:len(b)-k] + s[r:]
print(s) | Title: Queries on a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**... | ```python
s = input()
q = int(input())
for i in range(q):
l, r, k = map(int, input().split())
if l==r:
continue
k%=(r-l)
b = s[l-1:r]
s = s[:l-1] + b[len(b)-k:] + b[:len(b)-k] + s[r:]
print(s)
``` | 0 | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,633,399,584 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 7,372,800 | n = int(input())
x = list(map(int,input().split()))
m = int(input())
y = list(map(int,input().split()))
f = 0
s = 0
for i in range(m):
f += (x.index(y[i])+1)
x = x[::-1]
for i in range(m):
s+= (x.index(y[i])+1)
print(f,s)
| Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
n = int(input())
x = list(map(int,input().split()))
m = int(input())
y = list(map(int,input().split()))
f = 0
s = 0
for i in range(m):
f += (x.index(y[i])+1)
x = x[::-1]
for i in range(m):
s+= (x.index(y[i])+1)
print(f,s)
``` | 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,570,327,331 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | a=int(input())
b=int(input())
if abs(a-b)==1:
print("1")
else:
n=abs(a-b)
h=n//2
s=(h*(h+1))//2
if n%2==0:
print(2*s)
else:
r=(2*s)+(h+1)
print(r) | 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=int(input())
b=int(input())
if abs(a-b)==1:
print("1")
else:
n=abs(a-b)
h=n//2
s=(h*(h+1))//2
if n%2==0:
print(2*s)
else:
r=(2*s)+(h+1)
print(r)
``` | 3 | |
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dis... | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.... | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 59... | 1,505,710,610 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,608,000 | n = int(input())
a = input()
arr = list(map(int,(input().split())))
arrL=[];arrR = []
for i in range(0,n):
if a[i]=='L':arrL.append(arr[i])
elif a[i]=='R':arrR.append(arr[i])
if arrL==[] or arrR ==[] :
print(-1);quit()
mL = max(arrL)
mR = min(arrR)
if mL > mR :
arrL =sorted(arrL)
arrR=s... | Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be... | ```python
n = int(input())
a = input()
arr = list(map(int,(input().split())))
arrL=[];arrR = []
for i in range(0,n):
if a[i]=='L':arrL.append(arr[i])
elif a[i]=='R':arrR.append(arr[i])
if arrL==[] or arrR ==[] :
print(-1);quit()
mL = max(arrL)
mR = min(arrR)
if mL > mR :
arrL =sorted(arrL)
... | 0 | |
893 | C | Rumor | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Ove... | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
... | Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example ... | 0 | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n10000000... | 1,679,779,817 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 1,107 | 17,408,000 | from collections import deque
n, m=map(int, input().split())
gold=[0]+list(map(int, input().split()))
adjacency_list={i: [] for i in range(1, n+1)}
for i in range(m):
l, r=map(int, input().split())
adjacency_list[l].append(r)
adjacency_list[r].append(l)
marks=[0 for i in range(n+1)]
connected_c... | Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte... | ```python
from collections import deque
n, m=map(int, input().split())
gold=[0]+list(map(int, input().split()))
adjacency_list={i: [] for i in range(1, n+1)}
for i in range(m):
l, r=map(int, input().split())
adjacency_list[l].append(r)
adjacency_list[r].append(l)
marks=[0 for i in range(n+1)]
c... | 3 | |
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate... | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence... | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15... | 1,696,682,327 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n,k=map(int,input().split())
a=list(map(int,input().split()))
if a[k+1]>0:
print(k+1)
else:
print(0) | Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* p... | ```python
n,k=map(int,input().split())
a=list(map(int,input().split()))
if a[k+1]>0:
print(k+1)
else:
print(0)
``` | 0 | |
1,008 | A | Romaji | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant... | The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. | Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"sumimasen\n",
"ninja\n",
"codeforces\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese. | 500 | [
{
"input": "sumimasen",
"output": "YES"
},
{
"input": "ninja",
"output": "YES"
},
{
"input": "codeforces",
"output": "NO"
},
{
"input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen",
"output": "YES"
},
{
"in... | 1,637,147,268 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | a=input()
b="aeioun"
c="bcdfghjklmpqrstvwxyz"
d=len(a)
f=0
for i in range(d):
if i == d-1:
break
else:
if a[i] in c:
if a[i+1] in b:
f="YES"
pass
else:
f="NO"
break
if f=="YES":
print... | Title: Romaji
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after eve... | ```python
a=input()
b="aeioun"
c="bcdfghjklmpqrstvwxyz"
d=len(a)
f=0
for i in range(d):
if i == d-1:
break
else:
if a[i] in c:
if a[i+1] in b:
f="YES"
pass
else:
f="NO"
break
if f=="YES":
... | 0 | |
844 | B | Rectangles | PROGRAMMING | 1,300 | [
"combinatorics",
"math"
] | null | null | You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or column. | The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly.
The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored wh... | Output single integer — the number of non-empty sets from the problem description. | [
"1 1\n0\n",
"2 3\n1 0 1\n0 1 0\n"
] | [
"1\n",
"8\n"
] | In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets. | 1,000 | [
{
"input": "1 1\n0",
"output": "1"
},
{
"input": "2 3\n1 0 1\n0 1 0",
"output": "8"
},
{
"input": "2 2\n1 1\n1 1",
"output": "8"
},
{
"input": "1 10\n0 0 0 0 0 0 0 0 0 0",
"output": "1023"
},
{
"input": "11 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "2047"... | 1,503,594,925 | 2,425 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 62 | 0 | def a_sum(n):
return (1+n)*n//2
n, m = map(int, input().split())
board = []
for _ in range(n):
board.append(''.join(input().split()))
res = []
for i in range(n):
a, b = board[i].count('0'), board[i].count('1')
if a > 1:
res.append(a)
if b > 1:
res.append(b)
board = list(zip(*board)... | Title: Rectangles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or ... | ```python
def a_sum(n):
return (1+n)*n//2
n, m = map(int, input().split())
board = []
for _ in range(n):
board.append(''.join(input().split()))
res = []
for i in range(n):
a, b = board[i].count('0'), board[i].count('1')
if a > 1:
res.append(a)
if b > 1:
res.append(b)
board = list(z... | 0 | |
441 | A | Valera and Antique Items | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfec... | The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has.
Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space... | In the first line, print integer *p* — the number of sellers with who Valera can make a deal.
In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order. | [
"3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n",
"3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n"
] | [
"3\n1 2 3\n",
"0\n\n"
] | In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.
In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the... | 500 | [
{
"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000",
"output": "3\n1 2 3"
},
{
"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000",
"output": "0"
},
{
"input": "2 100001\n1 895737\n1 541571",
"output": "0"
},
{
"input": "1 1000000\n1 100... | 1,677,771,506 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 61 | 1,433,600 | n , v = list(map(int , input().split()))
a = []
for el in range(n):
l = list(map(int , input().split()))
if(l[1] < v):
a.append(el+1)
print(len(a))
print(*a) | Title: Valera and Antique Items
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the... | ```python
n , v = list(map(int , input().split()))
a = []
for el in range(n):
l = list(map(int , input().split()))
if(l[1] < v):
a.append(el+1)
print(len(a))
print(*a)
``` | 0 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,591,177,603 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 218 | 0 | a = input()
b = input()
s1 = a[:len(a)//2]
s2 = a[len(a)//2:]
if(s2[::-1]+s1[::-1] == b):
print("YES")
else:
print("NO") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
a = input()
b = input()
s1 = a[:len(a)//2]
s2 = a[len(a)//2:]
if(s2[::-1]+s1[::-1] == b):
print("YES")
else:
print("NO")
``` | 3.9455 |
0 | none | none | none | 0 | [
"none"
] | null | null | Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any nu... | First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players. | Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. | [
"4\n75 150 75 50\n",
"3\n100 150 250\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | 0 | [
{
"input": "4\n75 150 75 50",
"output": "Yes"
},
{
"input": "3\n100 150 250",
"output": "No"
},
{
"input": "7\n34 34 68 34 34 68 34",
"output": "Yes"
},
{
"input": "10\n72 96 12 18 81 20 6 2 54 1",
"output": "No"
},
{
"input": "20\n958692492 954966768 77387000 724... | 1,440,879,578 | 2,258 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 2,000 | 11,980,800 | def p(x):
res = []
i = 2
while x > 1:
while x % i == 0:
x //= i
if i != 2 and i != 3:
res.append(i)
i += 1
return res
read = lambda: map(int, input().split())
n = int(input())
a = [p(int(i)) for i in input().split()]
k = a[0]
f = su... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a*... | ```python
def p(x):
res = []
i = 2
while x > 1:
while x % i == 0:
x //= i
if i != 2 and i != 3:
res.append(i)
i += 1
return res
read = lambda: map(int, input().split())
n = int(input())
a = [p(int(i)) for i in input().split()]
k = a[... | 0 | |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,614,950,671 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 307,200 |
def find_path(n, d, map_):
cur_i = 0
jump_count = 0
end_flag = False
while not end_flag:
max_jump = -1
for i in range(d, 0, -1):
if (cur_i + i) < n and fmap[cur_i + i] == '1':
max_jump = i
break
print(cur_i, max_jump)
... | Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
def find_path(n, d, map_):
cur_i = 0
jump_count = 0
end_flag = False
while not end_flag:
max_jump = -1
for i in range(d, 0, -1):
if (cur_i + i) < n and fmap[cur_i + i] == '1':
max_jump = i
break
print(cur_i, ma... | 0 | |
18 | C | Stripe | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | C. Stripe | 2 | 64 | Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | [
"9\n1 5 -6 7 9 -16 0 -2 2\n",
"3\n1 1 1\n",
"2\n0 0\n"
] | [
"3\n",
"0\n",
"1\n"
] | none | 0 | [
{
"input": "9\n1 5 -6 7 9 -16 0 -2 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "4\n100 1 10 111",
"output": "1"
},
{
"input": "10\n0 4 -3 0 -2 2 -3 -3 2 5",
"output": "3"
},
{
"input": "... | 1,485,789,948 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 218 | 11,980,800 | # 18C
# θ(n) time
# θ(n) space
__author__ = 'artyom'
# SOLUTION
def main():
n = read()
a = read(3)
s = 0
t = sum(a)
count = 0
for i in range(n - 1):
s += a[i]
t -= a[i]
if s == t:
count += 1
return count
# HELPERS
def read(m... | Title: Stripe
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that ... | ```python
# 18C
# θ(n) time
# θ(n) space
__author__ = 'artyom'
# SOLUTION
def main():
n = read()
a = read(3)
s = 0
t = sum(a)
count = 0
for i in range(n - 1):
s += a[i]
t -= a[i]
if s == t:
count += 1
return count
# HELPERS
... | 3.856236 |
495 | B | Modular Equations | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and... | In the only line of the input two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=109) are given. | If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation . | [
"21 5\n",
"9435152 272\n",
"10 10\n"
] | [
"2\n",
"282\n",
"infinity\n"
] | In the first sample the answers of the Modular Equation are 8 and 16 since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6f5ff39ebd209bf990adaf91f4b82f9687097224.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "21 5",
"output": "2"
},
{
"input": "9435152 272",
"output": "282"
},
{
"input": "10 10",
"output": "infinity"
},
{
"input": "0 1000000000",
"output": "0"
},
{
"input": "11 2",
"output": "2"
},
{
"input": "1 0",
"output": "1"
},
{
... | 1,585,016,684 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 1,000 | 0 | #ax =- b(mod n)
#a % x = b
def factorNumber(x, b):
factors = []
for i in range(1, x+1):
if x % i == 0 and i >= b: factors.append(i)
return factors
(a,b) = list(map(int,input().split()))
answers = 0
if a == b:
print("infinity")
elif a < b:
print(0)
else:
factors = factorNumber(a-b,b)
... | Title: Modular Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed'... | ```python
#ax =- b(mod n)
#a % x = b
def factorNumber(x, b):
factors = []
for i in range(1, x+1):
if x % i == 0 and i >= b: factors.append(i)
return factors
(a,b) = list(map(int,input().split()))
answers = 0
if a == b:
print("infinity")
elif a < b:
print(0)
else:
factors = factorNumber(... | 0 | |
604 | B | More Cowbell | PROGRAMMING | 1,400 | [
"binary search",
"greedy"
] | null | null | Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a sin... | The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=2·*k*<=≤<=100<=000), denoting the number of cowbells and the number of boxes, respectively.
The next line contains *n* space-separated integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s*1<=≤<=*s*2<=≤<=...<=≤<=*s**n*<=≤<=1<=000<=000... | Print a single integer, the smallest *s* for which it is possible for Kevin to put all of his cowbells into *k* boxes of size *s*. | [
"2 1\n2 5\n",
"4 3\n2 3 5 9\n",
"3 2\n3 5 7\n"
] | [
"7\n",
"9\n",
"8\n"
] | In the first sample, Kevin must pack his two cowbells into the same box.
In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}.
In the third sample, the optimal solution is {3, 5} and {7}. | 1,000 | [
{
"input": "2 1\n2 5",
"output": "7"
},
{
"input": "4 3\n2 3 5 9",
"output": "9"
},
{
"input": "3 2\n3 5 7",
"output": "8"
},
{
"input": "20 11\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10 10\n3 15 31 61 63 63 68 94 98 100",
"outp... | 1,448,993,242 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | import math
def can_pack(m, b):
global n, k
cnt = 0
if b[-1] > m:
return False
p1 = 0
p2 = 0
while p1 <= p2:
if b[p2] + b[p1] <= m:
p1 += 1
p2 -= 1
else:
p2 -= 1
cnt += 1
return cnt <= k
n, k = [int(x) ... | Title: More Cowbell
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order t... | ```python
import math
def can_pack(m, b):
global n, k
cnt = 0
if b[-1] > m:
return False
p1 = 0
p2 = 0
while p1 <= p2:
if b[p2] + b[p1] <= m:
p1 += 1
p2 -= 1
else:
p2 -= 1
cnt += 1
return cnt <= k
n, k ... | 0 | |
499 | A | Watching a movie | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | You have decided to watch the best moments of some movie. There are two buttons on your player:
1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie... | The first line contains two space-separated integers *n*, *x* (1<=≤<=*n*<=≤<=50, 1<=≤<=*x*<=≤<=105) — the number of the best moments of the movie and the value of *x* for the second button.
The following *n* lines contain the descriptions of the best moments of the movie, the *i*-th line of the description contains tw... | Output a single number — the answer to the problem. | [
"2 3\n5 6\n10 12\n",
"1 1\n1 100000\n"
] | [
"6\n",
"100000\n"
] | In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch th... | 500 | [
{
"input": "2 3\n5 6\n10 12",
"output": "6"
},
{
"input": "1 1\n1 100000",
"output": "100000"
},
{
"input": "10 1\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728",
"output": "53974"
},
{
"input": "1... | 1,620,373,764 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 28 | 62 | 6,963,200 | def compute_curr(curr,x, l,r):
if x == l:
curr = l
elif x < l:
curr += ((l-curr)//x)*x
return curr
def solve(arr,n,x):
curr = 1
count = 0
for i,v in enumerate(arr):
curr = compute_curr(curr,x,*v)
count += v[1]-curr+1
curr = v[1]+1
return count
... | Title: Watching a movie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have decided to watch the best moments of some movie. There are two buttons on your player:
1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the pl... | ```python
def compute_curr(curr,x, l,r):
if x == l:
curr = l
elif x < l:
curr += ((l-curr)//x)*x
return curr
def solve(arr,n,x):
curr = 1
count = 0
for i,v in enumerate(arr):
curr = compute_curr(curr,x,*v)
count += v[1]-curr+1
curr = v[1]+1
return co... | 0 | |
58 | B | Coins | PROGRAMMING | 1,300 | [
"greedy"
] | B. Coins | 2 | 256 | In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be d... | The first and only line contains an integer *n* (1<=≤<=*n*<=≤<=106) which represents the denomination of the most expensive coin. | Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination *n* of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coin... | [
"10\n",
"4\n",
"3\n"
] | [
"10 5 1\n",
"4 2 1\n",
"3 1\n"
] | none | 1,000 | [
{
"input": "10",
"output": "10 5 1"
},
{
"input": "4",
"output": "4 2 1"
},
{
"input": "3",
"output": "3 1"
},
{
"input": "2",
"output": "2 1"
},
{
"input": "5",
"output": "5 1"
},
{
"input": "6",
"output": "6 3 1"
},
{
"input": "7",
"o... | 1,610,359,795 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 154 | 0 | def factors(n):
c=2
if n<=1000:
c=1
i=1
ans=[n]
while i**c<=n:
if n%i==0 and i!=n:
ans.append(i)
i+=1
return ans
def coins(n):
if n==1:
return 1
a=factors(n)
a.remove(n)
maxi=max(a,key=lambda s:len(factors(s)))
pr... | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following... | ```python
def factors(n):
c=2
if n<=1000:
c=1
i=1
ans=[n]
while i**c<=n:
if n%i==0 and i!=n:
ans.append(i)
i+=1
return ans
def coins(n):
if n==1:
return 1
a=factors(n)
a.remove(n)
maxi=max(a,key=lambda s:len(factors(s)... | 0 |
433 | A | Kitahara Haruki's Gift | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equa... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple. | In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes). | [
"3\n100 200 100\n",
"4\n100 100 100 200\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | 500 | [
{
"input": "3\n100 200 100",
"output": "YES"
},
{
"input": "4\n100 100 100 200",
"output": "NO"
},
{
"input": "1\n100",
"output": "NO"
},
{
"input": "1\n200",
"output": "NO"
},
{
"input": "2\n100 100",
"output": "YES"
},
{
"input": "2\n200 200",
"o... | 1,680,019,533 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n=int(input())
a=list(map(int,input().split()))
if (sum(a)//100)%2==0:
print("YES")
else:
print("NO") | Title: Kitahara Haruki's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't w... | ```python
n=int(input())
a=list(map(int,input().split()))
if (sum(a)//100)%2==0:
print("YES")
else:
print("NO")
``` | 0 | |
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with t... | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — ... | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10... | 1,666,771,479 | 2,147,483,647 | Python 3 | OK | TESTS | 67 | 343 | 10,035,200 | n = int(input())
trees = []
for i in range(n):
trees.append(list(map(int,input().split())))
# trees[i][0]: position
# trees[i][1]: height
r_edge = -trees[0][1]
max_num = 1
for i in range(n-1):
# try to cut i-th tree
# if can be cut leftward, then rightward, then cannot be cut
if trees[i][0]... | Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described b... | ```python
n = int(input())
trees = []
for i in range(n):
trees.append(list(map(int,input().split())))
# trees[i][0]: position
# trees[i][1]: height
r_edge = -trees[0][1]
max_num = 1
for i in range(n-1):
# try to cut i-th tree
# if can be cut leftward, then rightward, then cannot be cut
if t... | 3 | |
989 | A | A Blend of Springtime | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower o... | The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively. | Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower). | [
".BAC.\n",
"AA..CB\n"
] | [
"Yes\n",
"No\n"
] | In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | 500 | [
{
"input": ".BAC.",
"output": "Yes"
},
{
"input": "AA..CB",
"output": "No"
},
{
"input": ".",
"output": "No"
},
{
"input": "ACB.AAAAAA",
"output": "Yes"
},
{
"input": "B.BC.BBBCA",
"output": "Yes"
},
{
"input": "BA..CAB..B",
"output": "Yes"
},
... | 1,528,738,547 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 92 | 0 | l = input()
if "ABC" in l or "ACB" in l or "BCA" in l or "BAC" in l:
print("Yes")
elif "CAB" in l or "CBA" in l:
print("Yes")
else:
print("No")
| Title: A Blend of Springtime
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimisti... | ```python
l = input()
if "ABC" in l or "ACB" in l or "BCA" in l or "BAC" in l:
print("Yes")
elif "CAB" in l or "CBA" in l:
print("Yes")
else:
print("No")
``` | 3 | |
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the mini... | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th ... | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697... | 1,692,380,314 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 61 | 0 | def main():
x = int(input())
restos = 0
dividendo = x
while (dividendo != 1):
restos += dividendo % 2
dividendo = dividendo // 2
bacterias = restos + 1 # bacteria inicial
print(bacterias)
main()
| Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split... | ```python
def main():
x = int(input())
restos = 0
dividendo = x
while (dividendo != 1):
restos += dividendo % 2
dividendo = dividendo // 2
bacterias = restos + 1 # bacteria inicial
print(bacterias)
main()
``` | 3 | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,693,669,884 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 46 | 0 | import math
m=input()
g=m.split()
alist=[]
alist.append((int(g[0]), int(g[1])))
count=0
for c in alist:
a,b=c
if a==b:
print(1)
else:
x = min(a, b)
y = max(a, b)
while x < y+0.0001:
x=x*3
y=y*2
count += 1
print(coun... | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
import math
m=input()
g=m.split()
alist=[]
alist.append((int(g[0]), int(g[1])))
count=0
for c in alist:
a,b=c
if a==b:
print(1)
else:
x = min(a, b)
y = max(a, b)
while x < y+0.0001:
x=x*3
y=y*2
count += 1
... | 3 | |
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dis... | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.... | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 59... | 1,656,362,900 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n = int(input())
dirs = input()
p = [int(i) for i in input().split()]
r = -1
l = -1
for i in range(n - 1):
if dirs[i] + dirs[i + 1] == "RL":
r = i
l = i + 1
break
if r == -1 or l == -1:
print(-1)
else:
print((p[l] - p[r]) // 2) | Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be... | ```python
n = int(input())
dirs = input()
p = [int(i) for i in input().split()]
r = -1
l = -1
for i in range(n - 1):
if dirs[i] + dirs[i + 1] == "RL":
r = i
l = i + 1
break
if r == -1 or l == -1:
print(-1)
else:
print((p[l] - p[r]) // 2)
``` | 0 | |
962 | A | Equator | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on... | The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests.
The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. | Print the index of the day when Polycarp will celebrate the equator. | [
"4\n1 3 2 1\n",
"6\n2 2 2 2 2 2\n"
] | [
"2\n",
"3\n"
] | In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (... | 0 | [
{
"input": "4\n1 3 2 1",
"output": "2"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "3"
},
{
"input": "1\n10000",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "2"
},
{
"input": "4\n2 1 1 3",
"output": "3"
}... | 1,524,313,310 | 530 | Python 3 | OK | TESTS | 106 | 187 | 20,787,200 | n = int(input())
a = list(map(int, input().split()))
sum1 = sum(a)
sum2 = 0
i = 0
while sum2 < (sum1 + 1) // 2:
sum2 += a[i]
i += 1
print(i) | Title: Equator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve... | ```python
n = int(input())
a = list(map(int, input().split()))
sum1 = sum(a)
sum2 = 0
i = 0
while sum2 < (sum1 + 1) // 2:
sum2 += a[i]
i += 1
print(i)
``` | 3 | |
820 | A | Mister B and Book Reading | PROGRAMMING | 900 | [
"implementation"
] | null | null | Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at ... | First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≤<=*c*<=≤<=1000, 0<=≤<=*l*<=<<=*v*0<=≤<=*v*1<=≤<=1000, 0<=≤<=*a*<=≤<=1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages fo... | Print one integer — the number of days Mister B needed to finish the book. | [
"5 5 10 5 4\n",
"12 4 12 4 1\n",
"15 1 100 0 0\n"
] | [
"1\n",
"3\n",
"15\n"
] | In the first sample test the book contains 5 pages, so Mister B read it right at the first day.
In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.
In third sample test every day Mister B read 1 page of the book, so he finished... | 500 | [
{
"input": "5 5 10 5 4",
"output": "1"
},
{
"input": "12 4 12 4 1",
"output": "3"
},
{
"input": "15 1 100 0 0",
"output": "15"
},
{
"input": "1 1 1 0 0",
"output": "1"
},
{
"input": "1000 999 1000 1000 998",
"output": "2"
},
{
"input": "1000 2 2 5 1",
... | 1,498,647,317 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | l=raw_input()
arr=l.split()
for i in range(0,5):
arr[i]=int(arr[i])
count=1
i=1
left_pages=arr[0]
if arr[0]<arr[1]:
print count
else:
left_pages=left_pages-arr[1]
while left_pages>0:
count+=1
effective_pages_read_per_day = arr[1] + i * arr[3] - arr[4]
checker = arr[... | Title: Mister B and Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, ... | ```python
l=raw_input()
arr=l.split()
for i in range(0,5):
arr[i]=int(arr[i])
count=1
i=1
left_pages=arr[0]
if arr[0]<arr[1]:
print count
else:
left_pages=left_pages-arr[1]
while left_pages>0:
count+=1
effective_pages_read_per_day = arr[1] + i * arr[3] - arr[4]
chec... | -1 | |
743 | B | Chloe and the sequence | PROGRAMMING | 1,200 | [
"binary search",
"bitmasks",
"constructive algorithms",
"implementation"
] | null | null | Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element eq... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1). | Print single integer — the integer at the *k*-th position in the obtained sequence. | [
"3 2\n",
"4 8\n"
] | [
"2",
"4"
] | In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4. | 1,000 | [
{
"input": "3 2",
"output": "2"
},
{
"input": "4 8",
"output": "4"
},
{
"input": "5 27",
"output": "1"
},
{
"input": "7 44",
"output": "3"
},
{
"input": "15 18432",
"output": "12"
},
{
"input": "20 259676",
"output": "3"
},
{
"input": "30 6... | 1,559,724,082 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 6 | 296 | 268,390,400 | n,k=map(int,input().split())
a=[1]
for i in range(2,n+1):
a.extend(a)
a.insert(len(a)//2,i)
print(a[k-1])
| Title: Chloe and the sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following a... | ```python
n,k=map(int,input().split())
a=[1]
for i in range(2,n+1):
a.extend(a)
a.insert(len(a)//2,i)
print(a[k-1])
``` | 0 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,680,099,223 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | cont=0
condi=True
n= int(input())
sere=0
dima=0
arr=[]
for i in range(n):
arr.append(int(input()))
for i in range(len(arr)):
if arr[0+cont]>arr[-1]:
if condi==True:
sere= sere+arr[0+cont]
condi=False
else:
dima= dima+arr[0+cont]
cond... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
cont=0
condi=True
n= int(input())
sere=0
dima=0
arr=[]
for i in range(n):
arr.append(int(input()))
for i in range(len(arr)):
if arr[0+cont]>arr[-1]:
if condi==True:
sere= sere+arr[0+cont]
condi=False
else:
dima= dima+arr[0+cont]
... | -1 | |
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,597,781,880 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 13 | 124 | 0 | import sys
n = int(input())
a = input().split()
count = 0
num = "".join(a)
y = num.count("0")
if n == 1:
print("YES")
sys.exit()
if y == 1 and n > 1:
print("YES")
else:
print("NO") | 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
import sys
n = int(input())
a = input().split()
count = 0
num = "".join(a)
y = num.count("0")
if n == 1:
print("YES")
sys.exit()
if y == 1 and n > 1:
print("YES")
else:
print("NO")
``` | 0 | |
794 | A | Bank Robbery | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe f... | The first line of input contains three space-separated integers, *a*, *b* and *c* (1<=≤<=*b*<=<<=*a*<=<<=*c*<=≤<=109), denoting the positions of Oleg, the first security guard and the second security guard, respectively.
The next line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the numbe... | Output a single integer: the maximum number of banknotes Oleg can take. | [
"5 3 7\n8\n4 7 5 5 3 6 2 8\n",
"6 5 7\n5\n1 5 7 92 3\n"
] | [
"4\n",
"0\n"
] | In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first se... | 500 | [
{
"input": "5 3 7\n8\n4 7 5 5 3 6 2 8",
"output": "4"
},
{
"input": "6 5 7\n5\n1 5 7 92 3",
"output": "0"
},
{
"input": "3 2 4\n1\n3",
"output": "1"
},
{
"input": "5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6",
"output": "8"
},
{
"input": "7 3 10\n5\n3 3 3 3 3",
"output... | 1,495,063,526 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 7,270,400 | line1 = input()
a,b,c = line1.split(' ')
a,b,c = int(a),int(b),int(c)
input()
safes = range(b+1,c)
line3 = input().split(' ')
c = 0
for sf in safes:
c += line3.count(str(sf))
print(c) | Title: Bank Robbery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and... | ```python
line1 = input()
a,b,c = line1.split(' ')
a,b,c = int(a),int(b),int(c)
input()
safes = range(b+1,c)
line3 = input().split(' ')
c = 0
for sf in safes:
c += line3.count(str(sf))
print(c)
``` | 0 | |
600 | B | Queries about less or equal elements | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | 0 | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -77918754... | 1,655,034,456 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 1,076 | 27,545,600 | if __name__ == '__main__':
n, m = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
c = []
for i in range(m):
c.append([b[i], i])
a.sort()
c = sorted(c, key=lambda k: k[0])
left = 0
res ... | Title: Queries about less or equal elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
In... | ```python
if __name__ == '__main__':
n, m = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
c = []
for i in range(m):
c.append([b[i], i])
a.sort()
c = sorted(c, key=lambda k: k[0])
left = 0... | 3 | |
779 | C | Dishonest Sellers | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*.
Not all of sellers are honest, so now some products could be more expensive than after a week... | In the first line there are two positive integer numbers *n* and *k* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*k*<=≤<=*n*) — total number of items to buy and minimal number of items Igor wants to by right now.
The second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — prices of items during d... | Print the minimal amount of money Igor will spend to buy all *n* items. Remember, he should buy at least *k* items right now. | [
"3 1\n5 4 6\n3 1 5\n",
"5 3\n3 4 7 10 3\n4 5 5 12 5\n"
] | [
"10\n",
"25\n"
] | In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.
In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week ... | 1,000 | [
{
"input": "3 1\n5 4 6\n3 1 5",
"output": "10"
},
{
"input": "5 3\n3 4 7 10 3\n4 5 5 12 5",
"output": "25"
},
{
"input": "1 0\n9\n8",
"output": "8"
},
{
"input": "2 0\n4 10\n1 2",
"output": "3"
},
{
"input": "4 2\n19 5 17 13\n3 18 8 10",
"output": "29"
},
... | 1,536,151,973 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 45 | 421 | 17,920,000 | a = [int(k) for k in input().split()]
b = [int(k) for k in input().split()]
c = [int(k) for k in input().split()]
d = [b[k] - c[k] for k in range(a[0])]
d.sort()
e = 0
while d[e] < 0 and e < a[0]:
e += 1
if e > a[1]:
print(sum(d[0:e])+sum(c))
else:
print(sum(d[0:a[1]])+sum(c)) | Title: Dishonest Sellers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be... | ```python
a = [int(k) for k in input().split()]
b = [int(k) for k in input().split()]
c = [int(k) for k in input().split()]
d = [b[k] - c[k] for k in range(a[0])]
d.sort()
e = 0
while d[e] < 0 and e < a[0]:
e += 1
if e > a[1]:
print(sum(d[0:e])+sum(c))
else:
print(sum(d[0:a[1]])+sum(c))
``` | -1 | |
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like... | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input"... | 1,640,629,192 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 61 | 204,800 | n=int(input())
s=input()
c0=s.count("0")
c1=s.count("1")
print(c0+c1-2*min(c0,c1))
| Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Cons... | ```python
n=int(input())
s=input()
c0=s.count("0")
c1=s.count("1")
print(c0+c1-2*min(c0,c1))
``` | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.