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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
172 | B | Pseudorandom Sequence Period | PROGRAMMING | 1,200 | [
"*special",
"implementation",
"number theory"
] | null | null | Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way: (for *i*<=≥<=1). Here *a*, *b*, *m* are constants, fixed for the given realization of the pseudorandom numbers generator, *r*0 is the so-called *randseed* (t... | The single line of the input contains four integers *a*, *b*, *m* and *r*0 (1<=≤<=*m*<=≤<=105,<=0<=≤<=*a*,<=*b*<=≤<=1000,<=0<=≤<=*r*0<=<<=*m*), separated by single spaces. | Print a single integer — the period of the sequence. | [
"2 6 12 11\n",
"2 3 5 1\n",
"3 6 81 9\n"
] | [
"2\n",
"4\n",
"1\n"
] | The first sample is described above.
In the second sample the sequence is (starting from the first element): 0, 3, 4, 1, 0, 3, 4, 1, 0, ...
In the third sample the sequence is (starting from the first element): 33, 24, 78, 78, 78, 78, ... | 1,000 | [
{
"input": "2 6 12 11",
"output": "2"
},
{
"input": "2 3 5 1",
"output": "4"
},
{
"input": "3 6 81 9",
"output": "1"
},
{
"input": "10 11 12 3",
"output": "3"
},
{
"input": "4 4 5 4",
"output": "2"
},
{
"input": "0 1 6 5",
"output": "1"
},
{
... | 1,645,188,595 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 56 | 716 | 26,624,000 | import poplib
import string
import math
def main_function():
a, b, m, r_0 = [int(i) for i in input().split(" ")]
current_index = 1
hash_ = {r_0: 0}
while True:
r_0 = (a * r_0 + b) % m
if r_0 in hash_:
print(current_index - hash_[r_0])
break
e... | Title: Pseudorandom Sequence Period
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way: (for *i*<=≥<=1). Here *a*, *b*, *m* are con... | ```python
import poplib
import string
import math
def main_function():
a, b, m, r_0 = [int(i) for i in input().split(" ")]
current_index = 1
hash_ = {r_0: 0}
while True:
r_0 = (a * r_0 + b) % m
if r_0 in hash_:
print(current_index - hash_[r_0])
break
... | 3 | |
127 | A | Wasted Time | PROGRAMMING | 900 | [
"geometry"
] | null | null | Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
Mr. Scrooge's signature can be represented as a polyline ... | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* — integers *x**i* and *y**i*, separated by a space.
All points *A**i* are different. Th... | Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6. | [
"2 1\n0 0\n10 0\n",
"5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n",
"6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n"
] | [
"0.200000000",
"6.032163204",
"3.000000000"
] | none | 500 | [
{
"input": "2 1\n0 0\n10 0",
"output": "0.200000000"
},
{
"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0",
"output": "6.032163204"
},
{
"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0",
"output": "3.000000000"
},
{
"input": "10 95\n-20 -5\n2 -8\n14 13\n10 3\n17 11\n13 -12\n-6 11\n1... | 1,594,398,503 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 218 | 6,656,000 | import math
n,k=map(int,input().split())
prev1,prev2 = map(int,input().split())
total = 0
for i in range(1,n):
tmp1,tmp2=map(int,input().split())
total+=math.sqrt((tmp1-prev1)**2+(tmp2-prev2)**2)
prev1,prev2 = tmp1,tmp2
print(total*k*0.02) | Title: Wasted Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count ... | ```python
import math
n,k=map(int,input().split())
prev1,prev2 = map(int,input().split())
total = 0
for i in range(1,n):
tmp1,tmp2=map(int,input().split())
total+=math.sqrt((tmp1-prev1)**2+(tmp2-prev2)**2)
prev1,prev2 = tmp1,tmp2
print(total*k*0.02)
``` | 3 | |
336 | A | Vasily the Bear and Triangle | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he... | The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0). | Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points. | [
"10 5\n",
"-10 5\n"
] | [
"0 15 15 0\n",
"-15 0 0 15\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the first sample | 500 | [
{
"input": "10 5",
"output": "0 15 15 0"
},
{
"input": "-10 5",
"output": "-15 0 0 15"
},
{
"input": "20 -10",
"output": "0 -30 30 0"
},
{
"input": "-10 -1000000000",
"output": "-1000000010 0 0 -1000000010"
},
{
"input": "-1000000000 -1000000000",
"output": "-... | 1,596,875,859 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 248 | 20,172,800 | def f(l):
x,y = l
yy = y+x if y*x>0 else y-x
xx = x+y if y*x>0 else x-y
return [xx,0,0,yy] if xx<0 else [0,yy,xx,0]
l = list(map(int,input().split()))
print(f(l))
| Title: Vasily the Bear and Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate ... | ```python
def f(l):
x,y = l
yy = y+x if y*x>0 else y-x
xx = x+y if y*x>0 else x-y
return [xx,0,0,yy] if xx<0 else [0,yy,xx,0]
l = list(map(int,input().split()))
print(f(l))
``` | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,634,031,461 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | m,n = map(int , input().split())
if 1 <= m <= 16 and 1 <= n <= 16 and m < n:
print((m * n) // 2) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m,n = map(int , input().split())
if 1 <= m <= 16 and 1 <= n <= 16 and m < n:
print((m * n) // 2)
``` | 0 |
490 | E | Restoring Increasing Sequence | PROGRAMMING | 2,000 | [
"binary search",
"brute force",
"greedy",
"implementation"
] | null | null | Peter wrote on the board a strictly increasing sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.
Restore the the original sequence knowing digits remaining on the b... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the length of the sequence. Next *n* lines contain one element of the sequence each. Each element consists only of digits and question marks. No element starts from digit 0. Each element has length from 1 to 8 characters, inclusive. | If the answer exists, print in the first line "YES" (without the quotes). Next *n* lines must contain the sequence of positive integers — a possible variant of Peter's sequence. The found sequence must be strictly increasing, it must be transformed from the given one by replacing each question mark by a single digit. A... | [
"3\n?\n18\n1?\n",
"2\n??\n?\n",
"5\n12224\n12??5\n12226\n?0000\n?00000\n"
] | [
"YES\n1\n18\n19\n",
"NO\n",
"YES\n12224\n12225\n12226\n20000\n100000\n"
] | none | 2,000 | [
{
"input": "3\n?\n18\n1?",
"output": "YES\n1\n18\n19"
},
{
"input": "2\n??\n?",
"output": "NO"
},
{
"input": "5\n12224\n12??5\n12226\n?0000\n?00000",
"output": "YES\n12224\n12225\n12226\n20000\n100000"
},
{
"input": "10\n473883\n3499005\n4?74792\n58146??\n8?90593\n9203?71\n?3... | 1,689,224,739 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,867,200 | def check(a, b, n):
for i in range(n):
if not (b[i] == '?' or a[i] == b[i]):
return False
return True
def process(a, b):
for i in range(len(a)-1, -1, -1):
if ((b[i] == '?' and a[i] != '9') or (b[i] != '?' and a[i] < b[i])) and check(a, b, i):
for j in range(... | Title: Restoring Increasing Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Peter wrote on the board a strictly increasing sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each questi... | ```python
def check(a, b, n):
for i in range(n):
if not (b[i] == '?' or a[i] == b[i]):
return False
return True
def process(a, b):
for i in range(len(a)-1, -1, -1):
if ((b[i] == '?' and a[i] != '9') or (b[i] != '?' and a[i] < b[i])) and check(a, b, i):
for j... | -1 | |
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,620,907,260 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 374 | 21,708,800 | n = input()
a = input().split(" ")
m = input()
b = input().split(" ")
x = {}
for i in range(0, len(a)):
x[a[i]] = i;
Vasyla = 0
Petya = 0
for query in b:
index = x[query]
Vasyla += (len(a) - index)
Petya += (index + 1)
print(str(Petya) + " " + str(Vasyla))
| 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 = input()
a = input().split(" ")
m = input()
b = input().split(" ")
x = {}
for i in range(0, len(a)):
x[a[i]] = i;
Vasyla = 0
Petya = 0
for query in b:
index = x[query]
Vasyla += (len(a) - index)
Petya += (index + 1)
print(str(Petya) + " " + str(Vasyla))
... | 3 | |
278 | A | Circle Line | PROGRAMMING | 800 | [
"implementation"
] | null | null | The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) —... | Print a single number — the length of the shortest path between stations number *s* and *t*. | [
"4\n2 3 4 9\n1 3\n",
"4\n5 8 2 100\n4 1\n",
"3\n1 1 1\n3 1\n",
"3\n31 41 59\n1 1\n"
] | [
"5\n",
"15\n",
"1\n",
"0\n"
] | In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13.
In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15.
In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2.
In the fourth sample the numbers of st... | 500 | [
{
"input": "4\n2 3 4 9\n1 3",
"output": "5"
},
{
"input": "4\n5 8 2 100\n4 1",
"output": "15"
},
{
"input": "3\n1 1 1\n3 1",
"output": "1"
},
{
"input": "3\n31 41 59\n1 1",
"output": "0"
},
{
"input": "5\n16 13 10 30 15\n4 2",
"output": "23"
},
{
"inpu... | 1,563,475,180 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 248 | 0 | n = int(input())
d = list(map(int,input().split()))
s,t = map(int,input().split())
k = d[min(s,t)-1:max(s,t)-1]
print(min(sum(k),sum(d)-sum(k))) | Title: Circle Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd... | ```python
n = int(input())
d = list(map(int,input().split()))
s,t = map(int,input().split())
k = d[min(s,t)-1:max(s,t)-1]
print(min(sum(k),sum(d)-sum(k)))
``` | 3 | |
903 | C | Boxes Packing | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box. | Print the minimum possible number of visible boxes. | [
"3\n1 2 3\n",
"4\n4 2 4 3\n"
] | [
"1\n",
"2\n"
] | In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1. | 0 | [
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "4\n4 2 4 3",
"output": "2"
},
{
"input": "10\n58 58 58 58 58 58 58 58 58 58",
"output": "10"
},
{
"input": "10\n86 89 89 86 86 89 86 86 89 89",
"output": "5"
},
{
"input": "100\n981 288 186 186 292 876 341 288 98... | 1,666,766,078 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 409,600 | import sys
import sys
import threading
from math import *
from bisect import *
from collections import *
from heapq import *
from functools import lru_cache
def gl():return list(map(int, input().split()))
def gi():return int(input())
def gc():return input()
dd = defaultdict
dq = deque
hp = heappush
... | Title: Boxes Packing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not pu... | ```python
import sys
import sys
import threading
from math import *
from bisect import *
from collections import *
from heapq import *
from functools import lru_cache
def gl():return list(map(int, input().split()))
def gi():return int(input())
def gc():return input()
dd = defaultdict
dq = deque
hp = ... | 0 | |
810 | A | Straight <<A>> | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, wh... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. | Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. | [
"2 10\n8 9\n",
"3 5\n4 4 4\n"
] | [
"4",
"3"
] | Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforc... | 500 | [
{
"input": "2 10\n8 9",
"output": "4"
},
{
"input": "3 5\n4 4 4",
"output": "3"
},
{
"input": "3 10\n10 8 9",
"output": "3"
},
{
"input": "2 23\n21 23",
"output": "2"
},
{
"input": "5 10\n5 10 10 9 10",
"output": "7"
},
{
"input": "12 50\n18 10 26 22 2... | 1,559,495,761 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 108 | 0 | a,b = map(int,input().split())
t = list(map(int,input().split()))
k = sum(t)
print(int(2*(a*b-a/2-k))) | Title: Straight <<A>>
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
... | ```python
a,b = map(int,input().split())
t = list(map(int,input().split()))
k = sum(t)
print(int(2*(a*b-a/2-k)))
``` | 0 | |
660 | C | Hard Process | PROGRAMMING | 1,600 | [
"binary search",
"dp",
"two pointers"
] | null | null | You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*). | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*. | On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones.
On the second line print *n* integers *a**j* — the elements of the array *a* after the changes.
If there are multiple answers, you can print any one of them. | [
"7 1\n1 0 0 1 1 0 1\n",
"10 2\n1 0 0 1 0 1 0 1 0 1\n"
] | [
"4\n1 0 0 1 1 1 1\n",
"5\n1 0 0 1 1 1 1 1 0 1\n"
] | none | 0 | [
{
"input": "7 1\n1 0 0 1 1 0 1",
"output": "4\n1 0 0 1 1 1 1"
},
{
"input": "10 2\n1 0 0 1 0 1 0 1 0 1",
"output": "5\n1 0 0 1 1 1 1 1 0 1"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "7 0\n0 1 0 0 0 1 0",
"o... | 1,692,194,703 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 436 | 9,830,400 | def maximize_segment(n, k, arr):
left = 0
right = 0
max_length = 0
best_left = 0
num_zeroes = 0
while right < n:
if arr[right] == 0:
num_zeroes += 1
while num_zeroes > k:
if arr[left] == 0:
num_zeroes -= 1
left += ... | Title: Hard Process
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can ch... | ```python
def maximize_segment(n, k, arr):
left = 0
right = 0
max_length = 0
best_left = 0
num_zeroes = 0
while right < n:
if arr[right] == 0:
num_zeroes += 1
while num_zeroes > k:
if arr[left] == 0:
num_zeroes -= 1
... | 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,664,897,313 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 92 | 0 | import sys
def inp() : return sys.stdin.readline().strip()
def get_ints(): return map(int, inp().split())
def get_arr(): return list(map(int, inp().split()))
def get_int(): return int(inp())
s=inp()
t=inp()
j=0
for c in t:
if(c==s[j]):
j+=1
print(j+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
import sys
def inp() : return sys.stdin.readline().strip()
def get_ints(): return map(int, inp().split())
def get_arr(): return list(map(int, inp().split()))
def get_int(): return int(inp())
s=inp()
t=inp()
j=0
for c in t:
if(c==s[j]):
j+=1
print(j+1)
``` | 3 | |
906 | A | Shockers | PROGRAMMING | 1,600 | [
"implementation",
"strings"
] | null | null | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of actions Valentin did.
The next *n* lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. Th... | Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. | [
"5\n! abc\n. ad\n. b\n! cd\n? c\n",
"8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e\n",
"7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first test case after the first action it becomes clear that the selected letter is one of the following: *a*, *b*, *c*. After the second action we can note that the selected letter is not *a*. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is *c*, but Valentin p... | 500 | [
{
"input": "5\n! abc\n. ad\n. b\n! cd\n? c",
"output": "1"
},
{
"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e",
"output": "2"
},
{
"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h",
"output": "0"
},
{
"input": "4\n! abcd\n! cdef\n? d\n? c",
"o... | 1,516,738,784 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 5,632,000 | n=int(input())
d={}
a=[]
c=0
k=0
for i in range(n):
s=input().split()
if s[0]=='!' and c==0:
for j in s[1]:
if j not in d:
a.append(j)
d[j]=1
c=1
elif s[0]=='!' and c==1:
for j in a:
if j not in s[1]:
del d[j]
elif s[0]=='.':
for j in s[1]:
if j in d:
del d[j]
elif s[0]=='?' and i!... | Title: Shockers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected le... | ```python
n=int(input())
d={}
a=[]
c=0
k=0
for i in range(n):
s=input().split()
if s[0]=='!' and c==0:
for j in s[1]:
if j not in d:
a.append(j)
d[j]=1
c=1
elif s[0]=='!' and c==1:
for j in a:
if j not in s[1]:
del d[j]
elif s[0]=='.':
for j in s[1]:
if j in d:
del d[j]
elif s[0]==... | 0 | |
965 | A | Paper Airplanes | PROGRAMMING | 800 | [
"math"
] | null | null | To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people.... | The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. | Print a single integer — the minimum number of packs they should buy. | [
"5 3 2 3\n",
"5 3 100 1\n"
] | [
"4\n",
"5\n"
] | In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | 500 | [
{
"input": "5 3 2 3",
"output": "4"
},
{
"input": "5 3 100 1",
"output": "5"
},
{
"input": "10000 10000 1 1",
"output": "100000000"
},
{
"input": "1 1 10000 10000",
"output": "1"
},
{
"input": "300 300 21 23",
"output": "196"
},
{
"input": "300 2 37 51... | 1,524,715,276 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 93 | 7,065,600 | from math import ceil
k,n,s,p = map(int,input().split())
sheetsperperson = ceil(n / s)
print(ceil((k*sheetsperperson)/p)) | Title: Paper Airplanes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several p... | ```python
from math import ceil
k,n,s,p = map(int,input().split())
sheetsperperson = ceil(n / s)
print(ceil((k*sheetsperperson)/p))
``` | 3 | |
999 | C | Alphabetic Removals | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next ite... | The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove.
The second line contains the string $s$ consisting of $n$ lowercase Latin letters. | Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times.
If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). | [
"15 3\ncccaabababaccbc\n",
"15 9\ncccaabababaccbc\n",
"1 1\nu\n"
] | [
"cccbbabaccbc\n",
"cccccc\n",
""
] | none | 0 | [
{
"input": "15 3\ncccaabababaccbc",
"output": "cccbbabaccbc"
},
{
"input": "15 9\ncccaabababaccbc",
"output": "cccccc"
},
{
"input": "5 2\nzyzyx",
"output": "zzy"
},
{
"input": "4 3\nhack",
"output": "k"
},
{
"input": "4 3\nzzzz",
"output": "z"
},
{
"i... | 1,681,473,497 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 140 | 8,704,000 | a,b = map(int,input().split())
string = input()
for x in range(b):
string = string.replace(min(string),"",b-a+len(string))
if a-len(string)==b:
break
print(string) | Title: Alphabetic Removals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is... | ```python
a,b = map(int,input().split())
string = input()
for x in range(b):
string = string.replace(min(string),"",b-a+len(string))
if a-len(string)==b:
break
print(string)
``` | 3 | |
629 | A | Far Relative’s Birthday Cake | PROGRAMMING | 800 | [
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null | Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta... | In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. | Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. | [
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] | [
"4\n",
"9\n"
] | If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3) | 500 | [
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},... | 1,455,986,587 | 487 | Python 3 | OK | TESTS | 48 | 77 | 0 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
n = int(input())
a = [ 0 for i in range(n) ]
ans = 0
for i in range(n):
str = input()
m = 0
for j in range(n):
if str[j] == 'C':
m += 1
a[j] += 1
ans += m*(m-1)
start = time.time()
for i in range(n):
... | Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with s... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
n = int(input())
a = [ 0 for i in range(n) ]
ans = 0
for i in range(n):
str = input()
m = 0
for j in range(n):
if str[j] == 'C':
m += 1
a[j] += 1
ans += m*(m-1)
start = time.time()
for i in ... | 3 | |
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is... | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so ... | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "... | 1,596,165,552 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 7,270,400 | n=int(input())
l=[]
while(n):
h,m=map(int,input().split())
l.append([h,m])
n-=1
c=[1]
for i in range(len(l)):
if l.count(l[i])>1:
c.append(l.count(l[i]))
m=0
for i in range(len(c)):
if c[i]>m:
m=c[i]
print(m)
| Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l... | ```python
n=int(input())
l=[]
while(n):
h,m=map(int,input().split())
l.append([h,m])
n-=1
c=[1]
for i in range(len(l)):
if l.count(l[i])>1:
c.append(l.count(l[i]))
m=0
for i in range(len(c)):
if c[i]>m:
m=c[i]
print(m)
``` | 0 | |
1,006 | B | Polycarp's Practice | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"sortings"
] | null | null | Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cann... | The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$) — the number of problems and the number of days, respectively.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2000$) — difficulties of problems in Polycarp's list, in the order they are p... | In the first line of the output print the maximum possible total profit.
In the second line print exactly $k$ positive integers $t_1, t_2, \dots, t_k$ ($t_1 + t_2 + \dots + t_k$ must equal $n$), where $t_j$ means the number of problems Polycarp will solve during the $j$-th day in order to achieve the maximum possible ... | [
"8 3\n5 4 2 6 5 1 9 2\n",
"5 1\n1 1 1 1 1\n",
"4 2\n1 2000 2000 2\n"
] | [
"20\n3 2 3",
"1\n5\n",
"4000\n2 2\n"
] | The first example is described in the problem statement.
In the second example there is only one possible distribution.
In the third example the best answer is to distribute problems in the following way: $[1, 2000], [2000, 2]$. The total profit of this distribution is $2000 + 2000 = 4000$. | 0 | [
{
"input": "8 3\n5 4 2 6 5 1 9 2",
"output": "20\n4 1 3"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "1\n5"
},
{
"input": "4 2\n1 2000 2000 2",
"output": "4000\n2 2"
},
{
"input": "1 1\n2000",
"output": "2000\n1"
},
{
"input": "1 1\n1234",
"output": "1234\n1"
... | 1,623,914,633 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
if k == n:
print(sum(n))
print(' '.join(['1']*len(n)))
else:
a = sorted(a, reverse=True)
b = [(i, x) for i, x in enumerate(a)]
b = sorted(b, key=lambda x: x[1], reverse=True)
topk = b[:k]
topk_idxs = [i fo... | Title: Polycarp's Practice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least... | ```python
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
if k == n:
print(sum(n))
print(' '.join(['1']*len(n)))
else:
a = sorted(a, reverse=True)
b = [(i, x) for i, x in enumerate(a)]
b = sorted(b, key=lambda x: x[1], reverse=True)
topk = b[:k]
topk_id... | 0 | |
439 | B | Devu, the Dumb Guy | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is *x* hours. In other ... | The first line will contain two space separated integers *n*, *x* (1<=≤<=*n*,<=*x*<=≤<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105). | Output a single integer representing the answer to the problem. | [
"2 3\n4 1\n",
"4 2\n5 1 2 1\n",
"3 3\n1 1 1\n"
] | [
"11\n",
"10\n",
"6\n"
] | Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 ... | 1,000 | [
{
"input": "2 3\n4 1",
"output": "11"
},
{
"input": "4 2\n5 1 2 1",
"output": "10"
},
{
"input": "3 3\n1 1 1",
"output": "6"
},
{
"input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3",
"output": "65"
},
{
"input": "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3... | 1,626,244,047 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 155 | 14,438,400 | from sys import *
from math import *
#from collections import Counter
input = lambda:stdin.readline()
int_arr = lambda : list(map(int,stdin.readline().strip().split()))
str_arr = lambda :list(map(str,stdin.readline().split()))
get_str = lambda : map(str,stdin.readline().strip().split())
get_int = lambda: map(... | Title: Devu, the Dumb Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject co... | ```python
from sys import *
from math import *
#from collections import Counter
input = lambda:stdin.readline()
int_arr = lambda : list(map(int,stdin.readline().strip().split()))
str_arr = lambda :list(map(str,stdin.readline().split()))
get_str = lambda : map(str,stdin.readline().strip().split())
get_int = la... | 3 | |
501 | A | Contest | PROGRAMMING | 900 | [
"implementation"
] | null | null | Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ... | The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180).
It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round). | Output on a single line:
"Misha" (without the quotes), if Misha got more points than Vasya.
"Vasya" (without the quotes), if Vasya got more points than Misha.
"Tie" (without the quotes), if both of them got the same number of points. | [
"500 1000 20 30\n",
"1000 1000 1 1\n",
"1500 1000 176 177\n"
] | [
"Vasya\n",
"Tie\n",
"Misha\n"
] | none | 500 | [
{
"input": "500 1000 20 30",
"output": "Vasya"
},
{
"input": "1000 1000 1 1",
"output": "Tie"
},
{
"input": "1500 1000 176 177",
"output": "Misha"
},
{
"input": "1500 1000 74 177",
"output": "Misha"
},
{
"input": "750 2500 175 178",
"output": "Vasya"
},
{
... | 1,674,301,833 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | a,b,c,d = map(int, input().split())
def point(p,t):
return int(max((.1*3*p), (p-(.004*t*p))))
if point(a,c) == point(b,d):
print ("Tie")
else: print(["Misha","Vasya"][point(b,d)>point(a,c)])
| Title: Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved t... | ```python
a,b,c,d = map(int, input().split())
def point(p,t):
return int(max((.1*3*p), (p-(.004*t*p))))
if point(a,c) == point(b,d):
print ("Tie")
else: print(["Misha","Vasya"][point(b,d)>point(a,c)])
``` | 3 | |
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "Y... | 1,589,650,971 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 218 | 6,656,000 | s1 = input()
s2 = input()
count = 0
flag = True
if len(s1)!=len(s2):
flag = False
for i in range(len(s1)):
if s1[i]!=s2[i]:
count+=1
if count>2:
flag = False
if flag:
print('YES')
else:
print('NO')
| Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ... | ```python
s1 = input()
s2 = input()
count = 0
flag = True
if len(s1)!=len(s2):
flag = False
for i in range(len(s1)):
if s1[i]!=s2[i]:
count+=1
if count>2:
flag = False
if flag:
print('YES')
else:
print('NO')
``` | 0 | |
298 | A | Snow Footprints | PROGRAMMING | 1,300 | [
"greedy",
"implementation"
] | null | null | There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000).
The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's gu... | Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them. | [
"9\n..RRLL...\n",
"11\n.RRRLLLLL..\n"
] | [
"3 4\n",
"7 5\n"
] | The first test sample is the one in the picture. | 500 | [
{
"input": "11\n.RRRLLLLL..",
"output": "7 5"
},
{
"input": "4\n.RL.",
"output": "3 2"
},
{
"input": "3\n.L.",
"output": "2 1"
},
{
"input": "3\n.R.",
"output": "2 3"
}
] | 1,657,943,873 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n=int(input())
a=input()
if(a.count('R')==0):
s=a.find('L')+1
elif(a.count('L')==0):
s=a.find('R')+1
else:
s=min(a.find('L'),a.find('R'))+1
t=s
for i in a:
if(i=='R'):
t= t + 1
elif(i=='L'):
t= t - 1
if(t<s):
t=s
print(s,t)
| Title: Snow Footprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *... | ```python
n=int(input())
a=input()
if(a.count('R')==0):
s=a.find('L')+1
elif(a.count('L')==0):
s=a.find('R')+1
else:
s=min(a.find('L'),a.find('R'))+1
t=s
for i in a:
if(i=='R'):
t= t + 1
elif(i=='L'):
t= t - 1
if(t<s):
t=s
print(s,t)
``` | 0 | |
665 | B | Shopping | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.
The store contains *k* items. *n* customers have already used the above service. Each user paid for *m* items. Let *a**ij* denote the *j*-th item in the *i*-th person's orde... | The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*k*<=≤<=100,<=1<=≤<=*m*<=≤<=*k*) — the number of users, the number of items each user wants to buy and the total number of items at the market.
The next line contains *k* distinct integers *p**l* (1<=≤<=*p**l*<=≤<=*k*) denoting the initial positions ... | Print the only integer *t* — the total time needed for Ayush to process all the orders. | [
"2 2 5\n3 4 1 2 5\n1 5\n3 1\n"
] | [
"14\n"
] | Customer 1 wants the items 1 and 5.
*pos*(1) = 3, so the new positions are: [1, 3, 4, 2, 5].
*pos*(5) = 5, so the new positions are: [5, 1, 3, 4, 2].
Time taken for the first customer is 3 + 5 = 8.
Customer 2 wants the items 3 and 1.
*pos*(3) = 3, so the new positions are: [3, 5, 1, 4, 2].
*pos*(1) = 3, so the ne... | 0 | [
{
"input": "2 2 5\n3 4 1 2 5\n1 5\n3 1",
"output": "14"
},
{
"input": "4 4 4\n1 2 3 4\n3 4 2 1\n4 3 2 1\n4 1 2 3\n4 1 2 3",
"output": "59"
},
{
"input": "1 1 1\n1\n1",
"output": "1"
},
{
"input": "10 1 100\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 8... | 1,689,653,267 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689653267.534639")# 1689653267.5346591 | Title: Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.
The store contains *k* items. *n* customers have already used the above service... | ```python
print("_RANDOM_GUESS_1689653267.534639")# 1689653267.5346591
``` | 0 | |
362 | B | Petya and Staircases | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.
No... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty s... | Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO". | [
"10 5\n2 4 8 3 6\n",
"10 5\n2 4 5 7 9\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "10 5\n2 4 8 3 6",
"output": "NO"
},
{
"input": "10 5\n2 4 5 7 9",
"output": "YES"
},
{
"input": "10 9\n2 3 4 5 6 7 8 9 10",
"output": "NO"
},
{
"input": "5 2\n4 5",
"output": "NO"
},
{
"input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37",
"outp... | 1,663,083,819 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 62 | 1,228,800 | n,m=map(int,input().split())
# matrix=[list(map(int,input().split())) for i in range(m)]
arr=list(map(int,input().split()))
start=1
arr.sort()
fin=arr[-1]
sta=arr[0]
if sta==1 or fin==n or sta-1>3:
print("NO")
else:
cnt=0
for i in range(1,m):
if (arr[i]-arr[i-1])==1:
cnt+=... | Title: Petya and Staircases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump o... | ```python
n,m=map(int,input().split())
# matrix=[list(map(int,input().split())) for i in range(m)]
arr=list(map(int,input().split()))
start=1
arr.sort()
fin=arr[-1]
sta=arr[0]
if sta==1 or fin==n or sta-1>3:
print("NO")
else:
cnt=0
for i in range(1,m):
if (arr[i]-arr[i-1])==1:
... | 0 | |
729 | B | Spotlights | PROGRAMMING | 1,200 | [
"dp",
"implementation"
] | null | null | Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of t... | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell ... | Print one integer — the number of good positions for placing the spotlight. | [
"2 4\n0 1 0 0\n1 0 1 0\n",
"4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n"
] | [
"9\n",
"20\n"
] | In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and... | 1,000 | [
{
"input": "2 4\n0 1 0 0\n1 0 1 0",
"output": "9"
},
{
"input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0",
"output": "20"
},
{
"input": "1 5\n1 1 0 0 0",
"output": "3"
},
{
"input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0",
"output": "20"
},
{
"input": "3 ... | 1,653,097,945 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 5,734,400 | n,m = map(int,input().split())
values, a_i, a_j = [],{},{}
for _ in range(n):
values.append(input().split())
total = 0
for i in range(n):
for j in range(m):
sj = a_j.get(j)
si = a_i.get(i)
if values[i][j] == '1':
if sj is None:
a_j[j] = 1
... | Title: Spotlights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to pl... | ```python
n,m = map(int,input().split())
values, a_i, a_j = [],{},{}
for _ in range(n):
values.append(input().split())
total = 0
for i in range(n):
for j in range(m):
sj = a_j.get(j)
si = a_i.get(i)
if values[i][j] == '1':
if sj is None:
a_j[j] ... | 0 | |
518 | B | Tanya and Postcard | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"strings"
] | null | null | Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s... | The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |*a*| means the ... | Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message. | [
"AbC\nDCbA\n",
"ABC\nabc\n",
"abacaba\nAbaCaBA\n"
] | [
"3 0\n",
"0 3\n",
"3 4\n"
] | none | 1,000 | [
{
"input": "AbC\nDCbA",
"output": "3 0"
},
{
"input": "ABC\nabc",
"output": "0 3"
},
{
"input": "abacaba\nAbaCaBA",
"output": "3 4"
},
{
"input": "zzzzz\nZZZZZ",
"output": "0 5"
},
{
"input": "zzzZZZ\nZZZzzZ",
"output": "5 1"
},
{
"input": "abcdefghijk... | 1,579,823,643 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 155 | 307,200 | from collections import *
s, t = deque(input()), input()
mem, a1, a2 = Counter(t), 0, 0
for i in range(len(s)):
if mem[s[0]]:
a1 += 1
mem[s[0]] -= 1
s.popleft()
else:
s.rotate(-1)
# print(s)
for i in s:
if i.isupper() and mem[i.lower()]:
a2 += 1
... | Title: Tanya and Postcard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she f... | ```python
from collections import *
s, t = deque(input()), input()
mem, a1, a2 = Counter(t), 0, 0
for i in range(len(s)):
if mem[s[0]]:
a1 += 1
mem[s[0]] -= 1
s.popleft()
else:
s.rotate(-1)
# print(s)
for i in s:
if i.isupper() and mem[i.lower()]:
a2 ... | 0 | |
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i... | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "64009798... | 1,602,245,003 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 124 | 307,200 | def gcd(a,b):
if b==0:
return a
return gcd(b,a%b)
l,r=map(int,input().split())
if r-l==0 or r-l==1:
print(-1)
else:
if r-l==2:
if l%2==0:
print(l,l+1,r)
else:
print(-1)
elif r-l > 2:
if l%2==0:
print(l,l+1,l+2)
... | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different st... | ```python
def gcd(a,b):
if b==0:
return a
return gcd(b,a%b)
l,r=map(int,input().split())
if r-l==0 or r-l==1:
print(-1)
else:
if r-l==2:
if l%2==0:
print(l,l+1,r)
else:
print(-1)
elif r-l > 2:
if l%2==0:
print(l,l+1,l... | 3 | |
485 | B | Valuable Resources | PROGRAMMING | 1,300 | [
"brute force",
"greedy"
] | null | null | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes.... | The first line of the input contains number *n* — the number of mines on the map (2<=≤<=*n*<=≤<=1000). Each of the next *n* lines contains a pair of integers *x**i* and *y**i* — the coordinates of the corresponding mine (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109). All points are pairwise distinct. | Print the minimum area of the city that can cover all the mines with valuable resources. | [
"2\n0 0\n2 2\n",
"2\n0 0\n0 3\n"
] | [
"4\n",
"9\n"
] | none | 500 | [
{
"input": "2\n0 0\n2 2",
"output": "4"
},
{
"input": "2\n0 0\n0 3",
"output": "9"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "3\n2 2\n1 1\n3 3",
"output": "4"
},
{
"input": "3\n3 1\n1 3\n2 2",
"output": "4"
},
{
"input": "3\n0 1\n1 0\n2 ... | 1,415,207,551 | 2,551 | Python 3 | RUNTIME_ERROR | PRETESTS | 0 | 46 | 0 | #fin = open("input.txt")
n = int(input())
n = int(fin.readline())
X1, Y1, X2, Y2 = 10 ** 9 * 2, 10 ** 9 * 2, -10 ** 9 * 2, -10 ** 9 * 2
for i in range(n):
x, y = map(int, input().split())
#x, y = map(int, fin.readline().split())
X1, Y1, X2, Y2 = min(X1, x), min(Y1, y), max(X2, x), max(Y2, y)
print(max((X2 - X1), (Y2... | Title: Valuable Resources
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. Th... | ```python
#fin = open("input.txt")
n = int(input())
n = int(fin.readline())
X1, Y1, X2, Y2 = 10 ** 9 * 2, 10 ** 9 * 2, -10 ** 9 * 2, -10 ** 9 * 2
for i in range(n):
x, y = map(int, input().split())
#x, y = map(int, fin.readline().split())
X1, Y1, X2, Y2 = min(X1, x), min(Y1, y), max(X2, x), max(Y2, y)
print(max((X2 ... | -1 | |
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should cons... | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letter... | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcde... | 1,627,581,686 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 61 | 6,963,200 | n,k=map(int,input().split())
al="abcdefghijklmnopqrstuvwxyz"
ch=k
pas=""
j=0
for i in range(len(al)):
if len (pas)< n:
if ch:
pas=pas+al[i]
ch=ch-1
else:
pas=pas+pas[j]
if j<len(pas)-1:
j=j+1
else:
... | Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the foll... | ```python
n,k=map(int,input().split())
al="abcdefghijklmnopqrstuvwxyz"
ch=k
pas=""
j=0
for i in range(len(al)):
if len (pas)< n:
if ch:
pas=pas+al[i]
ch=ch-1
else:
pas=pas+pas[j]
if j<len(pas)-1:
j=j+1
else:
... | 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,668,514,648 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 1 | 61 | 2,867,200 | def oi(): return int(input())
def os(): return input().rstrip()
def mi(): return list(map(int, input().split()))
# import sys
# input = sys.stdin.readline
# import sys
# sys.setrecursionlimit(10**8)
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
input_count = 0
S = os()
S = list(S)
M ... | 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
def oi(): return int(input())
def os(): return input().rstrip()
def mi(): return list(map(int, input().split()))
# import sys
# input = sys.stdin.readline
# import sys
# sys.setrecursionlimit(10**8)
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
input_count = 0
S = os()
S = lis... | -1 | |
812 | A | Sagheer and Crossroads | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane... | The input consists of four lines with each line describing a road part given in a counter-clockwise order.
Each line contains four integers *l*, *s*, *r*, *p* — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light. | On a single line, print "YES" if an accident is possible, and "NO" otherwise. | [
"1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n",
"0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n",
"1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.
In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur. | 500 | [
{
"input": "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
... | 1,497,028,042 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 307,200 | l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l3=list(map(int,input().split()))
l4=list(map(int,input().split()))
count=0
if(l1[3]==1 and (l1[0]==1 or l1[1]==1 or l1[2]==1 or l2[0]==1 or l3[1]==1 or l4[2]==1)):
count=1
elif(l2[3]==1 and (l1[2]==1 or l2[0]==1 or l2[1]==1 or l2[2]==1 or l... | Title: Sagheer and Crossroads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 l... | ```python
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l3=list(map(int,input().split()))
l4=list(map(int,input().split()))
count=0
if(l1[3]==1 and (l1[0]==1 or l1[1]==1 or l1[2]==1 or l2[0]==1 or l3[1]==1 or l4[2]==1)):
count=1
elif(l2[3]==1 and (l1[2]==1 or l2[0]==1 or l2[1]==1 or l2[... | 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,541,492,752 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 109 | 0 | w=list(input())
s=len(w)
for i in range(s):
if w[i]=='h':
a=i
break
for i in range(s):
if w[i]=='e':
b=i
break
for i in range(s):
if w[i]=='l':
c=i
w.remove("l")
break
for i in range(s-1):
if w[i]=="l":
d=i
break
... | 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
w=list(input())
s=len(w)
for i in range(s):
if w[i]=='h':
a=i
break
for i in range(s):
if w[i]=='e':
b=i
break
for i in range(s):
if w[i]=='l':
c=i
w.remove("l")
break
for i in range(s-1):
if w[i]=="l":
d=i
... | 0 |
907 | B | Tic-Tac-Toe | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.
The game is played on the following field.
Players are making moves by turns. At first move a player can put his chip in any cell of any small field... | First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "... | Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified. | [
"... ... ...\n... ... ...\n... ... ...\n\n... ... ...\n... ... ...\n... x.. ...\n\n... ... ...\n... ... ...\n... ... ...\n6 4\n",
"xoo x.. x..\nooo ... ...\nooo ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n7 4\n",
"o.. ... ...\n... ... ...\n... ... ...\n\n... xxx ..... | [
"... ... ... \n... ... ... \n... ... ... \n\n... ... ... \n... ... ... \n... x.. ... \n\n!!! ... ... \n!!! ... ... \n!!! ... ... \n\n",
"xoo x!! x!! \nooo !!! !!! \nooo !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! \n\n",
"o!! !!! !!! \n!!! !!! !!! \n!!! !!! !!!... | In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field.
In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second pla... | 1,000 | [
{
"input": "... ... ...\n... ... ...\n... ... ...\n\n... ... ...\n... ... ...\n... x.. ...\n\n... ... ...\n... ... ...\n... ... ...\n6 4",
"output": "... ... ... \n... ... ... \n... ... ... \n\n... ... ... \n... ... ... \n... x.. ... \n\n!!! ... ... \n!!! ... ... \n!!! ... ... "
},
{
"input": "xoo x... | 1,614,697,222 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 93 | 819,200 | import itertools
import bisect
import collections
import math
import sys
from collections import *
import os
import sys
from io import BytesIO, IOBase
ii = lambda: int(input())
lmii = lambda: list(map(int, input().split()))
li = lambda: list(input())
mii = lambda: map(int, input().split())
msi = la... | Title: Tic-Tac-Toe
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.
The game is played on the following field.
Players ... | ```python
import itertools
import bisect
import collections
import math
import sys
from collections import *
import os
import sys
from io import BytesIO, IOBase
ii = lambda: int(input())
lmii = lambda: list(map(int, input().split()))
li = lambda: list(input())
mii = lambda: map(int, input().split())... | 0 | |
960 | C | Subsequence Counting | PROGRAMMING | 1,700 | [
"bitmasks",
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size *n* has 2*n*<=-<=1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence <=-<= Minimum_element_of_su... | The only line of input consists of two space separated integers *X* and *d* (1<=≤<=*X*,<=*d*<=≤<=109). | Output should consist of two lines.
First line should contain a single integer *n* (1<=≤<=*n*<=≤<=10<=000)— the number of integers in the final array.
Second line should consist of *n* space separated integers — *a*1,<=*a*2,<=... ,<=*a**n* (1<=≤<=*a**i*<=<<=1018).
If there is no answer, print a single integer -1.... | [
"10 5\n",
"4 2\n"
] | [
"6\n5 50 7 15 6 100",
"4\n10 100 1000 10000"
] | In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence ≥ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Simil... | 1,500 | [
{
"input": "10 5",
"output": "6\n1 1 1 7 13 19 "
},
{
"input": "4 2",
"output": "3\n1 1 4 "
},
{
"input": "4 1",
"output": "3\n1 1 3 "
},
{
"input": "1 1",
"output": "1\n1 "
},
{
"input": "63 1",
"output": "21\n1 1 1 1 1 3 3 3 3 5 5 5 7 7 9 11 13 15 17 19 21 "... | 1,574,098,615 | 2,147,483,647 | PyPy 3 | OK | TESTS | 63 | 171 | 512,000 | from math import *
from collections import *
import sys
sys.setrecursionlimit(10**9)
l = [2**i-1 for i in range(40)]
x,d = map(int,input().split())
a = []
ct = 1
while(x != 0):
for i in range(39):
if l[i+1] > x:
ind = i
break
x -= l[ind]
for i in range(ind):
a.append(ct)
ct += d
print(len... | Title: Subsequence Counting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size *n* has 2*n*<=-<=1 non-empty subsequences in it.
Pikachu being mischievous as he alway... | ```python
from math import *
from collections import *
import sys
sys.setrecursionlimit(10**9)
l = [2**i-1 for i in range(40)]
x,d = map(int,input().split())
a = []
ct = 1
while(x != 0):
for i in range(39):
if l[i+1] > x:
ind = i
break
x -= l[ind]
for i in range(ind):
a.append(ct)
ct += d
... | 3 | |
498 | A | Crazy Town | PROGRAMMING | 1,700 | [
"geometry"
] | null | null | Crazy Town is a plane on which there are *n* infinite line roads. Each road is defined by the equation *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, where *a**i* and *b**i* are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We ... | The first line contains two space-separated integers *x*1, *y*1 (<=-<=106<=≤<=*x*1,<=*y*1<=≤<=106) — the coordinates of your home.
The second line contains two integers separated by a space *x*2, *y*2 (<=-<=106<=≤<=*x*2,<=*y*2<=≤<=106) — the coordinates of the university you are studying at.
The third line contains a... | Output the answer to the problem. | [
"1 1\n-1 -1\n2\n0 1 0\n1 0 0\n",
"1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3\n"
] | [
"2\n",
"2\n"
] | Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors): | 500 | [
{
"input": "1 1\n-1 -1\n2\n0 1 0\n1 0 0",
"output": "2"
},
{
"input": "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3",
"output": "2"
},
{
"input": "841746 527518\n595261 331297\n10\n-946901 129987 670374\n-140388 -684770 309555\n-302589 415564 -387435\n-565799 -72069 -395358\n-523453 -511446 85489... | 1,538,022,605 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 140 | 0 | if __name__ == '__main__':
xhome, yhome = [int(x) for x in input().split()]
xuni, yuni = [int(x) for x in input().split()]
n_roads = int(input())
n_steps = 0
for i in range(n_roads):
a, b, c = [int(x) for x in input().split()]
hline = (a*xhome) + (b*yhome) + c
uline = (a*xuni... | Title: Crazy Town
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Crazy Town is a plane on which there are *n* infinite line roads. Each road is defined by the equation *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, where *a**i* and *b**i* are not both equal to the zero. The roads divide the pl... | ```python
if __name__ == '__main__':
xhome, yhome = [int(x) for x in input().split()]
xuni, yuni = [int(x) for x in input().split()]
n_roads = int(input())
n_steps = 0
for i in range(n_roads):
a, b, c = [int(x) for x in input().split()]
hline = (a*xhome) + (b*yhome) + c
uline... | 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,697,143,895 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | from collections import *
def solve(s):
if s=='hello':
return 'YES'
elif len(s)>5 :
st=set()
sts=''
flag=0
for i in s:
if i in st:
pass
else:
st.add(i)
if i=='l' and flag==0:
... | 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
from collections import *
def solve(s):
if s=='hello':
return 'YES'
elif len(s)>5 :
st=set()
sts=''
flag=0
for i in s:
if i in st:
pass
else:
st.add(i)
if i=='l' and flag==0:
... | 0 |
712 | A | Memory and Crow | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. | Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. | [
"5\n6 -4 8 -2 3\n",
"5\n3 -2 -1 5 6\n"
] | [
"2 4 6 1 3 \n",
"1 -3 4 11 6 \n"
] | In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, ... | 500 | [
{
"input": "5\n6 -4 8 -2 3",
"output": "2 4 6 1 3 "
},
{
"input": "5\n3 -2 -1 5 6",
"output": "1 -3 4 11 6 "
},
{
"input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10",
"output": "11 530 469 -86 -86 -127 -87 -11 22 10 "
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0 0... | 1,474,898,557 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 202 | 10,035,200 | n = int(input())
al = list(map(int, input().split()))+[0]
bl = []
# Bi = Ai + Ai+1
for i in range(n):
bl+=[str(al[i]+al[i+1])]
print(" ".join(bl))
| Title: Memory and Crow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow... | ```python
n = int(input())
al = list(map(int, input().split()))+[0]
bl = []
# Bi = Ai + Ai+1
for i in range(n):
bl+=[str(al[i]+al[i+1])]
print(" ".join(bl))
``` | 3 | |
930 | D | Game with Tokens | PROGRAMMING | 2,500 | [
"data structures",
"games",
"implementation"
] | null | null | Consider the following game for two players. There is one white token and some number of black tokens. Each token is placed on a plane in a point with integer coordinates *x* and *y*.
The players take turn making moves, white starts. On each turn, a player moves all tokens of their color by 1 to up, down, left or righ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of black points.
The (*i*<=+<=1)-th line contains two integers *x**i*, *y**i* (<=-<=105<=≤<=*x**i*,<=*y**i*,<=<=≤<=105) — the coordinates of the point where the *i*-th black token is initially located.
It is guaranteed that initial position... | Print the number of points where the white token can be located initially, such that if both players play optimally, the black player wins. | [
"4\n-2 -1\n0 1\n0 -3\n2 -1\n",
"4\n-2 0\n-1 1\n0 -2\n1 -1\n",
"16\n2 1\n1 2\n-1 1\n0 1\n0 0\n1 1\n2 -1\n2 0\n1 0\n-1 -1\n1 -1\n2 2\n0 -1\n-1 0\n0 2\n-1 2\n"
] | [
"4\n",
"2\n",
"4\n"
] | In the first and second examples initial positions of black tokens are shown with black points, possible positions of the white token (such that the black player wins) are shown with white points.
The first example: <img class="tex-graphics" src="https://espresso.codeforces.com/5054b8d2df2fac92c92f96fae82d21c365d12983... | 2,000 | [
{
"input": "4\n-2 -1\n0 1\n0 -3\n2 -1",
"output": "4"
},
{
"input": "4\n-2 0\n-1 1\n0 -2\n1 -1",
"output": "2"
},
{
"input": "16\n2 1\n1 2\n-1 1\n0 1\n0 0\n1 1\n2 -1\n2 0\n1 0\n-1 -1\n1 -1\n2 2\n0 -1\n-1 0\n0 2\n-1 2",
"output": "4"
},
{
"input": "1\n1 2",
"output": "0"
... | 1,531,142,175 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 109 | 0 | from sys import*
from itertools import*
def solve(a):
inf = 1001001001
C = 400010
lmn = [inf] * 400010
lmx = [-inf] * 400010
for x, y in a:
x = (x - 1) / 2 + 100005
if lmn[x] > y:
lmn[x] = y
if lmx[x] < y:
lmx[x] = y
rmn = lmn[:]
... | Title: Game with Tokens
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the following game for two players. There is one white token and some number of black tokens. Each token is placed on a plane in a point with integer coordinates *x* and *y*.
The players take turn making move... | ```python
from sys import*
from itertools import*
def solve(a):
inf = 1001001001
C = 400010
lmn = [inf] * 400010
lmx = [-inf] * 400010
for x, y in a:
x = (x - 1) / 2 + 100005
if lmn[x] > y:
lmn[x] = y
if lmx[x] < y:
lmx[x] = y
rmn = lm... | -1 | |
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,644,247,569 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 15,769,600 | a,b,c = map(int, input().split())
n = int(input())
l = list(map(int, input().split()))
ans = 0
for j in range(b+1,c):
ans += l.count(j)
print(ans)
| 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
a,b,c = map(int, input().split())
n = int(input())
l = list(map(int, input().split()))
ans = 0
for j in range(b+1,c):
ans += l.count(j)
print(ans)
``` | 0 | |
94 | B | Friends | PROGRAMMING | 1,300 | [
"graphs",
"implementation",
"math"
] | B. Friends | 1 | 256 | One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something.
The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people"
Igor just c... | The first line contains an integer *m* (0<=≤<=*m*<=≤<=10), which is the number of relations of acquaintances among the five friends of Igor's.
Each of the following *m* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=5;*a**i*<=≠<=*b**i*), where (*a**i*,<=*b**i*) is a pair of acquainted people.... | Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". | [
"4\n1 3\n2 3\n1 4\n5 3\n",
"5\n1 2\n2 3\n3 4\n4 5\n5 1\n"
] | [
"WIN\n",
"FAIL\n"
] | none | 1,000 | [
{
"input": "4\n1 3\n2 3\n1 4\n5 3",
"output": "WIN"
},
{
"input": "5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "FAIL"
},
{
"input": "1\n4 3",
"output": "WIN"
},
{
"input": "6\n1 3\n2 3\n1 2\n5 3\n4 2\n4 5",
"output": "WIN"
},
{
"input": "2\n1 3\n2 5",
"output": "WI... | 1,637,080,097 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | import sys
import math
from sys import stdin, stdout
# TAKE INPUT
def get_ints_in_variables():
return map(int, sys.stdin.readline().strip().split())
def get_int(): return int(input())
def get_ints_in_list(): return list(
map(int, sys.stdin.readline().strip().split()))
def get_list_of_list(n): return ... | Title: Friends
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something.
The following statement caught his attention: "Among any six people there are ei... | ```python
import sys
import math
from sys import stdin, stdout
# TAKE INPUT
def get_ints_in_variables():
return map(int, sys.stdin.readline().strip().split())
def get_int(): return int(input())
def get_ints_in_list(): return list(
map(int, sys.stdin.readline().strip().split()))
def get_list_of_list(n... | 0 |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,640,286,703 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 61 | 0 | n1=input()
n2=input()
c=[str(int(n1[i])^int(n2[i])) for i in range(len(n1))]
c="".join(c)
print(c) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
n1=input()
n2=input()
c=[str(int(n1[i])^int(n2[i])) for i in range(len(n1))]
c="".join(c)
print(c)
``` | 3.98475 |
110 | A | Nearly Lucky Number | PROGRAMMING | 800 | [
"implementation"
] | A. Nearly Lucky Number | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d... | The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). | [
"40047\n",
"7747774\n",
"1000000000000000000\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | 500 | [
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
... | 1,699,172,766 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | def isLuckyNum(s):
for ch in s:
if ch not in ['4','7']:
return "NO"
return "YES"
s = input()
print(isLuckyNum(s)) | Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
def isLuckyNum(s):
for ch in s:
if ch not in ['4','7']:
return "NO"
return "YES"
s = input()
print(isLuckyNum(s))
``` | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | Alice and Bob begin their day with a quick game. They first choose a starting number *X*0<=≥<=3 and try to reach one million by the process described below.
Alice goes first and then they take alternating turns. In the *i*-th turn, the player whose turn it is selects a prime number smaller than the current number, an... | The input contains a single integer *X*2 (4<=≤<=*X*2<=≤<=106). It is guaranteed that the integer *X*2 is composite, that is, is not prime. | Output a single integer — the minimum possible *X*0. | [
"14\n",
"20\n",
"8192\n"
] | [
"6\n",
"15\n",
"8191\n"
] | In the first test, the smallest possible starting number is *X*<sub class="lower-index">0</sub> = 6. One possible course of the game is as follows:
- Alice picks prime 5 and announces *X*<sub class="lower-index">1</sub> = 10 - Bob picks prime 7 and announces *X*<sub class="lower-index">2</sub> = 14.
In the second ... | 0 | [
{
"input": "14",
"output": "6"
},
{
"input": "20",
"output": "15"
},
{
"input": "8192",
"output": "8191"
},
{
"input": "1000000",
"output": "998677"
},
{
"input": "959806",
"output": "239958"
},
{
"input": "1452",
"output": "1206"
},
{
"inp... | 1,520,771,769 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 858 | 30,105,600 | # -*- coding: utf - 8 -*-
"""""""""""""""""""""""""""""""""""""""""""""
| author: mr.math - Hakimov Rahimjon |
| e-mail: [email protected] |
| created: 10.03.2018 20:50 |
"""""""""""""""""""""""""""""""""""""""""""""
# inp = open("input.txt", "r"); input = inp.readline; out = op... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice and Bob begin their day with a quick game. They first choose a starting number *X*0<=≥<=3 and try to reach one million by the process described below.
Alice goes first and then they take alternating turns. In the *i*-th tu... | ```python
# -*- coding: utf - 8 -*-
"""""""""""""""""""""""""""""""""""""""""""""
| author: mr.math - Hakimov Rahimjon |
| e-mail: [email protected] |
| created: 10.03.2018 20:50 |
"""""""""""""""""""""""""""""""""""""""""""""
# inp = open("input.txt", "r"); input = inp.readline... | 3 | |
84 | A | Toy Army | PROGRAMMING | 900 | [
"math",
"number theory"
] | A. Toy Army | 2 | 256 | The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current playe... | The input data consist of a single integer *n* (2<=≤<=*n*<=≤<=108, *n* is even). Please note that before the game starts there are 2*n* soldiers on the fields. | Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns. | [
"2\n",
"4\n"
] | [
"3\n",
"6\n"
] | The first sample test:
1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1.
2) Arcady's soldier 2 shoots at Valera's soldier 1.
3) Valera's soldier 1 shoots at Arcady's soldier 2.
There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2. | 500 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "6"
},
{
"input": "6",
"output": "9"
},
{
"input": "8",
"output": "12"
},
{
"input": "10",
"output": "15"
},
{
"input": "140",
"output": "210"
},
{
"input": "500",
"output": "75... | 1,570,519,478 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 216 | 0 | n=int(input())
r=2*n-(n//2)
print(r) | Title: Toy Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on t... | ```python
n=int(input())
r=2*n-(n//2)
print(r)
``` | 3.946 |
166 | E | Tetrahedron | PROGRAMMING | 1,500 | [
"dp",
"math",
"matrices"
] | null | null | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. ... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. | Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"2\n",
"4\n"
] | [
"3\n",
"21\n"
] | The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "6"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "183"
},
{
"input": "7",
"output": "546"
... | 1,633,805,212 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 2,000 | 90,726,400 | def main():
n = int(input())
M = 1000000007
dp = [0] * (n + 1)
for i in range(2, n + 1):
if i % 2 == 0:
dp[i] = (3*dp[i-1] + 3) % M
else:
dp[i] = (3*dp[i-1] - 3) % M
print(dp[n])
main()
| Title: Tetrahedron
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each m... | ```python
def main():
n = int(input())
M = 1000000007
dp = [0] * (n + 1)
for i in range(2, n + 1):
if i % 2 == 0:
dp[i] = (3*dp[i-1] + 3) % M
else:
dp[i] = (3*dp[i-1] - 3) % M
print(dp[n])
main()
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Поликарп мечтает стать программистом и фанатеет от степеней двойки. Среди двух чисел ему больше нравится то, которое делится на большую степень числа 2.
По заданной последовательности целых положительных чисел *a*1,<=*a*2,<=...,<=*a**n* требуется найти *r* — максимальную степень числа 2, на которую делится хотя бы од... | В первой строке записано целое число *n* (1<=≤<=*n*<=≤<=100) — длина последовательности *a*.
Во второй строке записана последовательность целых чисел *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Выведите два числа:
- *r* — максимальную степень двойки, на которую делится хотя бы одно из чисел заданной последовательности, - количество элементов последовательности, которые делятся на *r*. | [
"5\n80 7 16 4 48\n",
"4\n21 5 3 33\n"
] | [
"16 3\n",
"1 4\n"
] | В первом тестовом примере максимальная степень двойки, на которую делится хотя бы одно число, равна 16 = 2<sup class="upper-index">4</sup>, на неё делятся числа 80, 16 и 48.
Во втором тестовом примере все четыре числа нечётные, поэтому делятся только на 1 = 2<sup class="upper-index">0</sup>. Это и будет максимальной с... | 0 | [
{
"input": "5\n80 7 16 4 48",
"output": "16 3"
},
{
"input": "4\n21 5 3 33",
"output": "1 4"
},
{
"input": "10\n8 112 52 86 93 102 24 24 100 826791168",
"output": "256 1"
},
{
"input": "3\n458297759 18 104",
"output": "8 1"
},
{
"input": "7\n12 14 40 8 74 104 11",... | 1,458,977,084 | 1,484 | Python 3 | WRONG_ANSWER | PRETESTS | 4 | 61 | 4,608,000 | n = int(input())
z = input().split()
a = []
r = 0
k = 0
max = 0
for i in range(n):
a.append(int(z[i]))
if a[i] > max:
max = a[i]
for i in range(n):
j = 0
num = a[i]
while num % 2 ** j == 0:
j += 1
if j > r :
r = j - 1
r = 2 ** r
for i in range(n)... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Поликарп мечтает стать программистом и фанатеет от степеней двойки. Среди двух чисел ему больше нравится то, которое делится на большую степень числа 2.
По заданной последовательности целых положительных чисел *a*1,<=*a*2,<=...,... | ```python
n = int(input())
z = input().split()
a = []
r = 0
k = 0
max = 0
for i in range(n):
a.append(int(z[i]))
if a[i] > max:
max = a[i]
for i in range(n):
j = 0
num = a[i]
while num % 2 ** j == 0:
j += 1
if j > r :
r = j - 1
r = 2 ** r
for i i... | 0 | |
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first positi... | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4... | 1,619,516,399 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 77 | 102,400 | n = int(input())
arr = list(map(int,input().split()[:n]))
li = sorted(arr,reverse = True)
for ele in arr:
res = li.index(ele)
print(res + 1,end=" ")
| Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the star... | ```python
n = int(input())
arr = list(map(int,input().split()[:n]))
li = sorted(arr,reverse = True)
for ele in arr:
res = li.index(ele)
print(res + 1,end=" ")
``` | 3 | |
285 | A | Slightly Decreasing Permutations | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
The ... | The single line contains two space-separated integers: *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=<<=*n*) — the permutation length and the decreasing coefficient. | In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* — the permutation of length *n* with decreasing coefficient *k*.
If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. | [
"5 2\n",
"3 0\n",
"3 2\n"
] | [
"1 5 2 4 3\n",
"1 2 3\n",
"3 2 1\n"
] | none | 500 | [
{
"input": "5 2",
"output": "1 5 2 4 3"
},
{
"input": "3 0",
"output": "1 2 3"
},
{
"input": "3 2",
"output": "3 2 1"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output": "1 2"
},
{
"input": "2 1",
"output": "2 1"
},
{
"input":... | 1,559,805,522 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 310 | 7,782,400 | def input_ints():
return list(map(int, input().split()))
def output_list(v):
print(' '.join(str(x) for x in v))
def main():
n, k = input_ints()
ans = []
for i in range(k + 1):
ans.append(k + 1 - i)
for i in range(k + 2, n + 1):
ans.append(i)
output_list(ans)
... | Title: Slightly Decreasing Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutat... | ```python
def input_ints():
return list(map(int, input().split()))
def output_list(v):
print(' '.join(str(x) for x in v))
def main():
n, k = input_ints()
ans = []
for i in range(k + 1):
ans.append(k + 1 - i)
for i in range(k + 2, n + 1):
ans.append(i)
output_li... | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,680,728,454 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | while True:
n = int(input('enter n:))
if (1<=n<=100):
break
words=[]
for i in range(n):
while True:
word = str(input("enter a word:"))
if 1<=len(word)<=100:
words +=[word]
break
for i in range(n):
str=''
if len(words[i])>10:
... | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
while True:
n = int(input('enter n:))
if (1<=n<=100):
break
words=[]
for i in range(n):
while True:
word = str(input("enter a word:"))
if 1<=len(word)<=100:
words +=[word]
break
for i in range(n):
str=''
if len(words[i]... | -1 |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,555,183,113 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 248 | 0 | n=int(input())
s=list(map(int,input().split()))
s1=[]
s2=[]
for i in range(n):
if s[i]%2!=0:
s1.append(s[i])
else:
s2.append(s[i])
if len(s1)==1:
print(s.index(s1[0])+1)
if len(s2)==1:
print(s.index(s2[0])+1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n=int(input())
s=list(map(int,input().split()))
s1=[]
s2=[]
for i in range(n):
if s[i]%2!=0:
s1.append(s[i])
else:
s2.append(s[i])
if len(s1)==1:
print(s.index(s1[0])+1)
if len(s2)==1:
print(s.index(s2[0])+1)
``` | 3.938 |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,683,028,963 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
min=1001
for i in range(m-n):
if (l[i+n-1]-l[i])<min:
min=l[i+n-1]-l[i]
print(min) | Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
min=1001
for i in range(m-n):
if (l[i+n-1]-l[i])<min:
min=l[i+n-1]-l[i]
print(min)
``` | 0 | |
919 | B | Perfect Number | PROGRAMMING | 1,100 | [
"binary search",
"brute force",
"dp",
"implementation",
"number theory"
] | null | null | We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. | A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). | A single number, denoting the $k$-th smallest perfect integer. | [
"1\n",
"2\n"
] | [
"19\n",
"28\n"
] | The first perfect integer is $19$ and the second one is $28$. | 750 | [
{
"input": "1",
"output": "19"
},
{
"input": "2",
"output": "28"
},
{
"input": "13",
"output": "136"
},
{
"input": "101",
"output": "1432"
},
{
"input": "1023",
"output": "100270"
},
{
"input": "9999",
"output": "10800010"
},
{
"input": "10... | 1,635,212,591 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 1,637 | 4,505,600 | import sys
k = int(sys.stdin.readline())
current = 19
def digitsum(n):
total = 0
while n != 0:
total += n%10
n = n//10
return total == 10
while k > 1:
current += 9
while digitsum(current) == False:
current += 9
k -= 1
print(current)
| Title: Perfect Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
Input Specification:
A singl... | ```python
import sys
k = int(sys.stdin.readline())
current = 19
def digitsum(n):
total = 0
while n != 0:
total += n%10
n = n//10
return total == 10
while k > 1:
current += 9
while digitsum(current) == False:
current += 9
k -= 1
print(current)
``` | 3 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,526,474,616 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 186 | 7,372,800 | n = int(input())
ev=od=0
a = list(map(int,input().split()))
for i in range(len(a)):
if(a[i]%2):od+=1
else : ev+=1
if(od>1)and ev:
break
if(ev>1)and od:
break
for i in range(len(a)):
if(ev==1 and not a[i]%2):
print(i+1)
break;
elif od==1 and a[i]%2:
print(i... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
ev=od=0
a = list(map(int,input().split()))
for i in range(len(a)):
if(a[i]%2):od+=1
else : ev+=1
if(od>1)and ev:
break
if(ev>1)and od:
break
for i in range(len(a)):
if(ev==1 and not a[i]%2):
print(i+1)
break;
elif od==1 and a[i]%2:
... | 3.939767 |
596 | B | Wilbur and Array | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input.
The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109). | Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*. | [
"5\n1 2 3 4 5\n",
"4\n1 2 2 1\n"
] | [
"5",
"3"
] | In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes.
In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1. | 1,000 | [
{
"input": "5\n1 2 3 4 5",
"output": "5"
},
{
"input": "4\n1 2 2 1",
"output": "3"
},
{
"input": "3\n1 2 4",
"output": "4"
},
{
"input": "6\n1 2 3 6 5 4",
"output": "8"
},
{
"input": "10\n2 1 4 3 6 5 8 7 10 9",
"output": "19"
},
{
"input": "7\n12 6 12 ... | 1,447,608,325 | 3,025 | Python 3 | WRONG_ANSWER | PRETESTS | 10 | 202 | 8,806,400 | n = int(input())
arr = [int(x) for x in input().split()]
ans = [0] * n
ans[0] = arr[0]
for i in range(1, n):
ans[i] = ans[i - 1] + abs(arr[i] - arr[i - 1])
print(ans[n - 1]) | Title: Wilbur and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+... | ```python
n = int(input())
arr = [int(x) for x in input().split()]
ans = [0] * n
ans[0] = arr[0]
for i in range(1, n):
ans[i] = ans[i - 1] + abs(arr[i] - arr[i - 1])
print(ans[n - 1])
``` | 0 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,607,258,894 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 109 | 307,200 | s1=input()
s2=input()
n=int(s1,2)
h=int(s2,2)
r=n^h
le=len(str(bin(r).replace("0b","")))
if(le<len(s1)):
print('0'*(len(s1)-le)+str(bin(r).replace("0b","")))
else:
print(str(bin(r).replace("0b",""))) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
s1=input()
s2=input()
n=int(s1,2)
h=int(s2,2)
r=n^h
le=len(str(bin(r).replace("0b","")))
if(le<len(s1)):
print('0'*(len(s1)-le)+str(bin(r).replace("0b","")))
else:
print(str(bin(r).replace("0b","")))
``` | 3.972178 |
306 | A | Candies | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *... | The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends. | Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value. | [
"12 3\n",
"15 4\n",
"18 7\n"
] | [
"4 4 4 ",
"3 4 4 4 ",
"2 2 2 3 3 3 3 "
] | Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces. | 500 | [
{
"input": "12 4",
"output": "3 3 3 3 "
},
{
"input": "15 6",
"output": "2 2 2 3 3 3 "
},
{
"input": "18 8",
"output": "2 2 2 2 2 2 3 3 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "2 1",
"output": "2 "
},
{
"input": "100 1",
"output": "100 ... | 1,690,129,374 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | n, m = map(int, input().split())
for x in range(m):
if x<m-(n%m):
print(n//m, end=" ")
else:
print(n//m+1)
| Title: Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most ... | ```python
n, m = map(int, input().split())
for x in range(m):
if x<m-(n%m):
print(n//m, end=" ")
else:
print(n//m+1)
``` | 3 | |
489 | B | BerSU Ball | PROGRAMMING | 1,200 | [
"dfs and similar",
"dp",
"graph matchings",
"greedy",
"sortings",
"two pointers"
] | null | null | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in eac... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of boys. The second line contains sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is the *i*-th boy's dancing skill.
Similarly, the third line contains an integer *m* (1<=≤<=*m*<=≤<=100) — the number of girls. The fourth l... | Print a single number — the required maximum possible number of pairs. | [
"4\n1 4 6 2\n5\n5 1 5 7 9\n",
"4\n1 2 3 4\n4\n10 11 12 13\n",
"5\n1 1 1 1 1\n3\n1 2 3\n"
] | [
"3\n",
"0\n",
"2\n"
] | none | 1,000 | [
{
"input": "4\n1 4 6 2\n5\n5 1 5 7 9",
"output": "3"
},
{
"input": "4\n1 2 3 4\n4\n10 11 12 13",
"output": "0"
},
{
"input": "5\n1 1 1 1 1\n3\n1 2 3",
"output": "2"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 10\n1\n9",
"output": "1"
},
{... | 1,678,288,252 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 61 | 0 | import sys
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
p = 0
q = 0
count = 0
r = min(n,m)
while (p < r and q < r):
if (abs(a[p]-b[q]) <= 1):
count += 1
p += 1
q += 1
elif (a[p] > b[q... | Title: BerSU Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy... | ```python
import sys
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
p = 0
q = 0
count = 0
r = min(n,m)
while (p < r and q < r):
if (abs(a[p]-b[q]) <= 1):
count += 1
p += 1
q += 1
elif (... | 0 | |
534 | B | Covered Path | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"math"
] | null | null | The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the route took exactly *t* seconds to pass.
Assuming that at each of the seconds the speed is constan... | The first line contains two integers *v*1 and *v*2 (1<=≤<=*v*1,<=*v*2<=≤<=100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively.
The second line contains two integers *t* (2<=≤<=*t*<=≤<=100) — the time when the car moves along the segment in seconds, *d* (0<... | Print the maximum possible length of the path segment in meters. | [
"5 6\n4 2\n",
"10 10\n10 0\n"
] | [
"26",
"100"
] | In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters.
In the second sample, as *d* = 0, the car covers the whole segment at constant speed *v* = 10. In *t* = 10 seconds it covers the distance of 100 meters. | 1,000 | [
{
"input": "5 6\n4 2",
"output": "26"
},
{
"input": "10 10\n10 0",
"output": "100"
},
{
"input": "87 87\n2 10",
"output": "174"
},
{
"input": "1 11\n6 2",
"output": "36"
},
{
"input": "100 10\n10 10",
"output": "550"
},
{
"input": "1 1\n100 10",
"o... | 1,645,183,190 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 64 | 140 | 6,963,200 | '''
intially you have a starting speed let it be 5 and ending time let it be 6
then
5 _ _ _ _ _ _ 6
and between them there are moments of time in which stuff happens
there is a value d given which changes the speed by +d or -d in 1 second.
5 (5+d) or (5-d) _ _ _ _ _ 6 at t==2
now we want o figure out the maxim... | Title: Covered Path
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the ... | ```python
'''
intially you have a starting speed let it be 5 and ending time let it be 6
then
5 _ _ _ _ _ _ 6
and between them there are moments of time in which stuff happens
there is a value d given which changes the speed by +d or -d in 1 second.
5 (5+d) or (5-d) _ _ _ _ _ 6 at t==2
now we want o figure out... | 3 | |
400 | A | Inna and Choose Options | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"... | The first line of the input contains integer *t* (1<=≤<=*t*<=≤<=100). This value shows the number of sets of test data in the input. Next follows the description of each of the *t* tests on a separate line.
The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The ... | For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair *a*,<=*b*. Next, print on this line the pairs in the format *a*x*b*. Print the pairs in the order of increasing first parameter (*a*). Separate the pairs in the line b... | [
"4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO\n"
] | [
"3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0\n"
] | none | 500 | [
{
"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO",
"output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0"
},
{
"input": "2\nOOOOOOOOOOOO\nXXXXXXXXXXXX",
"output": "0\n6 1x12 2x6 3x4 4x3 6x2 12x1"
},
{
"input": "13\nXXXXXXXXXXXX\nXXXXXXXXXXXX\n... | 1,625,672,051 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | for i in range(int(input())):
s=input()
c=0
for i in s:
if i=='X':
c+=1
if c==0:
print(0)
elif c==12:
print("6 1x12 2x6 3x4 4x3 6x2 12x1")
else:
c,l=1,[1,0,0,0,0,0]
if (s[0]=='X' and s[6]=='X' ) or (s[1]=='X' and s[7]=='X' ) or (s[2... | Title: Inna and Choose Options
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game.... | ```python
for i in range(int(input())):
s=input()
c=0
for i in s:
if i=='X':
c+=1
if c==0:
print(0)
elif c==12:
print("6 1x12 2x6 3x4 4x3 6x2 12x1")
else:
c,l=1,[1,0,0,0,0,0]
if (s[0]=='X' and s[6]=='X' ) or (s[1]=='X' and s[7]=='X'... | 0 | |
195 | D | Analyzing Polyline | PROGRAMMING | 1,900 | [
"geometry",
"math",
"sortings"
] | null | null | As Valeric and Valerko were watching one of the last Euro Championship games in a sports bar, they broke a mug. Of course, the guys paid for it but the barman said that he will let them watch football in his bar only if they help his son complete a programming task. The task goes like that.
Let's consider a set of fun... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of functions. Each of the following *n* lines contains two space-separated integer numbers *k**i*,<=*b**i* (<=-<=109<=≤<=*k**i*,<=*b**i*<=≤<=109) that determine the *i*-th function. | Print a single number — the number of angles that do not equal 180 degrees in the graph of the polyline that equals the sum of the given functions. | [
"1\n1 0\n",
"3\n1 0\n0 2\n-1 1\n",
"3\n-2 -4\n1 7\n-5 1\n"
] | [
"1\n",
"2\n",
"3\n"
] | none | 2,000 | [
{
"input": "1\n1 0",
"output": "1"
},
{
"input": "3\n1 0\n0 2\n-1 1",
"output": "2"
},
{
"input": "3\n-2 -4\n1 7\n-5 1",
"output": "3"
},
{
"input": "10\n9 9\n-5 2\n-2 9\n0 6\n6 7\n-1 -10\n-8 6\n3 6\n-3 -9\n0 4",
"output": "8"
},
{
"input": "10\n-4 -9\n5 9\n-4 -1\... | 1,692,458,113 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 75 | 280 | 14,540,800 | from math import gcd
import sys
n = int(sys.stdin.readline())
res = set()
for _ in range(n):
k,b = map(int,sys.stdin.readline().split())
if k!=0:
a = gcd(k,b)
if k*b>0:
res.add((abs(b//a),abs(k//a)))
else:
res.add((-abs(b//a),abs(k//a)))
print(len(res)... | Title: Analyzing Polyline
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As Valeric and Valerko were watching one of the last Euro Championship games in a sports bar, they broke a mug. Of course, the guys paid for it but the barman said that he will let them watch football in his bar only... | ```python
from math import gcd
import sys
n = int(sys.stdin.readline())
res = set()
for _ in range(n):
k,b = map(int,sys.stdin.readline().split())
if k!=0:
a = gcd(k,b)
if k*b>0:
res.add((abs(b//a),abs(k//a)))
else:
res.add((-abs(b//a),abs(k//a)))
prin... | 3 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,694,640,486 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 61 | 0 | k , n, w= map(int,input().split())
for i in range(1,w+1):
n-=(k*i)
if n<0 :
print(abs(n))
else:
print(0) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
k , n, w= map(int,input().split())
for i in range(1,w+1):
n-=(k*i)
if n<0 :
print(abs(n))
else:
print(0)
``` | 3 | |
476 | B | Dreamoon and WiFi | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"combinatorics",
"dp",
"math",
"probabilities"
] | null | null | Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, de... | The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes ... | Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9. | [
"++-+-\n+-+-+\n",
"+-+-\n+-??\n",
"+++\n??-\n"
] | [
"1.000000000000\n",
"0.500000000000\n",
"0.000000000000\n"
] | For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position + 1.
For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="low... | 1,500 | [
{
"input": "++-+-\n+-+-+",
"output": "1.000000000000"
},
{
"input": "+-+-\n+-??",
"output": "0.500000000000"
},
{
"input": "+++\n??-",
"output": "0.000000000000"
},
{
"input": "++++++++++\n+++??++?++",
"output": "0.125000000000"
},
{
"input": "--+++---+-\n????????... | 1,689,427,437 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689427436.963162")# 1689427436.9631834 | Title: Dreamoon and WiFi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go... | ```python
print("_RANDOM_GUESS_1689427436.963162")# 1689427436.9631834
``` | 0 | |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,675,321,850 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | p1,p2=map(int,input().split())
w=d=l=0
for x in range(1,7):
if(abs(p1-x)<abs(p2-x)):
w=w+1
elif(abs(p1-x)==(p2-x)):
d=d+1
else:
l=l+1
print(w,d,l)
| Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
p1,p2=map(int,input().split())
w=d=l=0
for x in range(1,7):
if(abs(p1-x)<abs(p2-x)):
w=w+1
elif(abs(p1-x)==(p2-x)):
d=d+1
else:
l=l+1
print(w,d,l)
``` | 0 | |
145 | C | Lucky Subsequence | PROGRAMMING | 2,100 | [
"combinatorics",
"dp",
"math"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has sequence *a* consisting of *n* integers.
The subsequence of the sequence *a* is such su... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the sequence *a*. | On the single line print the single number — the answer to the problem modulo prime number 1000000007 (109<=+<=7). | [
"3 2\n10 10 10\n",
"4 2\n4 4 7 7\n"
] | [
"3\n",
"4\n"
] | In the first sample all 3 subsequences of the needed length are considered lucky.
In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1, 3}, {1, 4}, {2, 3} and {2, 4}. | 1,500 | [
{
"input": "3 2\n10 10 10",
"output": "3"
},
{
"input": "4 2\n4 4 7 7",
"output": "4"
},
{
"input": "7 4\n1 2 3 4 5 6 7",
"output": "35"
},
{
"input": "7 4\n7 7 7 7 7 7 7",
"output": "0"
},
{
"input": "10 1\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"... | 1,639,584,158 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 216 | 4,915,200 | p = 10**9+7
def power(x, y, p):
b = bin(y)[2:]
start = x % p
answer = 1
for i in range(len(b)):
if b[len(b)-i-1]=='1':
answer = (start*answer) % p
start = (start*start) % p
return answer
fact_dict = [1, 1]
for i in range(2, 10**5+2):
fact_dict.append... | Title: Lucky Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are n... | ```python
p = 10**9+7
def power(x, y, p):
b = bin(y)[2:]
start = x % p
answer = 1
for i in range(len(b)):
if b[len(b)-i-1]=='1':
answer = (start*answer) % p
start = (start*start) % p
return answer
fact_dict = [1, 1]
for i in range(2, 10**5+2):
fact_d... | 0 | |
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all c... | Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). | Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
... | 1,629,106,071 | 2,147,483,647 | Python 3 | OK | TESTS | 99 | 156 | 6,963,200 | n,num = int(input()),0
for i in range(2,n):
m = n
while m:
num += m % i
m -= m % i
m //= i
n -= 2
for i in range(2,int(num ** 0.5)):
while num % i == 0 and n % i == 0:
num //= i
n //= i
print(f'{num}/{n}') | Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of su... | ```python
n,num = int(input()),0
for i in range(2,n):
m = n
while m:
num += m % i
m -= m % i
m //= i
n -= 2
for i in range(2,int(num ** 0.5)):
while num % i == 0 and n % i == 0:
num //= i
n //= i
print(f'{num}/{n}')
``` | 3.87012 |
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,609,706,920 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 218 | 307,200 | a,n=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','r','u','v','w','x','y','z'],input()
b=[i.upper() for i in a]
if sum([n.count(i) for i in a]) >= sum([n.count(i) for i in b]): print(n.lower())
else: print(n.upper()) | 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
a,n=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','r','u','v','w','x','y','z'],input()
b=[i.upper() for i in a]
if sum([n.count(i) for i in a]) >= sum([n.count(i) for i in b]): print(n.lower())
else: print(n.upper())
``` | 0 |
688 | B | Lovely Palindromes | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). | Print the *n*-th even-length palindrome number. | [
"1\n",
"10\n"
] | [
"11\n",
"1001\n"
] | The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001. | 1,000 | [
{
"input": "1",
"output": "11"
},
{
"input": "10",
"output": "1001"
},
{
"input": "11",
"output": "1111"
},
{
"input": "12",
"output": "1221"
},
{
"input": "100",
"output": "100001"
},
{
"input": "1321",
"output": "13211231"
},
{
"input": "... | 1,622,129,470 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 13,004,800 |
# https://codeforces.com/contest/688/problem/B
def split(word):
return [char for char in word]
def listToString(s):
# initialize an empty string
str1 = ""
# traverse in the string
for ele in s:
str1 += ele
# return string
return str1
s = split(input())
n... | Title: Lovely Palindromes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is tr... | ```python
# https://codeforces.com/contest/688/problem/B
def split(word):
return [char for char in word]
def listToString(s):
# initialize an empty string
str1 = ""
# traverse in the string
for ele in s:
str1 += ele
# return string
return str1
s = split(... | 0 | |
678 | C | Joty and Chocolate | PROGRAMMING | 1,600 | [
"implementation",
"math",
"number theory"
] | null | null | Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisibl... | The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109). | Print the only integer *s* — the maximum number of chocolates Joty can get.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"5 2 3 12 15\n",
"20 2 3 3 5\n"
] | [
"39\n",
"51\n"
] | none | 0 | [
{
"input": "5 2 3 12 15",
"output": "39"
},
{
"input": "20 2 3 3 5",
"output": "51"
},
{
"input": "1 1 1 1 1",
"output": "1"
},
{
"input": "1 2 2 2 2",
"output": "0"
},
{
"input": "2 1 3 3 3",
"output": "6"
},
{
"input": "3 1 1 3 3",
"output": "9"
... | 1,694,467,788 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 185 | 62 | 0 | from math import lcm
n,a,b,p,q=[int(e) for e in input().split()]
print(max(p*(n//a)+q*(n//b-n//lcm(a,b)),q*(n//b)+p*(n//a-n//lcm(a,b)))) | Title: Joty and Chocolate
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by *a* and an unpai... | ```python
from math import lcm
n,a,b,p,q=[int(e) for e in input().split()]
print(max(p*(n//a)+q*(n//b-n//lcm(a,b)),q*(n//b)+p*(n//a-n//lcm(a,b))))
``` | 3 | |
586 | B | Laurenty and Shop | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese.
The town where Laurenty lives in is not large. The houses in it are located in two rows, *n* houses in each... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=50) — the number of houses in each row.
Each of the next two lines contains *n*<=-<=1 space-separated integer — values *a**ij* (1<=≤<=*a**ij*<=≤<=100).
The last line contains *n* space-separated integers *b**j* (1<=≤<=*b**j*<=≤<=100). | Print a single integer — the least total time Laurenty needs to wait at the crossroads, given that he crosses the avenue only once both on his way to the store and on his way back home. | [
"4\n1 2 3\n3 2 1\n3 2 2 3\n",
"3\n1 2\n3 3\n2 1 3\n",
"2\n1\n1\n1 1\n"
] | [
"12\n",
"11\n",
"4\n"
] | The first sample is shown on the figure above.
In the second sample, Laurenty's path can look as follows:
- Laurenty crosses the avenue, the waiting time is 3; - Laurenty uses the second crossing in the first row, the waiting time is 2; - Laurenty uses the first crossing in the first row, the waiting time is 1; ... | 1,000 | [
{
"input": "4\n1 2 3\n3 2 1\n3 2 2 3",
"output": "12"
},
{
"input": "3\n1 2\n3 3\n2 1 3",
"output": "11"
},
{
"input": "2\n1\n1\n1 1",
"output": "4"
},
{
"input": "2\n1\n1\n2 1",
"output": "5"
},
{
"input": "3\n1 100\n1 1\n100 100 100",
"output": "204"
},
... | 1,444,643,830 | 2,830 | Python 3 | OK | TESTS | 40 | 62 | 0 | n = int(input())
H1 = list(map(int, input().split()))
H2 = list(map(int, input().split()))
av = list(map(int, input().split()))
ans = []
for i in range(n - 1):
ans.append(sum(H1[:i]) + av[i] + sum(H2[i:]))
ans.append(sum(H1) + av[-1])
ans.sort()
print(ans[0] + ans[1])
| Title: Laurenty and Shop
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese.
The ... | ```python
n = int(input())
H1 = list(map(int, input().split()))
H2 = list(map(int, input().split()))
av = list(map(int, input().split()))
ans = []
for i in range(n - 1):
ans.append(sum(H1[:i]) + av[i] + sum(H2[i:]))
ans.append(sum(H1) + av[-1])
ans.sort()
print(ans[0] + ans[1])
``` | 3 | |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,695,531,349 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 62 | 0 | n=input()
n=n.lower()
vow="aeiou"
str=""
for i in n:
if i not in vow:
str+="."+i
print(str)
| Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
n=input()
n=n.lower()
vow="aeiou"
str=""
for i in n:
if i not in vow:
str+="."+i
print(str)
``` | 0 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,592,302,978 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 248 | 307,200 | n = int(input())
team_dict = {}
for i in range(n):
scoring_team =str(input().strip())
if scoring_team not in list(team_dict.keys()):
team_dict[scoring_team]=0
team_dict[scoring_team]=team_dict[scoring_team]+1
winning_team = sorted([(k,v) for k,v in list(team_dict.items())],key=lambda x:x[1],rev... | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
n = int(input())
team_dict = {}
for i in range(n):
scoring_team =str(input().strip())
if scoring_team not in list(team_dict.keys()):
team_dict[scoring_team]=0
team_dict[scoring_team]=team_dict[scoring_team]+1
winning_team = sorted([(k,v) for k,v in list(team_dict.items())],key=lambda ... | 3.937428 |
439 | B | Devu, the Dumb Guy | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is *x* hours. In other ... | The first line will contain two space separated integers *n*, *x* (1<=≤<=*n*,<=*x*<=≤<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105). | Output a single integer representing the answer to the problem. | [
"2 3\n4 1\n",
"4 2\n5 1 2 1\n",
"3 3\n1 1 1\n"
] | [
"11\n",
"10\n",
"6\n"
] | Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 ... | 1,000 | [
{
"input": "2 3\n4 1",
"output": "11"
},
{
"input": "4 2\n5 1 2 1",
"output": "10"
},
{
"input": "3 3\n1 1 1",
"output": "6"
},
{
"input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3",
"output": "65"
},
{
"input": "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3... | 1,564,379,786 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 2,560,000 | from sys import stdin
stdin = open("sum.in", 'r')
hat = stdin.readlines()
n, x = map(int, hat[0].split())
lst = [int(x) for x in hat[1].split()]
newlst = []
lst.sort()
halfway = int(0.5*n)
#print(lst)
houres = 0
for i in range(n):
#print(i)
if x != 1:
houres += x * lst[i]
x -= 1
... | Title: Devu, the Dumb Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject co... | ```python
from sys import stdin
stdin = open("sum.in", 'r')
hat = stdin.readlines()
n, x = map(int, hat[0].split())
lst = [int(x) for x in hat[1].split()]
newlst = []
lst.sort()
halfway = int(0.5*n)
#print(lst)
houres = 0
for i in range(n):
#print(i)
if x != 1:
houres += x * lst[i]
... | -1 | |
449 | B | Jzzhu and Cities | PROGRAMMING | 2,000 | [
"graphs",
"greedy",
"shortest paths"
] | null | null | Jzzhu is the president of country A. There are *n* cities numbered from 1 to *n* in his country. City 1 is the capital of A. Also there are *m* roads connecting the cities. One can go from city *u**i* to *v**i* (and vise versa) using the *i*-th road, the length of this road is *x**i*. Finally, there are *k* train route... | The first line contains three integers *n*,<=*m*,<=*k* (2<=≤<=*n*<=≤<=105; 1<=≤<=*m*<=≤<=3·105; 1<=≤<=*k*<=≤<=105).
Each of the next *m* lines contains three integers *u**i*,<=*v**i*,<=*x**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*; 1<=≤<=*x**i*<=≤<=109).
Each of the next *k* lines contains two integers *s*... | Output a single integer representing the maximum number of the train routes which can be closed. | [
"5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5\n",
"2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3\n"
] | [
"2\n",
"2\n"
] | none | 1,000 | [
{
"input": "5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5",
"output": "2"
},
{
"input": "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3",
"output": "2"
},
{
"input": "5 4 3\n1 2 999999999\n2 3 1000000000\n3 4 529529529\n5 1 524524524\n5 524444444\n5 529999999\n2 1000000000",
"output": ... | 1,667,208,985 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 56,729,600 | from collections import deque
n, m, k = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
u, v, cost = map(int, input().split())
graph[u-1].append([v-1, cost])
graph[v-1].append([u-1, cost])
visited = set()
queue = deque([[0,0]])
min_cost = [float('inf') for i in ran... | Title: Jzzhu and Cities
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jzzhu is the president of country A. There are *n* cities numbered from 1 to *n* in his country. City 1 is the capital of A. Also there are *m* roads connecting the cities. One can go from city *u**i* to *v**i* (and vi... | ```python
from collections import deque
n, m, k = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
u, v, cost = map(int, input().split())
graph[u-1].append([v-1, cost])
graph[v-1].append([u-1, cost])
visited = set()
queue = deque([[0,0]])
min_cost = [float('inf') fo... | 0 | |
424 | A | Squats | PROGRAMMING | 900 | [
"implementation"
] | null | null | Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ethe... | The first line contains integer *n* (2<=≤<=*n*<=≤<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting. | In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. | [
"4\nxxXx\n",
"2\nXX\n",
"6\nxXXxXx\n"
] | [
"1\nXxXx\n",
"1\nxX\n",
"0\nxXXxXx\n"
] | none | 500 | [
{
"input": "4\nxxXx",
"output": "1\nXxXx"
},
{
"input": "2\nXX",
"output": "1\nxX"
},
{
"input": "6\nxXXxXx",
"output": "0\nxXXxXx"
},
{
"input": "4\nxXXX",
"output": "1\nxxXX"
},
{
"input": "2\nXx",
"output": "0\nXx"
},
{
"input": "22\nXXxXXxxXxXxXXXX... | 1,531,066,397 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 109 | 0 | n=int(input())
a=list(input())
z=a.count('X')
p=n//2
print(abs(p-z))
if z>p:
t=0
for i in range(n):
if t<abs(p-z):
if a[i]=='X':
a[i]='x'
t+=1
else:
break
for i in range(n):
print(a[i],end='')
elif z==p:
for... | Title: Squats
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly hamsters to ... | ```python
n=int(input())
a=list(input())
z=a.count('X')
p=n//2
print(abs(p-z))
if z>p:
t=0
for i in range(n):
if t<abs(p-z):
if a[i]=='X':
a[i]='x'
t+=1
else:
break
for i in range(n):
print(a[i],end='')
elif z==p... | 3 | |
63 | A | Sinking Ship | PROGRAMMING | 900 | [
"implementation",
"sortings",
"strings"
] | A. Sinking Ship | 2 | 256 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a stri... | The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spa... | Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. | [
"6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n"
] | [
"Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n"
] | none | 500 | [
{
"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"
},
{
"input": "1\nA captain",
"output": "A"
},
{
"input": "1\nAbcdefjhij captain",
"output": "Abcdefjhij"
},
{
"input": "5\nA captain... | 1,619,387,518 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 154 | 204,800 | n = int(input())
crew = []
for _ in range(n):
crew.append(input())
for member in crew:
member = member.split(' ')
if member[1] == "rat":
print(member[0])
for member in crew:
member = member.split(' ')
if member[1] == "woman" or member[1] == "child":
print(member[0])
for member in ... | Title: Sinking Ship
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to ... | ```python
n = int(input())
crew = []
for _ in range(n):
crew.append(input())
for member in crew:
member = member.split(' ')
if member[1] == "rat":
print(member[0])
for member in crew:
member = member.split(' ')
if member[1] == "woman" or member[1] == "child":
print(member[0])
for ... | 3.961119 |
818 | C | Sofa Thief | PROGRAMMING | 2,000 | [
"brute force",
"implementation"
] | null | null | Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs ... | The first line contains one integer number *d* (1<=≤<=*d*<=≤<=105) — the number of sofas in the storehouse.
The second line contains two integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the size of the storehouse.
Next *d* lines contains four integer numbers *x*1, *y*1, *x*2, *y*2 (1<=≤<=*x*1,<=*x*2<=≤<=*n*, 1<=≤... | Print the number of the sofa for which all the conditions are met. Sofas are numbered 1 through *d* as given in input. If there is no such sofa then print -1. | [
"2\n3 2\n3 1 3 2\n1 2 2 2\n1 0 0 1\n",
"3\n10 10\n1 2 1 1\n5 5 6 5\n6 4 5 4\n2 1 2 0\n",
"2\n2 2\n2 1 1 1\n1 2 2 2\n1 0 0 0\n"
] | [
"1\n",
"2\n",
"-1\n"
] | Let's consider the second example.
- The first sofa has 0 to its left, 2 sofas to its right ((1, 1) is to the left of both (5, 5) and (5, 4)), 0 to its top and 2 to its bottom (both 2nd and 3rd sofas are below). - The second sofa has *cnt*<sub class="lower-index">*l*</sub> = 2, *cnt*<sub class="lower-index">*r*</su... | 0 | [
{
"input": "2\n3 2\n3 1 3 2\n1 2 2 2\n1 0 0 1",
"output": "1"
},
{
"input": "3\n10 10\n1 2 1 1\n5 5 6 5\n6 4 5 4\n2 1 2 0",
"output": "2"
},
{
"input": "2\n2 2\n2 1 1 1\n1 2 2 2\n1 0 0 0",
"output": "-1"
},
{
"input": "1\n1 2\n1 1 1 2\n0 0 0 0",
"output": "1"
},
{
... | 1,498,758,224 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 16 | 763 | 26,828,800 | from sys import stdin, stdout
k = int(stdin.readline())
n, m = map(int, stdin.readline().split())
left, right, down, up = [], [], [], []
challengers = []
for i in range(k):
x1, y1, x2, y2 = map(int, stdin.readline().split())
if x1 == x2:
if y1 < y2:
challengers.append((x1,... | Title: Sofa Thief
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for G... | ```python
from sys import stdin, stdout
k = int(stdin.readline())
n, m = map(int, stdin.readline().split())
left, right, down, up = [], [], [], []
challengers = []
for i in range(k):
x1, y1, x2, y2 = map(int, stdin.readline().split())
if x1 == x2:
if y1 < y2:
challengers.a... | 0 | |
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,673,408,817 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 62 | 409,600 | b=input()
c=input()
un=c.count("1")
zero=c.count("0")
print(abs(zero-un))
| 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
b=input()
c=input()
un=c.count("1")
zero=c.count("0")
print(abs(zero-un))
``` | 3 | |
172 | C | Bus | PROGRAMMING | 1,500 | [
"*special",
"implementation",
"sortings"
] | null | null | There is a bus stop near the university. The lessons are over, and *n* students come to the stop. The *i*-th student will appear at the bus stop at time *t**i* (all *t**i*'s are distinct).
We shall assume that the stop is located on the coordinate axis *Ox*, at point *x*<==<=0, and the bus goes along the ray *Ox*, tha... | The first line contains two space-separated integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of students and the number of passengers the bus can transport, correspondingly. Next *n* lines contain descriptions of the students, one per line. Each line contains a pair of integers *t**i*,<=*x**i* (1<=≤<=*t**i*<=≤... | Print *n* numbers *w*1,<=*w*2,<=...,<=*w**n*, *w**i* — the moment of time when the *i*-th student got off the bus. Print the numbers on one line and separate them with single spaces. | [
"1 10\n3 5\n",
"2 1\n3 5\n4 5\n",
"5 4\n3 5\n4 5\n5 5\n6 5\n7 1\n",
"20 4\n28 13\n31 13\n35 6\n36 4\n52 6\n53 4\n83 2\n84 4\n87 1\n93 6\n108 4\n113 6\n116 1\n125 2\n130 2\n136 13\n162 2\n166 4\n184 1\n192 2\n"
] | [
"8\n",
"8 19\n",
"11 11 11 11 20\n",
"51 51 43 40 93 89 86 89 114 121 118 121 137 139 139 152 195 199 193 195\n"
] | In the first sample the bus waits for the first student for 3 units of time and drives him to his destination in additional 5 units of time. So the student leaves the bus at the moment of time 3 + 5 = 8.
In the second sample the capacity of the bus equals 1, that's why it will drive the first student alone. This stude... | 1,500 | [
{
"input": "1 10\n3 5",
"output": "8"
},
{
"input": "2 1\n3 5\n4 5",
"output": "8 19"
},
{
"input": "5 4\n3 5\n4 5\n5 5\n6 5\n7 1",
"output": "11 11 11 11 20"
},
{
"input": "20 4\n28 13\n31 13\n35 6\n36 4\n52 6\n53 4\n83 2\n84 4\n87 1\n93 6\n108 4\n113 6\n116 1\n125 2\n130 2\... | 1,519,094,678 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 1,000 | 12,595,200 | a=input().split()
n=int(a[0])
m=int(a[1])
t=[]
c=[]
time=int(0)
time=int(time)
answer=""
for i in range(n):
a=input().split()
t.append(int(a[0]))
c.append(int(a[1]))
f=0
if int(n/m)-n/m!=0:
f=int(n/m)+1
else:
f=int(n/m)
maxx=0
for j in range(f):
... | Title: Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a bus stop near the university. The lessons are over, and *n* students come to the stop. The *i*-th student will appear at the bus stop at time *t**i* (all *t**i*'s are distinct).
We shall assume that the stop is located ... | ```python
a=input().split()
n=int(a[0])
m=int(a[1])
t=[]
c=[]
time=int(0)
time=int(time)
answer=""
for i in range(n):
a=input().split()
t.append(int(a[0]))
c.append(int(a[1]))
f=0
if int(n/m)-n/m!=0:
f=int(n/m)+1
else:
f=int(n/m)
maxx=0
for j in r... | 0 | |
911 | A | Nearest Minimums | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. | The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times. | Print the only number — distance between two nearest minimums in the array. | [
"2\n3 3\n",
"3\n5 6 5\n",
"9\n2 1 3 5 4 1 2 3 1\n"
] | [
"1\n",
"2\n",
"3\n"
] | none | 0 | [
{
"input": "2\n3 3",
"output": "1"
},
{
"input": "3\n5 6 5",
"output": "2"
},
{
"input": "9\n2 1 3 5 4 1 2 3 1",
"output": "3"
},
{
"input": "6\n4 6 7 8 6 4",
"output": "5"
},
{
"input": "2\n1000000000 1000000000",
"output": "1"
},
{
"input": "42\n1 1 ... | 1,515,983,834 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 77 | 7,372,800 |
n = int(input())
a = list(map(int, input().split()))
m = min(a)
index = -1
dist = 0
for i in range(n):
if a[i] == m:
if index != -1:
dist = i - index
index = i
print(dist) | Title: Nearest Minimums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
I... | ```python
n = int(input())
a = list(map(int, input().split()))
m = min(a)
index = -1
dist = 0
for i in range(n):
if a[i] == m:
if index != -1:
dist = i - index
index = i
print(dist)
``` | 0 | |
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and c... | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",... | 1,611,562,131 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 11 | 902 | 1,331,200 | n = int(input())
k = 1
done = False
if n < 1000:
limit = n
elif n in range(1000, 10000):
limit = 75
elif n in range(10000, 100000):
limit = 225
elif n in range(100000, 1000000):
limit = 725
elif n in range(1000000, 10000000):
limit = 2250
elif n in range(10000000, 100000000):
l... | Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent... | ```python
n = int(input())
k = 1
done = False
if n < 1000:
limit = n
elif n in range(1000, 10000):
limit = 75
elif n in range(10000, 100000):
limit = 225
elif n in range(100000, 1000000):
limit = 725
elif n in range(1000000, 10000000):
limit = 2250
elif n in range(10000000, 10000000... | 0 | |
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu... | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"... | 1,694,259,437 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 1,843,200 | from dataclasses import dataclass
import math
@dataclass
class Underground:
quantity_to_trips: int
season_tickets: int
coast_ticket: float
coast_season_ticket: float
def price_season_one_trip(self):
if self.quantity_to_trips < self.season_tickets:
return self.coast_season_tic... | Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl... | ```python
from dataclasses import dataclass
import math
@dataclass
class Underground:
quantity_to_trips: int
season_tickets: int
coast_ticket: float
coast_season_ticket: float
def price_season_one_trip(self):
if self.quantity_to_trips < self.season_tickets:
return self.coast_... | 0 | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,672,710,062 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n=int(input())
l=[int(i) for i in input().split()]
l1=[0 for i in range(max(l)+1)]
for i in l:
l1[i]+=1
m1=0
for i in range(0,len(l1),2):
m1+=l1[i]*i
m2=0
for i in range(1,len(l1),2):
m2+=l1[i]*i
print(max(m1,m2)) | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
n=int(input())
l=[int(i) for i in input().split()]
l1=[0 for i in range(max(l)+1)]
for i in l:
l1[i]+=1
m1=0
for i in range(0,len(l1),2):
m1+=l1[i]*i
m2=0
for i in range(1,len(l1),2):
m2+=l1[i]*i
print(max(m1,m2))
``` | 0 | |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,691,678,342 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | while True:
try:
a=list(map(int,input().split()))
print(max(0,len(set(a))-1)
except Exception as e:
break
| Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
while True:
try:
a=list(map(int,input().split()))
print(max(0,len(set(a))-1)
except Exception as e:
break
``` | -1 | |
1 | B | Spreadsheet | PROGRAMMING | 1,600 | [
"implementation",
"math"
] | B. Spreadsheets | 10 | 64 | In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow th... | The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=105), the number of coordinates in the test. Then there follow *n* lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 . | Write *n* lines, each line should contain a cell coordinates in the other numeration system. | [
"2\nR23C55\nBC23\n"
] | [
"BC23\nR23C55\n"
] | none | 0 | [
{
"input": "2\nR23C55\nBC23",
"output": "BC23\nR23C55"
},
{
"input": "1\nA1",
"output": "R1C1"
},
{
"input": "5\nR8C3\nD1\nR7C2\nR8C9\nR8C9",
"output": "C8\nR1C4\nB7\nI8\nI8"
},
{
"input": "4\nR4C25\nR90C35\nAP55\nX83",
"output": "Y4\nAI90\nR55C42\nR83C24"
},
{
"i... | 1,683,755,427 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 5 | 278 | 6,656,000 | def calculate(x):
p=ord('A')-1
c=0
s=0
x=x[::-1]
for i in x:
s+=(ord(i)-p)*(26**c)
c+=1
return s
def calc(x):
j=int(x)
p=ord('A')-1
y=""
while j!=0:
y=chr(p+j%26)+y
j=j//26
return y
for _ in range(int(input())):
s=input()
... | Title: Spreadsheet
Time Limit: 10 seconds
Memory Limit: 64 megabytes
Problem Description:
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter n... | ```python
def calculate(x):
p=ord('A')-1
c=0
s=0
x=x[::-1]
for i in x:
s+=(ord(i)-p)*(26**c)
c+=1
return s
def calc(x):
j=int(x)
p=ord('A')-1
y=""
while j!=0:
y=chr(p+j%26)+y
j=j//26
return y
for _ in range(int(input())):
s=input... | -1 |
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge... | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input... | 1,660,874,801 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 295 | 28,876,800 | import sys
from heapq import heappop, heappush
input = sys.stdin.readline
def dijkstra(graph, start=0):
n = len(graph)
dist, parents = [float('inf')] * n, [-1] * n
dist[start] = 0.0
queue = [(0.0, start)]
while queue:
path_len, v = heappop(queue)
if path_len == dist[v]:
... | Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* a... | ```python
import sys
from heapq import heappop, heappush
input = sys.stdin.readline
def dijkstra(graph, start=0):
n = len(graph)
dist, parents = [float('inf')] * n, [-1] * n
dist[start] = 0.0
queue = [(0.0, start)]
while queue:
path_len, v = heappop(queue)
if path_len == dist... | 3.637351 |
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi... | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel... | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input"... | 1,676,703,143 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 307,200 | n , m = map(int,input().split())
d = dict()
for _ in range(m):
a , b = input().split()
if(len(a)<=len(b)):
d[a] = a
else:
d[a] = b
s = list(input().split())
for i in s :
print(d[i],end=" ") | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first ... | ```python
n , m = map(int,input().split())
d = dict()
for _ in range(m):
a , b = input().split()
if(len(a)<=len(b)):
d[a] = a
else:
d[a] = b
s = list(input().split())
for i in s :
print(d[i],end=" ")
``` | 3 | |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
... | 1,674,303,183 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 62 | 0 | from itertools import combinations
if __name__ == '__main__':
s = input()
t = ""
for el in s:
t += str(min(int(el), 9 - int(el)))
print(int(t) * (int(t) != 0) + 9 *(int(t) == 0))
| Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform... | ```python
from itertools import combinations
if __name__ == '__main__':
s = input()
t = ""
for el in s:
t += str(min(int(el), 9 - int(el)))
print(int(t) * (int(t) != 0) + 9 *(int(t) == 0))
``` | 0 | |
527 | C | Glass Carving | PROGRAMMING | 1,500 | [
"binary search",
"data structures",
"implementation"
] | null | null | Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular *w* mm <=×<= *h* mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how.
In order not to waste time, he decided to prac... | The first line contains three integers *w*,<=*h*,<=*n* (2<=≤<=*w*,<=*h*<=≤<=200<=000, 1<=≤<=*n*<=≤<=200<=000).
Next *n* lines contain the descriptions of the cuts. Each description has the form *H* *y* or *V* *x*. In the first case Leonid makes the horizontal cut at the distance *y* millimeters (1<=≤<=*y*<=≤<=*h*<=-<=... | After each cut print on a single line the area of the maximum available glass fragment in mm2. | [
"4 3 4\nH 2\nV 2\nV 3\nV 1\n",
"7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1\n"
] | [
"8\n4\n4\n2\n",
"28\n16\n12\n6\n4\n"
] | Picture for the first sample test: | 1,500 | [
{
"input": "4 3 4\nH 2\nV 2\nV 3\nV 1",
"output": "8\n4\n4\n2"
},
{
"input": "7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1",
"output": "28\n16\n12\n6\n4"
},
{
"input": "2 2 1\nV 1",
"output": "2"
},
{
"input": "2 2 1\nH 1",
"output": "2"
},
{
"input": "2 2 2\nV 1\nH 1",
"ou... | 1,588,173,314 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 307,200 | from heapq import heappush, heapify
w, h, n = map(int, input().split())
H_cuts = [0, h]
V_cuts = [0, w]
# heapify(H_cuts)
# heapify(V_cuts)
last_big_H = h
last_big_V = w
for i in range(n):
direction, dist = input().split()
distance = int(dist)
if direction == "H":
# heappush(H_cuts, ... | Title: Glass Carving
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular *w* mm <=×<= *h* mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What ... | ```python
from heapq import heappush, heapify
w, h, n = map(int, input().split())
H_cuts = [0, h]
V_cuts = [0, w]
# heapify(H_cuts)
# heapify(V_cuts)
last_big_H = h
last_big_V = w
for i in range(n):
direction, dist = input().split()
distance = int(dist)
if direction == "H":
# heappus... | 0 | |
624 | B | Making a String | PROGRAMMING | 1,100 | [
"greedy",
"sortings"
] | null | null | You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
- the *i*-th letter occurs in the string no more than *a**i* times; - the number of occurrences of each letter in the string must be distinct for all the ... | The first line of the input contains a single integer *n* (2<=<=≤<=<=*n*<=<=≤<=<=26) — the number of letters in the alphabet.
The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — *i*-th of these integers gives the limitation on the number of occurrences of the *i*-th character in the string. | Print a single integer — the maximum length of the string that meets all the requirements. | [
"3\n2 5 5\n",
"3\n1 1 2\n"
] | [
"11\n",
"3\n"
] | For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc". | 1,000 | [
{
"input": "3\n2 5 5",
"output": "11"
},
{
"input": "3\n1 1 2",
"output": "3"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "3\n1 1000000000 2",
"output": "1000000003"
},
{
"input": "26\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10000... | 1,496,338,433 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | dicio = {}
def vernodicio(x):
if x not in dicio:
dicio[x] = True
return x
else:
return vernodicio(x-1)
k = 0
x = int(input())
lista = map(int,raw_input().split())
dicio={}
for i in range(x):
v = vernodicio(lista[i])
k += v
print (k)
| Title: Making a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
- the *i*-th letter occurs in the string no more than ... | ```python
dicio = {}
def vernodicio(x):
if x not in dicio:
dicio[x] = True
return x
else:
return vernodicio(x-1)
k = 0
x = int(input())
lista = map(int,raw_input().split())
dicio={}
for i in range(x):
v = vernodicio(lista[i])
k += v
print (k)
``` | -1 | |
906 | A | Shockers | PROGRAMMING | 1,600 | [
"implementation",
"strings"
] | null | null | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of actions Valentin did.
The next *n* lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. Th... | Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. | [
"5\n! abc\n. ad\n. b\n! cd\n? c\n",
"8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e\n",
"7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first test case after the first action it becomes clear that the selected letter is one of the following: *a*, *b*, *c*. After the second action we can note that the selected letter is not *a*. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is *c*, but Valentin p... | 500 | [
{
"input": "5\n! abc\n. ad\n. b\n! cd\n? c",
"output": "1"
},
{
"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e",
"output": "2"
},
{
"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h",
"output": "0"
},
{
"input": "4\n! abcd\n! cdef\n? d\n? c",
"o... | 1,587,168,892 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 202 | 2,150,400 | import sys
input=sys.stdin.readline
A=ord('a')
left=set([chr(i+A) for i in range(26)])
bad=0
q=int(input())
for i in range(q-1):
op,s = input().split()
if op=='!':
left=left&set(op)
else:
left=left-op
bad += len(left)==1
print(bad)
| Title: Shockers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected le... | ```python
import sys
input=sys.stdin.readline
A=ord('a')
left=set([chr(i+A) for i in range(26)])
bad=0
q=int(input())
for i in range(q-1):
op,s = input().split()
if op=='!':
left=left&set(op)
else:
left=left-op
bad += len(left)==1
print(bad)
``` | -1 | |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immedi... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate... | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": ... | 1,645,789,990 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 60 | 0 | n=int(input())
p=[]
for i in range(n):
p.append(int(input()))
print(len(set(p))) | Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an... | ```python
n=int(input())
p=[]
for i in range(n):
p.append(int(input()))
print(len(set(p)))
``` | 0 | |
887 | C | Solution for Cube | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation... | In first line given a sequence of 24 integers *a**i* (1<=≤<=*a**i*<=≤<=6), where *a**i* denotes color of *i*-th square. There are exactly 4 occurrences of all colors in this sequence. | Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise. | [
"2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4\n",
"5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3\n"
] | [
"NO",
"YES"
] | In first test case cube looks like this:
In second test case cube looks like this:
It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16. | 1,500 | [
{
"input": "2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4",
"output": "NO"
},
{
"input": "5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3",
"output": "YES"
},
{
"input": "2 6 3 3 5 5 2 6 1 1 6 4 4 4 2 4 6 5 3 1 2 5 3 1",
"output": "NO"
},
{
"input": "3 4 2 3 5 5 6 6 4 5 4 6... | 1,665,458,923 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | import sys
input = sys.stdin.readline
def f(a1, b1, c1, d1, e1, f1, g):
a, b, c, d, e, f = a1.copy(), b1.copy(), c1.copy(), d1.copy(), e1.copy(), f1.copy()
if len(set(a)) == len(set(b)) == 1:
if g == 1:
for i in [c, d, e, f]:
i[1], i[2] = i[2], i[1]
elif g... | Title: Solution for Cube
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly,... | ```python
import sys
input = sys.stdin.readline
def f(a1, b1, c1, d1, e1, f1, g):
a, b, c, d, e, f = a1.copy(), b1.copy(), c1.copy(), d1.copy(), e1.copy(), f1.copy()
if len(set(a)) == len(set(b)) == 1:
if g == 1:
for i in [c, d, e, f]:
i[1], i[2] = i[2], i[1]
... | 3 | |
982 | A | Row | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms"
] | null | null | You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means t... | The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating. | Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase). | [
"3\n101\n",
"4\n1011\n",
"5\n10001\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | 500 | [
{
"input": "3\n101",
"output": "Yes"
},
{
"input": "4\n1011",
"output": "No"
},
{
"input": "5\n10001",
"output": "No"
},
{
"input": "1\n0",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "100\n010100101010100101001001010100101010010... | 1,584,792,261 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 3 | 186 | 2,048,000 | def main():
n = int(input())
s = input()
flag = False
for i in range(n):
if s[i] == '1' and i+1 < n:
if s[i+1] == '1':
flag = True
break
if s[i] == '0':
if 1 <= i < n-1:
if s[i-1] == '0' and s[i+1] == '0':
... | Title: Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating th... | ```python
def main():
n = int(input())
s = input()
flag = False
for i in range(n):
if s[i] == '1' and i+1 < n:
if s[i+1] == '1':
flag = True
break
if s[i] == '0':
if 1 <= i < n-1:
if s[i-1] == '0' and s[i+1] == '0':
... | -1 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,595,401,290 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 216 | 6,758,400 | def borze():
s=input()
size=len(s)
i=0
ans=''
while i<size:
if s[i]=='.':
ans=ans+'0'
i=i+1
elif s[i]=='-':
if s[i:i+2]=='-.':
ans=ans+'1'
i=i+2
elif s[i:i+2]=='--':
ans=ans+... | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
def borze():
s=input()
size=len(s)
i=0
ans=''
while i<size:
if s[i]=='.':
ans=ans+'0'
i=i+1
elif s[i]=='-':
if s[i:i+2]=='-.':
ans=ans+'1'
i=i+2
elif s[i:i+2]=='--':
... | 3.933411 |
110 | A | Nearly Lucky Number | PROGRAMMING | 800 | [
"implementation"
] | A. Nearly Lucky Number | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d... | The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). | [
"40047\n",
"7747774\n",
"1000000000000000000\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | 500 | [
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
... | 1,694,527,303 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 60 | 0 | inp=input()
st=''
for i in inp:
if i=="4" or i =="7":
st+=i
if len(inp)==len(st):
print("YES")
else:
print("NO") | Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
inp=input()
st=''
for i in inp:
if i=="4" or i =="7":
st+=i
if len(inp)==len(st):
print("YES")
else:
print("NO")
``` | 0 |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,671,531,545 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 3,000 | 16,998,400 | a = int(input())
c = list(map(int, input().split()))
l = []
for i in c:
lc = []
for d in range(a):
lc.append(abs(i-c[d]))
if 0 in lc:
lc.remove(0)
print(min(lc),max(lc))
| Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
a = int(input())
c = list(map(int, input().split()))
l = []
for i in c:
lc = []
for d in range(a):
lc.append(abs(i-c[d]))
if 0 in lc:
lc.remove(0)
print(min(lc),max(lc))
``` | 0 | |
980 | A | Links and Pearls | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one.
You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you l... | The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl. | Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"-o-o--",
"-o---\n",
"-o---o-\n",
"ooo\n"
] | [
"YES",
"YES",
"NO",
"YES\n"
] | none | 500 | [
{
"input": "-o-o--",
"output": "YES"
},
{
"input": "-o---",
"output": "YES"
},
{
"input": "-o---o-",
"output": "NO"
},
{
"input": "ooo",
"output": "YES"
},
{
"input": "---",
"output": "YES"
},
{
"input": "--o-o-----o----o--oo-o-----ooo-oo---o--",
"... | 1,525,967,804 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 93 | 7,065,600 | s = [x for x in input().lower()]
b = s.count('o')
v = s.count('-')
if b == 0 or v % b == 0:
print("YES")
else:
print("NO")
| Title: Links and Pearls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one.
You can remove a link or a pearl and insert it between two other existing links or pearl... | ```python
s = [x for x in input().lower()]
b = s.count('o')
v = s.count('-')
if b == 0 or v % b == 0:
print("YES")
else:
print("NO")
``` | 3 | |
442 | D | Adam and Tree | PROGRAMMING | 2,600 | [
"data structures",
"trees"
] | null | null | When Adam gets a rooted tree (connected non-directed graph without cycles), he immediately starts coloring it. More formally, he assigns a color to each edge of the tree so that it meets the following two conditions:
- There is no vertex that has more than two incident edges painted the same color. - For any two ve... | The first line contains integer *n* (1<=≤<=*n*<=≤<=106) — the number of times a new vertex is added. The second line contains *n* numbers *p**i* (1<=≤<=*p**i*<=≤<=*i*) — the numbers of the vertexes to which we add another vertex. | Print *n* integers — the minimum costs of the tree painting after each addition. | [
"11\n1 1 1 3 4 4 7 3 7 6 6\n"
] | [
"1 1 1 1 1 2 2 2 2 2 3 "
] | The figure below shows one of the possible variants to paint a tree from the sample at the last moment. The cost of the vertexes with numbers 11 and 12 equals 3.
<img class="tex-graphics" src="https://espresso.codeforces.com/3e0ae59416472763f3e14b7c4a5094de154d3b50.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 2,000 | [] | 1,689,642,754 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689642754.0613358")# 1689642754.0613556 | Title: Adam and Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Adam gets a rooted tree (connected non-directed graph without cycles), he immediately starts coloring it. More formally, he assigns a color to each edge of the tree so that it meets the following two conditions:
- ... | ```python
print("_RANDOM_GUESS_1689642754.0613358")# 1689642754.0613556
``` | 0 | |
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors... | In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ... | In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReal... | 1,623,135,323 | 2,147,483,647 | PyPy 3 | OK | TESTS | 64 | 140 | 0 | n=int(input())
l=[]
m=[]
j=0
for i in range(n):
s=str(input())
l.append(s)
d={'purple':'Power','green':'Time','blue':'Space','orange':'Soul','red':'Reality',
'yellow':'Mind'}
for x in d:
if x not in l:
m.append(d[x])
j=j+1
print(j)
for x in m:
print(x)
| Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So... | ```python
n=int(input())
l=[]
m=[]
j=0
for i in range(n):
s=str(input())
l.append(s)
d={'purple':'Power','green':'Time','blue':'Space','orange':'Soul','red':'Reality',
'yellow':'Mind'}
for x in d:
if x not in l:
m.append(d[x])
j=j+1
print(j)
for x in m:
print(x)
``` | 3 | |
1,004 | E | Sonya and Ice Cream | PROGRAMMING | 2,400 | [
"binary search",
"data structures",
"dp",
"greedy",
"shortest paths",
"trees"
] | null | null | Sonya likes ice cream very much. She eats it even during programming competitions. That is why the girl decided that she wants to open her own ice cream shops.
Sonya lives in a city with $n$ junctions and $n-1$ streets between them. All streets are two-way and connect two junctions. It is possible to travel from any j... | The first line contains two integers $n$ and $k$ ($1\leq k\leq n\leq 10^5$) — the number of junctions and friends respectively.
Each of the next $n-1$ lines contains three integers $u_i$, $v_i$, and $d_i$ ($1\leq u_i, v_i\leq n$, $v_i\neq u_i$, $1\leq d\leq 10^4$) — junctions that are connected by a street and the len... | Print one number — the minimal possible maximum distance that you need to pass to get from any junction to the nearest ice cream shop. Sonya's shops must form a simple path and the number of shops must be at most $k$. | [
"6 2\n1 2 3\n2 3 4\n4 5 2\n4 6 3\n2 4 6\n",
"10 3\n1 2 5\n5 7 2\n3 2 6\n10 6 3\n3 8 1\n6 4 2\n4 1 6\n6 9 4\n5 2 5\n"
] | [
"4\n",
"7\n"
] | In the first example, you can choose the path 2-4, so the answer will be 4.
In the second example, you can choose the path 4-1-2, so the answer will be 7. | 2,500 | [
{
"input": "6 2\n1 2 3\n2 3 4\n4 5 2\n4 6 3\n2 4 6",
"output": "4"
},
{
"input": "10 3\n1 2 5\n5 7 2\n3 2 6\n10 6 3\n3 8 1\n6 4 2\n4 1 6\n6 9 4\n5 2 5",
"output": "7"
},
{
"input": "8 4\n8 7 4\n5 6 7\n7 3 4\n8 4 3\n1 2 1\n2 3 5\n5 4 4",
"output": "10"
},
{
"input": "1 1",
... | 1,530,834,168 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 155 | 0 | import heapq
class Node:
def __init__(self):
self.edges = {}
self.longest_apendage = 0
#self.id = id
def __lt__(self, other):
for d0 in self.edges.values():
break
for d1 in other.edges.values():
return d0 < d1
# def __repr__(self):
# return "Node({}, {})".format(self.id, self.longest_ap... | Title: Sonya and Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya likes ice cream very much. She eats it even during programming competitions. That is why the girl decided that she wants to open her own ice cream shops.
Sonya lives in a city with $n$ junctions and $n-1$ str... | ```python
import heapq
class Node:
def __init__(self):
self.edges = {}
self.longest_apendage = 0
#self.id = id
def __lt__(self, other):
for d0 in self.edges.values():
break
for d1 in other.edges.values():
return d0 < d1
# def __repr__(self):
# return "Node({}, {})".format(self.id, self.... | 0 | |
950 | A | Left-handers, Right-handers and Ambidexters | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and ... | The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. | Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. | [
"1 4 2\n",
"5 5 5\n",
"0 2 0\n"
] | [
"6\n",
"14\n",
"0\n"
] | In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five l... | 500 | [
{
"input": "1 4 2",
"output": "6"
},
{
"input": "5 5 5",
"output": "14"
},
{
"input": "0 2 0",
"output": "0"
},
{
"input": "30 70 34",
"output": "128"
},
{
"input": "89 32 24",
"output": "112"
},
{
"input": "89 44 77",
"output": "210"
},
{
... | 1,564,205,990 | 2,147,483,647 | PyPy 3 | OK | TESTS | 79 | 140 | 0 | inp = list(map(int,input().split()))
l=inp[0]
r=inp[1]
a=inp[2]
if(l==r):
print (2*(l+a//2))
elif(l<r):
if(r-l<=a):
a=a-(r-l)
l=r
print (2*(l+a//2))
else:
l=l+a
print (2*min(r,l))
else:
if(l-r<=a):
a=a-(l-r)
r=l
print (2*(... | Title: Left-handers, Right-handers and Ambidexters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.... | ```python
inp = list(map(int,input().split()))
l=inp[0]
r=inp[1]
a=inp[2]
if(l==r):
print (2*(l+a//2))
elif(l<r):
if(r-l<=a):
a=a-(r-l)
l=r
print (2*(l+a//2))
else:
l=l+a
print (2*min(r,l))
else:
if(l-r<=a):
a=a-(l-r)
r=l
... | 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.